diff --git a/ts/docx/run/formatting.ts b/ts/docx/run/formatting.ts index 7236c24f5e..2685f07fda 100644 --- a/ts/docx/run/formatting.ts +++ b/ts/docx/run/formatting.ts @@ -1,6 +1,7 @@ import { Attributes, XmlComponent } from "../xml-components"; export { Underline } from "./underline"; export { SubScript, SuperScript } from "./script"; +export { RunFonts } from "./run-fonts"; export class Bold extends XmlComponent { diff --git a/ts/styles/style/index.ts b/ts/styles/style/index.ts index 5d9e221410..3cf06cefb8 100644 --- a/ts/styles/style/index.ts +++ b/ts/styles/style/index.ts @@ -131,6 +131,13 @@ export class ParagraphStyle extends Style { return this; } + public font(fontName: string): ParagraphStyle { + this.addRunProperty(new formatting.RunFonts(fontName)); + return this; + } + + // --------------------- Paragraph formatting ------------------------ // + public indent(left: number, hanging?: number): ParagraphStyle { this.addParagraphProperty(new Indent(left, hanging)); return this; diff --git a/ts/tests/stylesTest.ts b/ts/tests/stylesTest.ts index b56cb687fd..4180d182fd 100644 --- a/ts/tests/stylesTest.ts +++ b/ts/tests/stylesTest.ts @@ -320,6 +320,19 @@ describe("ParagraphStyle", () => { }); }); + it("#font", () => { + const style = new ParagraphStyle("myStyleId") + .font("Times"); + const tree = new Formatter().format(style); + expect(tree).to.deep.equal({ + "w:style": [ + {_attr: {"w:type": "paragraph", "w:styleId": "myStyleId"}}, + {"w:pPr": []}, + {"w:rPr": [{"w:rFonts": [{_attr: {"w:ascii": "Times", "w:hAnsi": "Times"}}]}]}, + ], + }); + }); + it("#bold", () => { const style = new ParagraphStyle("myStyleId") .bold();