2017-09-21 14:56:46 +01:00
|
|
|
// http://officeopenxml.com/WPparagraphProperties.php
|
2021-09-27 19:18:58 -07:00
|
|
|
// https://c-rex.net/projects/samples/ooxml/e1/Part4/OOXML_P4_DOCX_suppressLineNumbers_topic_ID0ECJAO.html
|
2022-06-26 23:26:42 +01:00
|
|
|
import { IContext, IgnoreIfEmptyXmlComponent, IXmlableObject, OnOffElement, XmlComponent } from "@file/xml-components";
|
2021-03-12 03:58:05 +00:00
|
|
|
import { DocumentWrapper } from "../document-wrapper";
|
2021-05-23 04:25:07 +03:00
|
|
|
import { IShadingAttributesProperties, Shading } from "../shading";
|
2020-07-11 17:01:32 +08:00
|
|
|
import { Alignment, AlignmentType } from "./formatting/alignment";
|
2021-05-23 08:00:49 +03:00
|
|
|
import { Border, IBordersOptions, ThematicBreak } from "./formatting/border";
|
2021-07-08 17:39:21 +10:00
|
|
|
import { PageBreakBefore } from "./formatting/break";
|
2021-07-08 17:46:13 +10:00
|
|
|
import { IIndentAttributesProperties, Indent } from "./formatting/indent";
|
2021-05-24 11:28:10 +03:00
|
|
|
import { ISpacingProperties, Spacing } from "./formatting/spacing";
|
2020-07-11 17:01:32 +08:00
|
|
|
import { HeadingLevel, Style } from "./formatting/style";
|
2022-10-16 00:21:34 +01:00
|
|
|
import { TabStop, TabStopDefinition, TabStopType } from "./formatting/tab-stop";
|
2020-07-11 17:01:32 +08:00
|
|
|
import { NumberProperties } from "./formatting/unordered-list";
|
2022-10-25 18:53:00 +01:00
|
|
|
import { WordWrap } from "./formatting/word-wrap";
|
2021-03-14 17:00:42 +00:00
|
|
|
import { FrameProperties, IFrameOptions } from "./frame/frame-properties";
|
2020-07-11 17:01:32 +08:00
|
|
|
import { OutlineLevel } from "./links";
|
2016-03-30 00:28:05 +01:00
|
|
|
|
2021-09-20 21:58:07 +03:00
|
|
|
export interface ILevelParagraphStylePropertiesOptions {
|
2020-07-11 17:01:32 +08:00
|
|
|
readonly alignment?: AlignmentType;
|
|
|
|
readonly thematicBreak?: boolean;
|
|
|
|
readonly contextualSpacing?: boolean;
|
|
|
|
readonly rightTabStop?: number;
|
|
|
|
readonly leftTabStop?: number;
|
|
|
|
readonly indent?: IIndentAttributesProperties;
|
|
|
|
readonly spacing?: ISpacingProperties;
|
|
|
|
readonly keepNext?: boolean;
|
|
|
|
readonly keepLines?: boolean;
|
|
|
|
readonly outlineLevel?: number;
|
2021-09-20 21:58:07 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
export interface IParagraphStylePropertiesOptions extends ILevelParagraphStylePropertiesOptions {
|
2021-09-16 13:01:47 +03:00
|
|
|
readonly numbering?: {
|
|
|
|
readonly reference: string;
|
|
|
|
readonly level: number;
|
|
|
|
readonly instance?: number;
|
|
|
|
readonly custom?: boolean;
|
|
|
|
};
|
2020-07-11 17:01:32 +08:00
|
|
|
}
|
2019-06-12 01:03:36 +01:00
|
|
|
|
2020-07-11 17:01:32 +08:00
|
|
|
export interface IParagraphPropertiesOptions extends IParagraphStylePropertiesOptions {
|
2021-05-23 08:00:49 +03:00
|
|
|
readonly border?: IBordersOptions;
|
2020-07-11 17:01:32 +08:00
|
|
|
readonly heading?: HeadingLevel;
|
|
|
|
readonly bidirectional?: boolean;
|
|
|
|
readonly pageBreakBefore?: boolean;
|
2022-10-16 00:21:34 +01:00
|
|
|
readonly tabStops?: readonly TabStopDefinition[];
|
2020-07-11 17:01:32 +08:00
|
|
|
readonly style?: string;
|
|
|
|
readonly bullet?: {
|
|
|
|
readonly level: number;
|
|
|
|
};
|
2021-05-23 04:25:07 +03:00
|
|
|
readonly shading?: IShadingAttributesProperties;
|
2021-03-13 04:07:44 +00:00
|
|
|
readonly widowControl?: boolean;
|
2021-03-14 17:00:42 +00:00
|
|
|
readonly frame?: IFrameOptions;
|
2021-09-27 19:11:09 -07:00
|
|
|
readonly suppressLineNumbers?: boolean;
|
2022-10-25 18:53:00 +01:00
|
|
|
readonly wordWrap?: boolean;
|
2022-11-03 00:30:16 +00:00
|
|
|
readonly scale?: number;
|
2023-03-17 02:20:51 +00:00
|
|
|
/**
|
|
|
|
* This element specifies whether inter-character spacing shall automatically be adjusted between regions of numbers and regions of East Asian text in the current paragraph. These regions shall be determined by the Unicode character values of the text content within the paragraph.
|
|
|
|
* This only works in Microsoft Word. It is not part of the ECMA-376 OOXML standard.
|
|
|
|
*/
|
|
|
|
readonly autoSpaceEastAsianText?: boolean;
|
2019-06-12 01:03:36 +01:00
|
|
|
}
|
2018-08-19 19:37:36 -04:00
|
|
|
|
2019-06-12 01:03:36 +01:00
|
|
|
export class ParagraphProperties extends IgnoreIfEmptyXmlComponent {
|
2022-09-15 20:00:50 +01:00
|
|
|
// eslint-disable-next-line functional/prefer-readonly-type
|
2021-03-12 03:58:05 +00:00
|
|
|
private readonly numberingReferences: { readonly reference: string; readonly instance: number }[] = [];
|
|
|
|
|
2022-08-31 07:52:27 +01:00
|
|
|
public constructor(options?: IParagraphPropertiesOptions) {
|
2016-05-09 03:44:16 +01:00
|
|
|
super("w:pPr");
|
2018-08-19 19:37:36 -04:00
|
|
|
|
2020-07-11 17:01:32 +08:00
|
|
|
if (!options) {
|
2021-05-20 01:06:07 +03:00
|
|
|
return this;
|
2020-07-11 17:01:32 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
if (options.heading) {
|
|
|
|
this.push(new Style(options.heading));
|
|
|
|
}
|
|
|
|
|
2021-05-20 01:06:07 +03:00
|
|
|
if (options.bullet) {
|
|
|
|
this.push(new Style("ListParagraph"));
|
2020-07-11 17:01:32 +08:00
|
|
|
}
|
|
|
|
|
2021-05-20 01:06:07 +03:00
|
|
|
if (options.numbering) {
|
|
|
|
if (!options.style && !options.heading) {
|
|
|
|
if (!options.numbering.custom) {
|
|
|
|
this.push(new Style("ListParagraph"));
|
|
|
|
}
|
|
|
|
}
|
2020-07-11 17:01:32 +08:00
|
|
|
}
|
|
|
|
|
2021-05-20 01:06:07 +03:00
|
|
|
if (options.style) {
|
|
|
|
this.push(new Style(options.style));
|
2020-07-11 17:01:32 +08:00
|
|
|
}
|
|
|
|
|
2021-05-24 11:28:10 +03:00
|
|
|
if (options.keepNext !== undefined) {
|
|
|
|
this.push(new OnOffElement("w:keepNext", options.keepNext));
|
2020-07-11 17:01:32 +08:00
|
|
|
}
|
|
|
|
|
2021-05-24 11:28:10 +03:00
|
|
|
if (options.keepLines !== undefined) {
|
|
|
|
this.push(new OnOffElement("w:keepLines", options.keepLines));
|
2020-07-11 17:01:32 +08:00
|
|
|
}
|
|
|
|
|
2021-05-20 01:06:07 +03:00
|
|
|
if (options.pageBreakBefore) {
|
|
|
|
this.push(new PageBreakBefore());
|
2020-07-11 17:01:32 +08:00
|
|
|
}
|
|
|
|
|
2021-05-20 01:06:07 +03:00
|
|
|
if (options.frame) {
|
|
|
|
this.push(new FrameProperties(options.frame));
|
2020-07-11 17:01:32 +08:00
|
|
|
}
|
|
|
|
|
2021-05-24 11:28:10 +03:00
|
|
|
if (options.widowControl !== undefined) {
|
|
|
|
this.push(new OnOffElement("w:widowControl", options.widowControl));
|
2020-07-11 17:01:32 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
if (options.bullet) {
|
|
|
|
this.push(new NumberProperties(1, options.bullet.level));
|
|
|
|
}
|
|
|
|
|
|
|
|
if (options.numbering) {
|
2021-03-12 03:58:05 +00:00
|
|
|
this.numberingReferences.push({
|
|
|
|
reference: options.numbering.reference,
|
|
|
|
instance: options.numbering.instance ?? 0,
|
|
|
|
});
|
|
|
|
|
|
|
|
this.push(new NumberProperties(`${options.numbering.reference}-${options.numbering.instance ?? 0}`, options.numbering.level));
|
2020-07-11 17:01:32 +08:00
|
|
|
}
|
|
|
|
|
2021-05-20 01:06:07 +03:00
|
|
|
if (options.border) {
|
|
|
|
this.push(new Border(options.border));
|
|
|
|
}
|
|
|
|
|
|
|
|
if (options.thematicBreak) {
|
|
|
|
this.push(new ThematicBreak());
|
|
|
|
}
|
|
|
|
|
|
|
|
if (options.shading) {
|
2021-05-23 04:25:07 +03:00
|
|
|
this.push(new Shading(options.shading));
|
2021-05-20 01:06:07 +03:00
|
|
|
}
|
|
|
|
|
2022-10-25 18:53:00 +01:00
|
|
|
if (options.wordWrap) {
|
|
|
|
this.push(new WordWrap());
|
|
|
|
}
|
|
|
|
|
2022-10-14 16:38:02 +05:45
|
|
|
/**
|
|
|
|
* FIX: Multitab support for Libre Writer
|
|
|
|
* Ensure there is only one w:tabs tag with multiple w:tab
|
|
|
|
*/
|
2022-10-16 00:21:34 +01:00
|
|
|
const tabDefinitions: readonly TabStopDefinition[] = [
|
|
|
|
...(options.rightTabStop ? [{ type: TabStopType.RIGHT, position: options.rightTabStop }] : []),
|
|
|
|
...(options.tabStops ? options.tabStops : []),
|
|
|
|
...(options.leftTabStop ? [{ type: TabStopType.LEFT, position: options.leftTabStop }] : []),
|
|
|
|
];
|
|
|
|
|
|
|
|
if (tabDefinitions.length > 0) {
|
|
|
|
this.push(new TabStop(tabDefinitions));
|
2020-07-11 17:01:32 +08:00
|
|
|
}
|
2022-10-14 16:38:02 +05:45
|
|
|
/**
|
2022-10-16 00:20:16 +01:00
|
|
|
* FIX - END
|
2022-10-14 16:38:02 +05:45
|
|
|
*/
|
2020-10-28 01:05:31 +00:00
|
|
|
|
2021-05-24 11:28:10 +03:00
|
|
|
if (options.bidirectional !== undefined) {
|
2021-12-02 17:24:19 +00:00
|
|
|
this.push(new OnOffElement("w:bidi", options.bidirectional));
|
2020-10-28 01:05:31 +00:00
|
|
|
}
|
2021-03-13 04:07:44 +00:00
|
|
|
|
2021-05-20 01:06:07 +03:00
|
|
|
if (options.spacing) {
|
|
|
|
this.push(new Spacing(options.spacing));
|
2021-03-13 04:07:44 +00:00
|
|
|
}
|
2021-03-14 17:00:42 +00:00
|
|
|
|
2021-05-20 01:06:07 +03:00
|
|
|
if (options.indent) {
|
|
|
|
this.push(new Indent(options.indent));
|
|
|
|
}
|
|
|
|
|
2021-05-24 11:28:10 +03:00
|
|
|
if (options.contextualSpacing !== undefined) {
|
|
|
|
this.push(new OnOffElement("w:contextualSpacing", options.contextualSpacing));
|
2021-05-20 01:06:07 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
if (options.alignment) {
|
|
|
|
this.push(new Alignment(options.alignment));
|
|
|
|
}
|
|
|
|
|
|
|
|
if (options.outlineLevel !== undefined) {
|
|
|
|
this.push(new OutlineLevel(options.outlineLevel));
|
2021-03-14 17:00:42 +00:00
|
|
|
}
|
2021-09-27 19:11:09 -07:00
|
|
|
|
|
|
|
if (options.suppressLineNumbers !== undefined) {
|
|
|
|
this.push(new OnOffElement("w:suppressLineNumbers", options.suppressLineNumbers));
|
|
|
|
}
|
2023-03-17 02:20:51 +00:00
|
|
|
|
|
|
|
if (options.autoSpaceEastAsianText !== undefined) {
|
|
|
|
this.push(new OnOffElement("w:autoSpaceDN", options.autoSpaceEastAsianText));
|
|
|
|
}
|
2016-03-30 00:28:05 +01:00
|
|
|
}
|
|
|
|
|
2017-03-08 21:36:09 +00:00
|
|
|
public push(item: XmlComponent): void {
|
2016-04-09 20:16:35 +01:00
|
|
|
this.root.push(item);
|
2016-03-30 00:28:05 +01:00
|
|
|
}
|
2021-03-12 03:58:05 +00:00
|
|
|
|
|
|
|
public prepForXml(context: IContext): IXmlableObject | undefined {
|
|
|
|
if (context.viewWrapper instanceof DocumentWrapper) {
|
|
|
|
for (const reference of this.numberingReferences) {
|
|
|
|
context.file.Numbering.createConcreteNumberingInstance(reference.reference, reference.instance);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return super.prepForXml(context);
|
|
|
|
}
|
2017-03-08 21:36:09 +00:00
|
|
|
}
|