diff --git a/src/file/numbering/abstract-numbering.spec.ts b/src/file/numbering/abstract-numbering.spec.ts index a2fb61b000..6548a4436d 100644 --- a/src/file/numbering/abstract-numbering.spec.ts +++ b/src/file/numbering/abstract-numbering.spec.ts @@ -417,7 +417,7 @@ describe("AbstractNumbering", () => { }); }); - it("#font", () => { + it("#font by name", () => { const abstractNumbering = new AbstractNumbering(1, [ { level: 0, @@ -447,6 +447,37 @@ describe("AbstractNumbering", () => { }); }); + it("#font for ascii and eastAsia", () => { + const abstractNumbering = new AbstractNumbering(1, [ + { + level: 0, + format: "lowerRoman", + text: "%0.", + style: { + run: { + font: { + ascii: "Times", + eastAsia: "KaiTi", + }, + }, + }, + }, + ]); + const tree = new Formatter().format(abstractNumbering); + expect(tree["w:abstractNum"][2]["w:lvl"]).to.include({ + "w:rPr": [ + { + "w:rFonts": { + _attr: { + "w:ascii": "Times", + "w:eastAsia": "KaiTi", + }, + }, + }, + ], + }); + }); + it("#bold", () => { const abstractNumbering = new AbstractNumbering(1, [ { diff --git a/src/file/paragraph/run/run-fonts.spec.ts b/src/file/paragraph/run/run-fonts.spec.ts index 1eacc8ecc9..a0180eae81 100644 --- a/src/file/paragraph/run/run-fonts.spec.ts +++ b/src/file/paragraph/run/run-fonts.spec.ts @@ -21,5 +21,12 @@ describe("RunFonts", () => { }, }); }); + + it("uses the font attrs for ascii and eastAsia", () => { + const tree = new Formatter().format(new RunFonts({ ascii: "Times", eastAsia: "KaiTi" })); + expect(tree).to.deep.equal({ + "w:rFonts": { _attr: { "w:ascii": "Times", "w:eastAsia": "KaiTi" } }, + }); + }); }); }); diff --git a/src/file/paragraph/run/run.spec.ts b/src/file/paragraph/run/run.spec.ts index 8712622921..32904327d8 100644 --- a/src/file/paragraph/run/run.spec.ts +++ b/src/file/paragraph/run/run.spec.ts @@ -275,6 +275,32 @@ describe("Run", () => { ], }); }); + + it("should set the font for ascii and eastAsia", () => { + const run = new Run({ + font: { + ascii: "Times", + eastAsia: "KaiTi", + }, + }); + const tree = new Formatter().format(run); + expect(tree).to.deep.equal({ + "w:r": [ + { + "w:rPr": [ + { + "w:rFonts": { + _attr: { + "w:ascii": "Times", + "w:eastAsia": "KaiTi", + }, + }, + }, + ], + }, + ], + }); + }); }); describe("#color", () => { diff --git a/src/file/styles/style/character-style.spec.ts b/src/file/styles/style/character-style.spec.ts index c660b152be..64c866a8c8 100644 --- a/src/file/styles/style/character-style.spec.ts +++ b/src/file/styles/style/character-style.spec.ts @@ -202,7 +202,7 @@ describe("CharacterStyle", () => { }); }); - it("should add font", () => { + it("should add font by name", () => { const style = new CharacterStyle({ id: "myStyleId", run: { @@ -241,6 +241,46 @@ describe("CharacterStyle", () => { }); }); + it("should add font for ascii and eastAsia", () => { + const style = new CharacterStyle({ + id: "myStyleId", + run: { + font: { + ascii: "test font ascii", + eastAsia: "test font eastAsia", + }, + }, + }); + const tree = new Formatter().format(style); + expect(tree).to.deep.equal({ + "w:style": [ + { _attr: { "w:type": "character", "w:styleId": "myStyleId" } }, + { + "w:rPr": [ + { + "w:rFonts": { + _attr: { + "w:ascii": "test font ascii", + "w:eastAsia": "test font eastAsia", + }, + }, + }, + ], + }, + { + "w:uiPriority": { + _attr: { + "w:val": 99, + }, + }, + }, + { + "w:unhideWhenUsed": EMPTY_OBJECT, + }, + ], + }); + }); + it("should add character spacing", () => { const style = new CharacterStyle({ id: "myStyleId", diff --git a/src/file/styles/style/paragraph-style.spec.ts b/src/file/styles/style/paragraph-style.spec.ts index 3331dc3513..7d01ef87e7 100644 --- a/src/file/styles/style/paragraph-style.spec.ts +++ b/src/file/styles/style/paragraph-style.spec.ts @@ -484,7 +484,7 @@ describe("ParagraphStyle", () => { }); }); - it("#font", () => { + it("#font by name", () => { const style = new ParagraphStyle({ id: "myStyleId", run: { @@ -513,6 +513,36 @@ describe("ParagraphStyle", () => { }); }); + it("#font for ascii and eastAsia", () => { + const style = new ParagraphStyle({ + id: "myStyleId", + run: { + font: { + ascii: "Times", + eastAsia: "KaiTi", + }, + }, + }); + const tree = new Formatter().format(style); + expect(tree).to.deep.equal({ + "w:style": [ + { _attr: { "w:type": "paragraph", "w:styleId": "myStyleId" } }, + { + "w:rPr": [ + { + "w:rFonts": { + _attr: { + "w:ascii": "Times", + "w:eastAsia": "KaiTi", + }, + }, + }, + ], + }, + ], + }); + }); + it("#bold", () => { const style = new ParagraphStyle({ id: "myStyleId",