2018-11-13 11:04:03 -02:00
|
|
|
import {
|
|
|
|
Alignment,
|
2019-06-12 01:03:36 +01:00
|
|
|
AlignmentType,
|
2018-11-13 11:04:03 -02:00
|
|
|
Indent,
|
|
|
|
ISpacingProperties,
|
|
|
|
KeepLines,
|
|
|
|
KeepNext,
|
|
|
|
LeftTabStop,
|
2019-02-13 17:16:45 +01:00
|
|
|
OutlineLevel,
|
2018-11-13 11:04:03 -02:00
|
|
|
ParagraphProperties,
|
|
|
|
Spacing,
|
|
|
|
ThematicBreak,
|
|
|
|
} from "file/paragraph";
|
2019-09-30 22:56:21 +01:00
|
|
|
import { RightTabStop } from "file/paragraph/formatting";
|
2018-11-13 11:04:03 -02:00
|
|
|
import * as formatting from "file/paragraph/run/formatting";
|
|
|
|
import { RunProperties } from "file/paragraph/run/properties";
|
2019-10-04 01:20:41 +01:00
|
|
|
import { UnderlineType } from "file/paragraph/run/underline";
|
|
|
|
import { ShadingType } from "file/table";
|
|
|
|
|
2018-11-13 11:04:29 -02:00
|
|
|
import { BasedOn, Link, Next, QuickFormat, SemiHidden, UiPriority, UnhideWhenUsed } from "./components";
|
2018-11-13 11:04:03 -02:00
|
|
|
import { Style } from "./style";
|
|
|
|
|
2019-10-04 01:20:41 +01:00
|
|
|
export interface IBaseParagraphStyleOptions {
|
|
|
|
readonly basedOn?: string;
|
|
|
|
readonly next?: string;
|
|
|
|
readonly quickFormat?: boolean;
|
|
|
|
readonly link?: string;
|
|
|
|
readonly semiHidden?: boolean;
|
|
|
|
readonly uiPriority?: number;
|
|
|
|
readonly unhideWhenUsed?: boolean;
|
|
|
|
readonly run?: {
|
|
|
|
readonly size?: number;
|
|
|
|
readonly bold?: boolean;
|
|
|
|
readonly italics?: boolean;
|
|
|
|
readonly smallCaps?: boolean;
|
|
|
|
readonly allCaps?: boolean;
|
|
|
|
readonly strike?: boolean;
|
|
|
|
readonly doubleStrike?: boolean;
|
|
|
|
readonly subScript?: boolean;
|
|
|
|
readonly superScript?: boolean;
|
|
|
|
readonly underline?: {
|
|
|
|
readonly type?: UnderlineType;
|
|
|
|
readonly color?: string;
|
|
|
|
};
|
|
|
|
readonly color?: string;
|
|
|
|
readonly font?: string;
|
|
|
|
readonly characterSpacing?: number;
|
|
|
|
readonly highlight?: string;
|
|
|
|
readonly shadow?: {
|
|
|
|
readonly type: ShadingType;
|
|
|
|
readonly fill: string;
|
|
|
|
readonly color: string;
|
|
|
|
};
|
|
|
|
};
|
|
|
|
readonly paragraph?: {
|
|
|
|
readonly alignment?: AlignmentType;
|
|
|
|
readonly thematicBreak?: boolean;
|
|
|
|
readonly rightTabStop?: number;
|
|
|
|
readonly leftTabStop?: number;
|
|
|
|
readonly indent?: object;
|
|
|
|
readonly spacing?: ISpacingProperties;
|
|
|
|
readonly keepNext?: boolean;
|
|
|
|
readonly keepLines?: boolean;
|
|
|
|
readonly outlineLevel?: number;
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
export interface IParagraphStyleOptions extends IBaseParagraphStyleOptions {
|
|
|
|
readonly id: string;
|
|
|
|
readonly name?: string;
|
|
|
|
}
|
2018-11-13 11:04:03 -02:00
|
|
|
export class ParagraphStyle extends Style {
|
|
|
|
private readonly paragraphProperties: ParagraphProperties;
|
|
|
|
private readonly runProperties: RunProperties;
|
|
|
|
|
2019-10-04 01:20:41 +01:00
|
|
|
constructor(options: IParagraphStyleOptions) {
|
|
|
|
super({ type: "paragraph", styleId: options.id }, options.name);
|
2019-06-12 01:03:36 +01:00
|
|
|
this.paragraphProperties = new ParagraphProperties({});
|
2018-11-13 11:04:03 -02:00
|
|
|
this.runProperties = new RunProperties();
|
|
|
|
this.root.push(this.paragraphProperties);
|
|
|
|
this.root.push(this.runProperties);
|
|
|
|
|
2019-10-04 01:20:41 +01:00
|
|
|
if (options.basedOn) {
|
|
|
|
this.root.push(new BasedOn(options.basedOn));
|
|
|
|
}
|
2018-11-13 11:04:03 -02:00
|
|
|
|
2019-10-04 01:20:41 +01:00
|
|
|
if (options.next) {
|
|
|
|
this.root.push(new Next(options.next));
|
|
|
|
}
|
2018-11-13 11:04:03 -02:00
|
|
|
|
2019-10-04 01:20:41 +01:00
|
|
|
if (options.quickFormat) {
|
|
|
|
this.root.push(new QuickFormat());
|
|
|
|
}
|
2018-11-13 11:04:03 -02:00
|
|
|
|
2019-10-04 01:20:41 +01:00
|
|
|
if (options.link) {
|
|
|
|
this.root.push(new Link(options.link));
|
|
|
|
}
|
2018-11-13 11:04:03 -02:00
|
|
|
|
2019-10-04 01:20:41 +01:00
|
|
|
if (options.semiHidden) {
|
|
|
|
this.root.push(new SemiHidden());
|
|
|
|
}
|
2018-11-13 11:04:03 -02:00
|
|
|
|
2019-10-04 01:20:41 +01:00
|
|
|
if (options.uiPriority) {
|
|
|
|
this.root.push(new UiPriority(options.uiPriority));
|
|
|
|
}
|
2018-11-13 11:04:03 -02:00
|
|
|
|
2019-10-04 01:20:41 +01:00
|
|
|
if (options.unhideWhenUsed) {
|
|
|
|
this.root.push(new UnhideWhenUsed());
|
|
|
|
}
|
|
|
|
|
|
|
|
if (options.run) {
|
|
|
|
if (options.run.size) {
|
|
|
|
this.runProperties.push(new formatting.Size(options.run.size));
|
|
|
|
this.runProperties.push(new formatting.SizeComplexScript(options.run.size));
|
|
|
|
}
|
|
|
|
|
|
|
|
if (options.run.bold) {
|
|
|
|
this.runProperties.push(new formatting.Bold());
|
|
|
|
}
|
|
|
|
|
|
|
|
if (options.run.italics) {
|
|
|
|
this.runProperties.push(new formatting.Italics());
|
|
|
|
}
|
|
|
|
|
|
|
|
if (options.run.smallCaps) {
|
|
|
|
this.runProperties.push(new formatting.SmallCaps());
|
|
|
|
}
|
|
|
|
|
|
|
|
if (options.run.allCaps) {
|
|
|
|
this.runProperties.push(new formatting.Caps());
|
|
|
|
}
|
|
|
|
|
|
|
|
if (options.run.strike) {
|
|
|
|
this.runProperties.push(new formatting.Strike());
|
|
|
|
}
|
|
|
|
|
|
|
|
if (options.run.doubleStrike) {
|
|
|
|
this.runProperties.push(new formatting.DoubleStrike());
|
|
|
|
}
|
|
|
|
|
|
|
|
if (options.run.subScript) {
|
|
|
|
this.runProperties.push(new formatting.SubScript());
|
|
|
|
}
|
|
|
|
|
|
|
|
if (options.run.superScript) {
|
|
|
|
this.runProperties.push(new formatting.SuperScript());
|
|
|
|
}
|
|
|
|
|
|
|
|
if (options.run.underline) {
|
|
|
|
this.runProperties.push(new formatting.Underline(options.run.underline.type, options.run.underline.color));
|
|
|
|
}
|
|
|
|
|
|
|
|
if (options.run.color) {
|
|
|
|
this.runProperties.push(new formatting.Color(options.run.color));
|
|
|
|
}
|
|
|
|
|
|
|
|
if (options.run.font) {
|
|
|
|
this.runProperties.push(new formatting.RunFonts(options.run.font));
|
|
|
|
}
|
|
|
|
|
|
|
|
if (options.run.characterSpacing) {
|
|
|
|
this.runProperties.push(new formatting.CharacterSpacing(options.run.characterSpacing));
|
|
|
|
}
|
|
|
|
|
|
|
|
if (options.run.highlight) {
|
|
|
|
this.runProperties.push(new formatting.Highlight(options.run.highlight));
|
|
|
|
}
|
|
|
|
|
|
|
|
if (options.run.shadow) {
|
|
|
|
this.runProperties.push(new formatting.Shading(options.run.shadow.type, options.run.shadow.fill, options.run.shadow.color));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (options.paragraph) {
|
|
|
|
if (options.paragraph.alignment) {
|
|
|
|
this.paragraphProperties.push(new Alignment(options.paragraph.alignment));
|
|
|
|
}
|
|
|
|
|
|
|
|
if (options.paragraph.thematicBreak) {
|
|
|
|
this.paragraphProperties.push(new ThematicBreak());
|
|
|
|
}
|
|
|
|
|
|
|
|
if (options.paragraph.rightTabStop) {
|
|
|
|
this.paragraphProperties.push(new RightTabStop(options.paragraph.rightTabStop));
|
|
|
|
}
|
|
|
|
|
|
|
|
if (options.paragraph.leftTabStop) {
|
|
|
|
this.paragraphProperties.push(new LeftTabStop(options.paragraph.leftTabStop));
|
|
|
|
}
|
|
|
|
|
|
|
|
if (options.paragraph.indent) {
|
|
|
|
this.paragraphProperties.push(new Indent(options.paragraph.indent));
|
|
|
|
}
|
|
|
|
|
|
|
|
if (options.paragraph.spacing) {
|
|
|
|
this.paragraphProperties.push(new Spacing(options.paragraph.spacing));
|
|
|
|
}
|
|
|
|
|
|
|
|
if (options.paragraph.keepNext) {
|
|
|
|
this.paragraphProperties.push(new KeepNext());
|
|
|
|
}
|
|
|
|
|
|
|
|
if (options.paragraph.keepLines) {
|
|
|
|
this.paragraphProperties.push(new KeepLines());
|
|
|
|
}
|
|
|
|
|
|
|
|
if (options.paragraph.outlineLevel) {
|
|
|
|
this.paragraphProperties.push(new OutlineLevel(options.paragraph.outlineLevel));
|
|
|
|
}
|
|
|
|
}
|
2018-11-13 11:04:03 -02:00
|
|
|
}
|
|
|
|
}
|