2022-06-26 23:26:42 +01:00
|
|
|
import { BorderElement, IBorderOptions } from "@file/border";
|
|
|
|
import { IShadingAttributesProperties, Shading } from "@file/shading";
|
|
|
|
import { ChangeAttributes, IChangedAttributesProperties } from "@file/track-revision/track-revision";
|
2022-11-03 00:30:16 +00:00
|
|
|
import {
|
|
|
|
HpsMeasureElement,
|
|
|
|
IgnoreIfEmptyXmlComponent,
|
|
|
|
NumberValueElement,
|
|
|
|
OnOffElement,
|
|
|
|
StringValueElement,
|
|
|
|
XmlComponent,
|
|
|
|
} from "@file/xml-components";
|
2022-06-15 00:07:12 +01:00
|
|
|
|
2020-07-11 17:01:32 +08:00
|
|
|
import { EmphasisMark, EmphasisMarkType } from "./emphasis-mark";
|
2021-05-24 08:20:08 +03:00
|
|
|
import { CharacterSpacing, Color, Highlight, HighlightComplexScript } from "./formatting";
|
2020-07-11 17:01:32 +08:00
|
|
|
import { IFontAttributesProperties, RunFonts } from "./run-fonts";
|
|
|
|
import { SubScript, SuperScript } from "./script";
|
|
|
|
import { Underline, UnderlineType } from "./underline";
|
|
|
|
|
|
|
|
interface IFontOptions {
|
|
|
|
readonly name: string;
|
|
|
|
readonly hint?: string;
|
|
|
|
}
|
|
|
|
|
|
|
|
export interface IRunStylePropertiesOptions {
|
|
|
|
readonly bold?: boolean;
|
|
|
|
readonly boldComplexScript?: boolean;
|
|
|
|
readonly italics?: boolean;
|
|
|
|
readonly italicsComplexScript?: boolean;
|
|
|
|
readonly underline?: {
|
|
|
|
readonly color?: string;
|
|
|
|
readonly type?: UnderlineType;
|
|
|
|
};
|
|
|
|
readonly emphasisMark?: {
|
|
|
|
readonly type?: EmphasisMarkType;
|
|
|
|
};
|
|
|
|
readonly color?: string;
|
2021-05-24 08:20:08 +03:00
|
|
|
readonly size?: number | string;
|
|
|
|
readonly sizeComplexScript?: boolean | number | string;
|
2020-07-11 17:01:32 +08:00
|
|
|
readonly rightToLeft?: boolean;
|
|
|
|
readonly smallCaps?: boolean;
|
|
|
|
readonly allCaps?: boolean;
|
|
|
|
readonly strike?: boolean;
|
|
|
|
readonly doubleStrike?: boolean;
|
|
|
|
readonly subScript?: boolean;
|
|
|
|
readonly superScript?: boolean;
|
|
|
|
readonly font?: string | IFontOptions | IFontAttributesProperties;
|
|
|
|
readonly highlight?: string;
|
|
|
|
readonly highlightComplexScript?: boolean | string;
|
|
|
|
readonly characterSpacing?: number;
|
2021-05-23 04:25:07 +03:00
|
|
|
readonly shading?: IShadingAttributesProperties;
|
2021-03-13 20:23:15 +00:00
|
|
|
readonly emboss?: boolean;
|
|
|
|
readonly imprint?: boolean;
|
2021-11-26 12:29:11 +01:00
|
|
|
readonly revision?: IRunPropertiesChangeOptions;
|
2022-01-06 04:36:55 +00:00
|
|
|
readonly border?: IBorderOptions;
|
2022-10-28 22:20:16 +01:00
|
|
|
readonly vanish?: boolean;
|
|
|
|
readonly specVanish?: boolean;
|
2022-11-03 00:30:16 +00:00
|
|
|
readonly scale?: number;
|
2020-07-11 17:01:32 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
export interface IRunPropertiesOptions extends IRunStylePropertiesOptions {
|
|
|
|
readonly style?: string;
|
|
|
|
}
|
2016-03-30 03:50:53 +01:00
|
|
|
|
2021-11-26 12:29:11 +01:00
|
|
|
export interface IRunPropertiesChangeOptions extends IRunPropertiesOptions, IChangedAttributesProperties {}
|
|
|
|
|
2021-05-24 08:20:08 +03:00
|
|
|
// <xsd:group name="EG_RPrBase">
|
|
|
|
// <xsd:choice>
|
|
|
|
// <xsd:element name="rStyle" type="CT_String"/>
|
|
|
|
// <xsd:element name="rFonts" type="CT_Fonts"/>
|
|
|
|
// <xsd:element name="b" type="CT_OnOff"/>
|
|
|
|
// <xsd:element name="bCs" type="CT_OnOff"/>
|
|
|
|
// <xsd:element name="i" type="CT_OnOff"/>
|
|
|
|
// <xsd:element name="iCs" type="CT_OnOff"/>
|
|
|
|
// <xsd:element name="caps" type="CT_OnOff"/>
|
|
|
|
// <xsd:element name="smallCaps" type="CT_OnOff"/>
|
|
|
|
// <xsd:element name="strike" type="CT_OnOff"/>
|
|
|
|
// <xsd:element name="dstrike" type="CT_OnOff"/>
|
|
|
|
// <xsd:element name="outline" type="CT_OnOff"/>
|
|
|
|
// <xsd:element name="shadow" type="CT_OnOff"/>
|
|
|
|
// <xsd:element name="emboss" type="CT_OnOff"/>
|
|
|
|
// <xsd:element name="imprint" type="CT_OnOff"/>
|
|
|
|
// <xsd:element name="noProof" type="CT_OnOff"/>
|
|
|
|
// <xsd:element name="snapToGrid" type="CT_OnOff"/>
|
|
|
|
// <xsd:element name="vanish" type="CT_OnOff"/>
|
|
|
|
// <xsd:element name="webHidden" type="CT_OnOff"/>
|
|
|
|
// <xsd:element name="color" type="CT_Color"/>
|
|
|
|
// <xsd:element name="spacing" type="CT_SignedTwipsMeasure"/>
|
|
|
|
// <xsd:element name="w" type="CT_TextScale"/>
|
|
|
|
// <xsd:element name="kern" type="CT_HpsMeasure"/>
|
|
|
|
// <xsd:element name="position" type="CT_SignedHpsMeasure"/>
|
|
|
|
// <xsd:element name="sz" type="CT_HpsMeasure"/>
|
|
|
|
// <xsd:element name="szCs" type="CT_HpsMeasure"/>
|
|
|
|
// <xsd:element name="highlight" type="CT_Highlight"/>
|
|
|
|
// <xsd:element name="u" type="CT_Underline"/>
|
|
|
|
// <xsd:element name="effect" type="CT_TextEffect"/>
|
|
|
|
// <xsd:element name="bdr" type="CT_Border"/>
|
|
|
|
// <xsd:element name="shd" type="CT_Shd"/>
|
|
|
|
// <xsd:element name="fitText" type="CT_FitText"/>
|
|
|
|
// <xsd:element name="vertAlign" type="CT_VerticalAlignRun"/>
|
|
|
|
// <xsd:element name="rtl" type="CT_OnOff"/>
|
|
|
|
// <xsd:element name="cs" type="CT_OnOff"/>
|
|
|
|
// <xsd:element name="em" type="CT_Em"/>
|
|
|
|
// <xsd:element name="lang" type="CT_Language"/>
|
|
|
|
// <xsd:element name="eastAsianLayout" type="CT_EastAsianLayout"/>
|
|
|
|
// <xsd:element name="specVanish" type="CT_OnOff"/>
|
|
|
|
// <xsd:element name="oMath" type="CT_OnOff"/>
|
|
|
|
// </xsd:choice>
|
|
|
|
// </xsd:group>
|
2019-04-09 05:27:18 -04:00
|
|
|
export class RunProperties extends IgnoreIfEmptyXmlComponent {
|
2022-08-31 07:52:27 +01:00
|
|
|
public constructor(options?: IRunPropertiesOptions) {
|
2016-04-09 20:16:35 +01:00
|
|
|
super("w:rPr");
|
2020-07-11 17:01:32 +08:00
|
|
|
|
|
|
|
if (!options) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2021-05-24 11:28:10 +03:00
|
|
|
if (options.bold !== undefined) {
|
|
|
|
this.push(new OnOffElement("w:b", options.bold));
|
2020-07-11 17:01:32 +08:00
|
|
|
}
|
2021-05-24 11:28:10 +03:00
|
|
|
if ((options.boldComplexScript === undefined && options.bold !== undefined) || options.boldComplexScript) {
|
|
|
|
this.push(new OnOffElement("w:bCs", options.boldComplexScript ?? options.bold));
|
2020-07-11 17:01:32 +08:00
|
|
|
}
|
|
|
|
|
2021-05-24 11:28:10 +03:00
|
|
|
if (options.italics !== undefined) {
|
|
|
|
this.push(new OnOffElement("w:i", options.italics));
|
2020-07-11 17:01:32 +08:00
|
|
|
}
|
2021-05-24 11:28:10 +03:00
|
|
|
|
|
|
|
if ((options.italicsComplexScript === undefined && options.italics !== undefined) || options.italicsComplexScript) {
|
|
|
|
this.push(new OnOffElement("w:iCs", options.italicsComplexScript ?? options.italics));
|
2020-07-11 17:01:32 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
if (options.underline) {
|
|
|
|
this.push(new Underline(options.underline.type, options.underline.color));
|
|
|
|
}
|
|
|
|
|
|
|
|
if (options.emphasisMark) {
|
|
|
|
this.push(new EmphasisMark(options.emphasisMark.type));
|
|
|
|
}
|
|
|
|
|
|
|
|
if (options.color) {
|
|
|
|
this.push(new Color(options.color));
|
|
|
|
}
|
|
|
|
|
2021-05-24 11:28:10 +03:00
|
|
|
if (options.size !== undefined) {
|
2021-05-24 08:20:08 +03:00
|
|
|
this.push(new HpsMeasureElement("w:sz", options.size));
|
2020-07-11 17:01:32 +08:00
|
|
|
}
|
|
|
|
const szCs =
|
|
|
|
options.sizeComplexScript === undefined || options.sizeComplexScript === true ? options.size : options.sizeComplexScript;
|
|
|
|
if (szCs) {
|
2021-05-24 08:20:08 +03:00
|
|
|
this.push(new HpsMeasureElement("w:szCs", szCs));
|
2020-07-11 17:01:32 +08:00
|
|
|
}
|
|
|
|
|
2021-05-24 11:28:10 +03:00
|
|
|
if (options.rightToLeft !== undefined) {
|
|
|
|
this.push(new OnOffElement("w:rtl", options.rightToLeft));
|
2020-07-11 17:01:32 +08:00
|
|
|
}
|
|
|
|
|
2021-05-24 08:20:08 +03:00
|
|
|
// These two are mutually exclusive
|
2021-05-24 11:28:10 +03:00
|
|
|
if (options.smallCaps !== undefined) {
|
|
|
|
this.push(new OnOffElement("w:smallCaps", options.smallCaps));
|
|
|
|
} else if (options.allCaps !== undefined) {
|
|
|
|
this.push(new OnOffElement("w:caps", options.allCaps));
|
2020-07-11 17:01:32 +08:00
|
|
|
}
|
|
|
|
|
2021-05-24 11:28:10 +03:00
|
|
|
if (options.strike !== undefined) {
|
|
|
|
this.push(new OnOffElement("w:strike", options.strike));
|
2020-07-11 17:01:32 +08:00
|
|
|
}
|
|
|
|
|
2021-05-24 11:28:10 +03:00
|
|
|
if (options.doubleStrike !== undefined) {
|
|
|
|
this.push(new OnOffElement("w:dstrike", options.doubleStrike));
|
2020-07-11 17:01:32 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
if (options.subScript) {
|
|
|
|
this.push(new SubScript());
|
|
|
|
}
|
|
|
|
|
|
|
|
if (options.superScript) {
|
|
|
|
this.push(new SuperScript());
|
|
|
|
}
|
|
|
|
|
|
|
|
if (options.style) {
|
2021-05-24 17:12:10 +03:00
|
|
|
this.push(new StringValueElement("w:rStyle", options.style));
|
2020-07-11 17:01:32 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
if (options.font) {
|
|
|
|
if (typeof options.font === "string") {
|
|
|
|
this.push(new RunFonts(options.font));
|
|
|
|
} else if ("name" in options.font) {
|
|
|
|
this.push(new RunFonts(options.font.name, options.font.hint));
|
|
|
|
} else {
|
|
|
|
this.push(new RunFonts(options.font));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (options.highlight) {
|
|
|
|
this.push(new Highlight(options.highlight));
|
|
|
|
}
|
|
|
|
const highlightCs =
|
|
|
|
options.highlightComplexScript === undefined || options.highlightComplexScript === true
|
|
|
|
? options.highlight
|
|
|
|
: options.highlightComplexScript;
|
|
|
|
if (highlightCs) {
|
|
|
|
this.push(new HighlightComplexScript(highlightCs));
|
|
|
|
}
|
|
|
|
|
|
|
|
if (options.characterSpacing) {
|
|
|
|
this.push(new CharacterSpacing(options.characterSpacing));
|
|
|
|
}
|
|
|
|
|
2021-05-24 11:28:10 +03:00
|
|
|
if (options.emboss !== undefined) {
|
|
|
|
this.push(new OnOffElement("w:emboss", options.emboss));
|
2021-03-13 20:23:15 +00:00
|
|
|
}
|
|
|
|
|
2021-05-24 11:28:10 +03:00
|
|
|
if (options.imprint !== undefined) {
|
|
|
|
this.push(new OnOffElement("w:imprint", options.imprint));
|
2021-03-13 20:23:15 +00:00
|
|
|
}
|
|
|
|
|
2021-05-23 04:25:07 +03:00
|
|
|
if (options.shading) {
|
|
|
|
this.push(new Shading(options.shading));
|
2020-07-11 17:01:32 +08:00
|
|
|
}
|
2021-11-26 12:29:11 +01:00
|
|
|
|
|
|
|
if (options.revision) {
|
|
|
|
this.push(new RunPropertiesChange(options.revision));
|
|
|
|
}
|
2022-01-06 04:36:55 +00:00
|
|
|
|
|
|
|
if (options.border) {
|
|
|
|
this.push(new BorderElement("w:bdr", options.border));
|
|
|
|
}
|
2022-10-28 22:20:16 +01:00
|
|
|
|
|
|
|
if (options.vanish) {
|
|
|
|
// https://c-rex.net/projects/samples/ooxml/e1/Part4/OOXML_P4_DOCX_vanish_topic_ID0E6W3O.html
|
|
|
|
// http://www.datypic.com/sc/ooxml/e-w_vanish-1.html
|
|
|
|
this.push(new OnOffElement("w:vanish", options.vanish));
|
|
|
|
}
|
|
|
|
|
|
|
|
if (options.specVanish) {
|
|
|
|
// https://c-rex.net/projects/samples/ooxml/e1/Part4/OOXML_P4_DOCX_specVanish_topic_ID0EIE1O.html
|
|
|
|
this.push(new OnOffElement("w:specVanish", options.vanish));
|
|
|
|
}
|
2022-11-03 00:30:16 +00:00
|
|
|
|
|
|
|
if (options.scale !== undefined) {
|
|
|
|
this.push(new NumberValueElement("w:w", options.scale));
|
|
|
|
}
|
2016-03-30 03:50:53 +01:00
|
|
|
}
|
2016-03-30 04:32:51 +01:00
|
|
|
|
2017-03-08 20:32:30 +00:00
|
|
|
public push(item: XmlComponent): void {
|
2016-04-09 20:16:35 +01:00
|
|
|
this.root.push(item);
|
2016-03-30 04:30:58 +01:00
|
|
|
}
|
2016-03-30 03:50:53 +01:00
|
|
|
}
|
2021-11-26 12:29:11 +01:00
|
|
|
|
|
|
|
export class RunPropertiesChange extends XmlComponent {
|
2022-08-31 07:52:27 +01:00
|
|
|
public constructor(options: IRunPropertiesChangeOptions) {
|
2021-11-26 12:29:11 +01:00
|
|
|
super("w:rPrChange");
|
|
|
|
this.root.push(
|
|
|
|
new ChangeAttributes({
|
|
|
|
id: options.id,
|
|
|
|
author: options.author,
|
|
|
|
date: options.date,
|
|
|
|
}),
|
|
|
|
);
|
|
|
|
this.addChildElement(new RunProperties(options as IRunPropertiesOptions));
|
|
|
|
}
|
|
|
|
}
|