diff --git a/ts/numbering/run-fonts.ts b/ts/docx/run/run-fonts.ts similarity index 79% rename from ts/numbering/run-fonts.ts rename to ts/docx/run/run-fonts.ts index dc4a8cd77b..a3ffa89f84 100644 --- a/ts/numbering/run-fonts.ts +++ b/ts/docx/run/run-fonts.ts @@ -1,9 +1,9 @@ -import {XmlAttributeComponent, XmlComponent} from "../docx/xml-components"; +import {XmlAttributeComponent, XmlComponent} from "../xml-components"; interface IRunFontAttributesProperties { ascii: string; hAnsi: string; - hint: string; + hint?: string; } class RunFontAttributes extends XmlAttributeComponent { @@ -19,7 +19,7 @@ class RunFontAttributes extends XmlAttributeComponent { export class RunFonts extends XmlComponent { - constructor(ascii: string, hint: string) { + constructor(ascii: string, hint?: string) { super("w:rFonts"); this.root.push(new RunFontAttributes({ ascii: ascii, diff --git a/ts/numbering/index.ts b/ts/numbering/index.ts index b813c665cf..39bfda0867 100644 --- a/ts/numbering/index.ts +++ b/ts/numbering/index.ts @@ -1,11 +1,11 @@ import * as _ from "lodash"; import { DocumentAttributes } from "../docx/document/document-attributes"; +import { RunFonts } from "../docx/run/run-fonts"; import { MultiPropertyXmlComponent } from "../docx/xml-components"; import { AbstractNumbering } from "./abstract-numbering"; import { Indent } from "./indent"; import { Level } from "./level"; import { Num } from "./num"; -import { RunFonts } from "./run-fonts"; export class Numbering extends MultiPropertyXmlComponent { private nextId: number; diff --git a/ts/tests/docx/run/fontTests.ts b/ts/tests/docx/run/fontTests.ts new file mode 100644 index 0000000000..a136a6949a --- /dev/null +++ b/ts/tests/docx/run/fontTests.ts @@ -0,0 +1,22 @@ +import { expect } from "chai"; +import { RunFonts } from "../../../docx/run/run-fonts"; +import { Formatter } from "../../../export/formatter"; + +describe("RunFonts", () => { + + describe("#constructor()", () => { + it("uses the font name for both ascii and hAnsi", () => { + const tree = new Formatter().format(new RunFonts("Times")); + expect(tree).to.deep.equal({ + "w:rFonts": [{_attr: {"w:ascii": "Times", "w:hAnsi": "Times"}}], + }); + }); + + it("uses hint if given", () => { + const tree = new Formatter().format(new RunFonts("Times", "default")); + expect(tree).to.deep.equal({ + "w:rFonts": [{_attr: {"w:ascii": "Times", "w:hAnsi": "Times", "w:hint": "default"}}], + }); + }); + }); +});