From b6cf1ab951ddc6c2a543581a399e3d9210389a28 Mon Sep 17 00:00:00 2001 From: Dolan Date: Mon, 23 Jul 2018 20:28:29 +0100 Subject: [PATCH 1/3] Add demo20 table border styles --- demo/demo20.js | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) create mode 100644 demo/demo20.js diff --git a/demo/demo20.js b/demo/demo20.js new file mode 100644 index 0000000000..12ffb58549 --- /dev/null +++ b/demo/demo20.js @@ -0,0 +1,17 @@ +const docx = require("../build"); + +var doc = new docx.Document(); + +const table = doc.createTable(4, 4); +table + .getCell(2, 2) + .addContent(new docx.Paragraph("Hello")) + .cellProperties.borders.addTopBorder(docx.BorderStyle.DASH_DOT_STROKED, 3, "red") + .addBottomBorder(docx.BorderStyle.DOUBLE, 3, "blue") + .addStartBorder(docx.BorderStyle.DOT_DOT_DASH, 3, "green") + .addEndBorder(docx.BorderStyle.DOT_DOT_DASH, 3, "#ff8000"); + +var exporter = new docx.LocalPacker(doc); +exporter.pack("My Document"); + +console.log("Document created successfully at project root!"); From 1fad9a666e3da8ccb35f2bff877b1d757efcb4f7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=B7=B4=E9=87=8C=E5=88=87=E7=BD=97?= Date: Tue, 24 Jul 2018 12:24:26 +0800 Subject: [PATCH 2/3] Let fonts suit for more characters --- src/file/numbering/numbering.spec.ts | 4 ++-- src/file/paragraph/run/run-fonts.spec.ts | 4 ++-- src/file/paragraph/run/run-fonts.ts | 6 ++++++ src/file/paragraph/run/run.spec.ts | 2 +- src/file/styles/styles.spec.ts | 2 +- 5 files changed, 12 insertions(+), 6 deletions(-) diff --git a/src/file/numbering/numbering.spec.ts b/src/file/numbering/numbering.spec.ts index b695d5d1d4..6b1177a5aa 100644 --- a/src/file/numbering/numbering.spec.ts +++ b/src/file/numbering/numbering.spec.ts @@ -34,7 +34,7 @@ describe("Numbering", () => { ]); // Once chai 4.0.0 lands and #644 is resolved, we can add the following to the test: // {"w:lvlText": [{"_attr": {"w:val": "•"}}]}, - // {"w:rPr": [{"w:rFonts": [{"_attr": {"w:ascii": "Symbol", "w:hAnsi": "Symbol", "w:hint": "default"}}]}]}, + // {"w:rPr": [{"w:rFonts": [{"_attr": {"w:ascii": "Symbol", "w:cs": "Symbol", "w:eastAsia": "Symbol", "w:hAnsi": "Symbol", "w:hint": "default"}}]}]}, // {"w:pPr": [{"_attr": {}}, // {"w:ind": [{"_attr": {"w:left": 720, "w:hanging": 360}}]}]}, }); @@ -297,7 +297,7 @@ describe("AbstractNumbering", () => { const level = abstractNumbering.createLevel(0, "lowerRoman", "%0.").font("Times"); const tree = new Formatter().format(level); expect(tree["w:lvl"]).to.include({ - "w:rPr": [{ "w:rFonts": [{ _attr: { "w:ascii": "Times", "w:hAnsi": "Times" } }] }], + "w:rPr": [{ "w:rFonts": [{ _attr: { "w:ascii": "Times", "w:cs": "Times", "w:eastAsia": "Times", "w:hAnsi": "Times" } }] }], }); }); diff --git a/src/file/paragraph/run/run-fonts.spec.ts b/src/file/paragraph/run/run-fonts.spec.ts index 54a84f2c9e..7e9b1d1783 100644 --- a/src/file/paragraph/run/run-fonts.spec.ts +++ b/src/file/paragraph/run/run-fonts.spec.ts @@ -8,14 +8,14 @@ describe("RunFonts", () => { 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" } }], + "w:rFonts": [{ _attr: { "w:ascii": "Times", "w:cs": "Times", "w:eastAsia": "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" } }], + "w:rFonts": [{ _attr: { "w:ascii": "Times", "w:cs": "Times", "w:eastAsia": "Times", "w:hAnsi": "Times", "w:hint": "default" } }], }); }); }); diff --git a/src/file/paragraph/run/run-fonts.ts b/src/file/paragraph/run/run-fonts.ts index 0b6b8f9806..bf667f6b19 100644 --- a/src/file/paragraph/run/run-fonts.ts +++ b/src/file/paragraph/run/run-fonts.ts @@ -2,6 +2,8 @@ import { XmlAttributeComponent, XmlComponent } from "file/xml-components"; interface IRunFontAttributesProperties { ascii: string; + cs: string; + eastAsia: string; hAnsi: string; hint?: string; } @@ -9,6 +11,8 @@ interface IRunFontAttributesProperties { class RunFontAttributes extends XmlAttributeComponent { protected xmlKeys = { ascii: "w:ascii", + cs: "w:cs", + eastAsia: "w:eastAsia", hAnsi: "w:hAnsi", hint: "w:hint", }; @@ -20,6 +24,8 @@ export class RunFonts extends XmlComponent { this.root.push( new RunFontAttributes({ ascii: ascii, + cs: ascii, + eastAsia: ascii, hAnsi: ascii, hint: hint, }), diff --git a/src/file/paragraph/run/run.spec.ts b/src/file/paragraph/run/run.spec.ts index 62a5fa425f..49ae94ff47 100644 --- a/src/file/paragraph/run/run.spec.ts +++ b/src/file/paragraph/run/run.spec.ts @@ -108,7 +108,7 @@ describe("Run", () => { 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" } }] }] }], + "w:r": [{ "w:rPr": [{ "w:rFonts": [{ _attr: { "w:ascii": "Times", "w:cs": "Times", "w:eastAsia": "Times", "w:hAnsi": "Times" } }] }] }], }); }); }); diff --git a/src/file/styles/styles.spec.ts b/src/file/styles/styles.spec.ts index e8c7bc6f92..21d637196e 100644 --- a/src/file/styles/styles.spec.ts +++ b/src/file/styles/styles.spec.ts @@ -459,7 +459,7 @@ describe("ParagraphStyle", () => { "w:style": [ { _attr: { "w:type": "paragraph", "w:styleId": "myStyleId" } }, { "w:pPr": [] }, - { "w:rPr": [{ "w:rFonts": [{ _attr: { "w:ascii": "Times", "w:hAnsi": "Times" } }] }] }, + { "w:rPr": [{ "w:rFonts": [{ _attr: { "w:ascii": "Times", "w:cs": "Times", "w:eastAsia": "Times", "w:hAnsi": "Times" } }] }] }, ], }); }); From 974eb510efe87a7a223cb50989e06961b450339c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=B7=B4=E9=87=8C=E5=88=87=E7=BD=97?= Date: Tue, 24 Jul 2018 12:37:15 +0800 Subject: [PATCH 3/3] Fix style --- src/file/numbering/numbering.spec.ts | 4 +++- src/file/paragraph/run/run-fonts.spec.ts | 4 +++- src/file/paragraph/run/run.spec.ts | 8 +++++++- src/file/styles/styles.spec.ts | 6 +++++- 4 files changed, 18 insertions(+), 4 deletions(-) diff --git a/src/file/numbering/numbering.spec.ts b/src/file/numbering/numbering.spec.ts index 6b1177a5aa..17b46eda30 100644 --- a/src/file/numbering/numbering.spec.ts +++ b/src/file/numbering/numbering.spec.ts @@ -297,7 +297,9 @@ describe("AbstractNumbering", () => { const level = abstractNumbering.createLevel(0, "lowerRoman", "%0.").font("Times"); const tree = new Formatter().format(level); expect(tree["w:lvl"]).to.include({ - "w:rPr": [{ "w:rFonts": [{ _attr: { "w:ascii": "Times", "w:cs": "Times", "w:eastAsia": "Times", "w:hAnsi": "Times" } }] }], + "w:rPr": [ + { "w:rFonts": [{ _attr: { "w:ascii": "Times", "w:cs": "Times", "w:eastAsia": "Times", "w:hAnsi": "Times" } }] }, + ], }); }); diff --git a/src/file/paragraph/run/run-fonts.spec.ts b/src/file/paragraph/run/run-fonts.spec.ts index 7e9b1d1783..366c0e16d5 100644 --- a/src/file/paragraph/run/run-fonts.spec.ts +++ b/src/file/paragraph/run/run-fonts.spec.ts @@ -15,7 +15,9 @@ describe("RunFonts", () => { 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:cs": "Times", "w:eastAsia": "Times", "w:hAnsi": "Times", "w:hint": "default" } }], + "w:rFonts": [ + { _attr: { "w:ascii": "Times", "w:cs": "Times", "w:eastAsia": "Times", "w:hAnsi": "Times", "w:hint": "default" } }, + ], }); }); }); diff --git a/src/file/paragraph/run/run.spec.ts b/src/file/paragraph/run/run.spec.ts index 49ae94ff47..050989c941 100644 --- a/src/file/paragraph/run/run.spec.ts +++ b/src/file/paragraph/run/run.spec.ts @@ -108,7 +108,13 @@ describe("Run", () => { 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:cs": "Times", "w:eastAsia": "Times", "w:hAnsi": "Times" } }] }] }], + "w:r": [ + { + "w:rPr": [ + { "w:rFonts": [{ _attr: { "w:ascii": "Times", "w:cs": "Times", "w:eastAsia": "Times", "w:hAnsi": "Times" } }] }, + ], + }, + ], }); }); }); diff --git a/src/file/styles/styles.spec.ts b/src/file/styles/styles.spec.ts index 21d637196e..4c888a4f02 100644 --- a/src/file/styles/styles.spec.ts +++ b/src/file/styles/styles.spec.ts @@ -459,7 +459,11 @@ describe("ParagraphStyle", () => { "w:style": [ { _attr: { "w:type": "paragraph", "w:styleId": "myStyleId" } }, { "w:pPr": [] }, - { "w:rPr": [{ "w:rFonts": [{ _attr: { "w:ascii": "Times", "w:cs": "Times", "w:eastAsia": "Times", "w:hAnsi": "Times" } }] }] }, + { + "w:rPr": [ + { "w:rFonts": [{ _attr: { "w:ascii": "Times", "w:cs": "Times", "w:eastAsia": "Times", "w:hAnsi": "Times" } }] }, + ], + }, ], }); });