diff --git a/ts/docx/run/index.ts b/ts/docx/run/index.ts index 11c89c594f..0ec7c97e9d 100644 --- a/ts/docx/run/index.ts +++ b/ts/docx/run/index.ts @@ -1,4 +1,5 @@ import {XmlComponent, Attributes} from "../xml-components"; +import { RunFonts } from "./run-fonts"; import {RunProperties} from "./properties"; import {Bold, Italics} from "./formatting"; import {Tab} from "./tab"; @@ -11,7 +12,6 @@ import {Underline} from "./underline" export class Run extends XmlComponent { private properties: RunProperties; - constructor() { super("w:r"); this.properties = new RunProperties(); @@ -72,4 +72,9 @@ export class Run extends XmlComponent { this.properties.push(new SuperScript()); return this; } -} \ No newline at end of file + + font(fontName: string): Run { + this.properties.push(new RunFonts(fontName)); + return this; + } +} diff --git a/ts/tests/docx/run/runTest.ts b/ts/tests/docx/run/runTest.ts index 8f87e0413d..a57e517e5b 100644 --- a/ts/tests/docx/run/runTest.ts +++ b/ts/tests/docx/run/runTest.ts @@ -1,4 +1,4 @@ -import { assert } from "chai"; +import { assert, expect } from "chai"; import { Run } from "../../../docx/run"; import { TextRun } from "../../../docx/run/text-run"; import { Formatter } from "../../../export/formatter"; @@ -85,4 +85,20 @@ describe("Run", () => { assert.equal(newJson.root[1].rootKey, "w:tab"); }); }); + + describe("#font()", () => { + it("should allow chaining calls", () => { + expect(run.font("Times")).to.equal(run); + }); + + it("should set the font as named", () => { + run.font("Times"); + const tree = new Formatter().format(run); + expect(tree).to.deep.equal({ + "w:r": [ + {"w:rPr": [{"w:rFonts": [{_attr: {"w:ascii": "Times", "w:hAnsi": "Times"}}]}]}, + ], + }); + }); + }); });