2017-09-19 15:42:40 +01:00
|
|
|
// http://officeopenxml.com/WPtext.php
|
2019-08-06 21:37:33 +01:00
|
|
|
import { ShadingType } from "file/table";
|
|
|
|
import { XmlComponent } from "file/xml-components";
|
|
|
|
|
2019-09-30 22:56:21 +01:00
|
|
|
import { FieldInstruction } from "file/table-of-contents/field-instruction";
|
2017-09-19 15:42:40 +01:00
|
|
|
import { Break } from "./break";
|
|
|
|
import { Caps, SmallCaps } from "./caps";
|
2018-09-03 10:54:53 -03:00
|
|
|
import { Begin, End, Separate } from "./field";
|
2018-08-08 20:20:22 +01:00
|
|
|
import {
|
|
|
|
Bold,
|
|
|
|
BoldComplexScript,
|
|
|
|
Color,
|
|
|
|
DoubleStrike,
|
2019-08-05 13:42:45 +03:00
|
|
|
Highlight,
|
|
|
|
HighlightComplexScript,
|
2018-08-08 20:20:22 +01:00
|
|
|
Italics,
|
|
|
|
ItalicsComplexScript,
|
|
|
|
RightToLeft,
|
2019-08-06 23:08:21 +01:00
|
|
|
Shading,
|
2019-08-05 13:42:45 +03:00
|
|
|
ShadowComplexScript,
|
2018-08-08 20:20:22 +01:00
|
|
|
Size,
|
|
|
|
SizeComplexScript,
|
|
|
|
Strike,
|
|
|
|
} from "./formatting";
|
2019-08-09 11:56:22 +03:00
|
|
|
import { NumberOfPages, NumberOfPagesSection, Page } from "./page-number";
|
2017-09-19 15:42:40 +01:00
|
|
|
import { RunProperties } from "./properties";
|
|
|
|
import { RunFonts } from "./run-fonts";
|
|
|
|
import { SubScript, SuperScript } from "./script";
|
|
|
|
import { Style } from "./style";
|
|
|
|
import { Tab } from "./tab";
|
2019-06-17 01:51:57 +01:00
|
|
|
import { Underline, UnderlineType } from "./underline";
|
2017-09-19 15:42:40 +01:00
|
|
|
|
2019-06-17 01:51:57 +01:00
|
|
|
export interface IRunOptions {
|
|
|
|
readonly bold?: true;
|
|
|
|
readonly italics?: true;
|
|
|
|
readonly underline?: {
|
|
|
|
readonly color?: string;
|
|
|
|
readonly type?: UnderlineType;
|
|
|
|
};
|
|
|
|
readonly color?: string;
|
|
|
|
readonly size?: number;
|
|
|
|
readonly rightToLeft?: boolean;
|
|
|
|
readonly smallCaps?: boolean;
|
|
|
|
readonly allCaps?: boolean;
|
|
|
|
readonly strike?: boolean;
|
|
|
|
readonly doubleStrike?: boolean;
|
|
|
|
readonly subScript?: boolean;
|
|
|
|
readonly superScript?: boolean;
|
|
|
|
readonly style?: string;
|
|
|
|
readonly font?: {
|
|
|
|
readonly name: string;
|
|
|
|
readonly hint?: string;
|
|
|
|
};
|
2019-08-06 21:37:33 +01:00
|
|
|
readonly highlight?: string;
|
2019-08-06 23:08:21 +01:00
|
|
|
readonly shading?: {
|
2019-08-06 21:37:33 +01:00
|
|
|
readonly type: ShadingType;
|
|
|
|
readonly fill: string;
|
|
|
|
readonly color: string;
|
|
|
|
};
|
2019-09-30 22:56:21 +01:00
|
|
|
readonly children?: Array<Begin | FieldInstruction | Separate | End>;
|
2019-06-17 01:51:57 +01:00
|
|
|
}
|
2017-09-19 15:42:40 +01:00
|
|
|
|
|
|
|
export class Run extends XmlComponent {
|
2018-11-02 02:51:57 +00:00
|
|
|
protected readonly properties: RunProperties;
|
2017-09-19 15:42:40 +01:00
|
|
|
|
2019-06-17 01:51:57 +01:00
|
|
|
constructor(options: IRunOptions) {
|
2017-09-19 15:42:40 +01:00
|
|
|
super("w:r");
|
|
|
|
this.properties = new RunProperties();
|
|
|
|
this.root.push(this.properties);
|
|
|
|
|
2019-06-17 01:51:57 +01:00
|
|
|
if (options.bold) {
|
|
|
|
this.properties.push(new Bold());
|
|
|
|
this.properties.push(new BoldComplexScript());
|
|
|
|
}
|
2017-09-19 15:42:40 +01:00
|
|
|
|
2019-06-17 01:51:57 +01:00
|
|
|
if (options.italics) {
|
|
|
|
this.properties.push(new Italics());
|
|
|
|
this.properties.push(new ItalicsComplexScript());
|
|
|
|
}
|
2017-09-19 15:42:40 +01:00
|
|
|
|
2019-06-17 01:51:57 +01:00
|
|
|
if (options.underline) {
|
|
|
|
this.properties.push(new Underline(options.underline.type, options.underline.color));
|
|
|
|
}
|
2017-09-19 15:42:40 +01:00
|
|
|
|
2019-06-17 01:51:57 +01:00
|
|
|
if (options.color) {
|
|
|
|
this.properties.push(new Color(options.color));
|
|
|
|
}
|
2017-09-19 15:42:40 +01:00
|
|
|
|
2019-06-17 01:51:57 +01:00
|
|
|
if (options.size) {
|
|
|
|
this.properties.push(new Size(options.size));
|
|
|
|
this.properties.push(new SizeComplexScript(options.size));
|
|
|
|
}
|
2017-09-19 15:42:40 +01:00
|
|
|
|
2019-06-17 01:51:57 +01:00
|
|
|
if (options.rightToLeft) {
|
|
|
|
this.properties.push(new RightToLeft());
|
|
|
|
}
|
|
|
|
|
|
|
|
if (options.smallCaps) {
|
|
|
|
this.properties.push(new SmallCaps());
|
|
|
|
}
|
|
|
|
|
|
|
|
if (options.allCaps) {
|
|
|
|
this.properties.push(new Caps());
|
|
|
|
}
|
|
|
|
|
|
|
|
if (options.strike) {
|
|
|
|
this.properties.push(new Strike());
|
|
|
|
}
|
|
|
|
|
|
|
|
if (options.doubleStrike) {
|
|
|
|
this.properties.push(new DoubleStrike());
|
|
|
|
}
|
|
|
|
|
|
|
|
if (options.subScript) {
|
|
|
|
this.properties.push(new SubScript());
|
|
|
|
}
|
|
|
|
|
|
|
|
if (options.superScript) {
|
|
|
|
this.properties.push(new SuperScript());
|
|
|
|
}
|
|
|
|
|
|
|
|
if (options.style) {
|
|
|
|
this.properties.push(new Style(options.style));
|
|
|
|
}
|
|
|
|
|
|
|
|
if (options.font) {
|
|
|
|
this.properties.push(new RunFonts(options.font.name, options.font.hint));
|
|
|
|
}
|
2019-08-06 21:37:33 +01:00
|
|
|
|
|
|
|
if (options.highlight) {
|
|
|
|
this.properties.push(new Highlight(options.highlight));
|
|
|
|
this.properties.push(new HighlightComplexScript(options.highlight));
|
|
|
|
}
|
|
|
|
|
2019-08-06 23:08:21 +01:00
|
|
|
if (options.shading) {
|
|
|
|
this.properties.push(new Shading(options.shading.type, options.shading.fill, options.shading.color));
|
|
|
|
this.properties.push(new ShadowComplexScript(options.shading.type, options.shading.fill, options.shading.color));
|
2019-08-06 21:37:33 +01:00
|
|
|
}
|
2019-09-30 22:56:21 +01:00
|
|
|
|
|
|
|
if (options.children) {
|
|
|
|
for (const child of options.children) {
|
|
|
|
this.root.push(child);
|
|
|
|
}
|
|
|
|
}
|
2018-07-24 18:52:45 +03:00
|
|
|
}
|
|
|
|
|
2017-09-19 15:42:40 +01:00
|
|
|
public break(): Run {
|
|
|
|
this.root.splice(1, 0, new Break());
|
|
|
|
return this;
|
|
|
|
}
|
|
|
|
|
|
|
|
public tab(): Run {
|
|
|
|
this.root.splice(1, 0, new Tab());
|
|
|
|
return this;
|
|
|
|
}
|
|
|
|
|
2018-05-12 20:04:54 -04:00
|
|
|
public pageNumber(): Run {
|
|
|
|
this.root.push(new Begin());
|
|
|
|
this.root.push(new Page());
|
|
|
|
this.root.push(new Separate());
|
|
|
|
this.root.push(new End());
|
|
|
|
return this;
|
|
|
|
}
|
|
|
|
|
2019-01-15 02:09:38 +00:00
|
|
|
public numberOfTotalPages(): Run {
|
|
|
|
this.root.push(new Begin());
|
|
|
|
this.root.push(new NumberOfPages());
|
|
|
|
this.root.push(new Separate());
|
|
|
|
this.root.push(new End());
|
|
|
|
return this;
|
|
|
|
}
|
|
|
|
|
2019-08-09 11:56:22 +03:00
|
|
|
public numberOfTotalPagesSection(): Run {
|
|
|
|
this.root.push(new Begin());
|
|
|
|
this.root.push(new NumberOfPagesSection());
|
|
|
|
this.root.push(new Separate());
|
|
|
|
this.root.push(new End());
|
|
|
|
return this;
|
|
|
|
}
|
2017-09-19 15:42:40 +01:00
|
|
|
}
|