From f9c97a673e2d5f03229998302e6a05ee6bb38f58 Mon Sep 17 00:00:00 2001 From: amitm02 Date: Mon, 6 Aug 2018 12:14:51 +0300 Subject: [PATCH 1/4] add complex font support to bold and italic --- src/file/paragraph/run/formatting.ts | 22 ++++++++++++++++++++++ src/file/paragraph/run/run.spec.ts | 2 ++ src/file/paragraph/run/run.ts | 4 +++- 3 files changed, 27 insertions(+), 1 deletion(-) diff --git a/src/file/paragraph/run/formatting.ts b/src/file/paragraph/run/formatting.ts index bd9da1c358..a59879917c 100644 --- a/src/file/paragraph/run/formatting.ts +++ b/src/file/paragraph/run/formatting.ts @@ -14,6 +14,17 @@ export class Bold extends XmlComponent { } } +export class BoldCs extends XmlComponent { + constructor() { + super("w:bCs"); + this.root.push( + new Attributes({ + val: true, + }), + ); + } +} + export class Italics extends XmlComponent { constructor() { super("w:i"); @@ -25,6 +36,17 @@ export class Italics extends XmlComponent { } } +export class ItalicsCs extends XmlComponent { + constructor() { + super("w:iCs"); + this.root.push( + new Attributes({ + val: true, + }), + ); + } +} + export class Caps extends XmlComponent { constructor() { super("w:caps"); diff --git a/src/file/paragraph/run/run.spec.ts b/src/file/paragraph/run/run.spec.ts index 5fbe93ee92..52443bc0d2 100644 --- a/src/file/paragraph/run/run.spec.ts +++ b/src/file/paragraph/run/run.spec.ts @@ -16,6 +16,7 @@ describe("Run", () => { run.bold(); const newJson = Utility.jsonify(run); assert.equal(newJson.root[0].root[0].rootKey, "w:b"); + assert.equal(newJson.root[0].root[1].rootKey, "w:bCs"); }); }); @@ -24,6 +25,7 @@ describe("Run", () => { run.italic(); const newJson = Utility.jsonify(run); assert.equal(newJson.root[0].root[0].rootKey, "w:i"); + assert.equal(newJson.root[0].root[1].rootKey, "w:iCs"); }); }); diff --git a/src/file/paragraph/run/run.ts b/src/file/paragraph/run/run.ts index ea45bbcd34..b08627aadb 100644 --- a/src/file/paragraph/run/run.ts +++ b/src/file/paragraph/run/run.ts @@ -1,7 +1,7 @@ // http://officeopenxml.com/WPtext.php import { Break } from "./break"; import { Caps, SmallCaps } from "./caps"; -import { Bold, Color, DoubleStrike, Italics, RTL, Size, SizeCs, Strike } from "./formatting"; +import { Bold, BoldCs, Color, DoubleStrike, Italics, ItalicsCs, RTL, Size, SizeCs, Strike } from "./formatting"; import { Begin, End, Page, Separate } from "./page-number"; import { RunProperties } from "./properties"; import { RunFonts } from "./run-fonts"; @@ -23,11 +23,13 @@ export class Run extends XmlComponent { public bold(): Run { this.properties.push(new Bold()); + this.properties.push(new BoldCs()); return this; } public italic(): Run { this.properties.push(new Italics()); + this.properties.push(new ItalicsCs()); return this; } From fe43525dada52eb8805d95a986f09ed18123d792 Mon Sep 17 00:00:00 2001 From: amitm02 Date: Tue, 7 Aug 2018 16:19:13 +0300 Subject: [PATCH 2/4] update hebrew demo --- demo/demo22.js | 20 ++++++++++++++++---- 1 file changed, 16 insertions(+), 4 deletions(-) diff --git a/demo/demo22.js b/demo/demo22.js index ce42f22ccd..1a5fd78be7 100644 --- a/demo/demo22.js +++ b/demo/demo22.js @@ -2,11 +2,23 @@ const docx = require('../build'); var doc = new docx.Document(); -var textRun = new docx.TextRun("שלום עולם").rtl(); -var paragraph = new docx.Paragraph().bidi(); -paragraph.addRun(textRun); -doc.addParagraph(paragraph); + +var paragraph1 = new docx.Paragraph().bidi(); +var textRun1 = new docx.TextRun("שלום עולם").rtl(); +paragraph1.addRun(textRun1); +doc.addParagraph(paragraph1); + +var paragraph2 = new docx.Paragraph().bidi(); +var textRun2 = new docx.TextRun("שלום עולם").bold().rtl(); +paragraph2.addRun(textRun2); +doc.addParagraph(paragraph2); + +var paragraph3 = new docx.Paragraph().bidi(); +var textRun3 = new docx.TextRun("שלום עולם").italic().rtl(); +paragraph3.addRun(textRun3); +doc.addParagraph(paragraph3); + var exporter = new docx.LocalPacker(doc); exporter.pack('My Document'); From 3dd6faa620bb0881156683e51891cf587d059c5d Mon Sep 17 00:00:00 2001 From: Dolan Date: Wed, 8 Aug 2018 01:29:52 +0100 Subject: [PATCH 3/4] Update README.md --- README.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/README.md b/README.md index 5415a4976e..207401f56c 100644 --- a/README.md +++ b/README.md @@ -19,6 +19,8 @@ # docx +drawing + ## Install ```sh From 4c75b91ce9e294f2328604ea38d30a9a279065f7 Mon Sep 17 00:00:00 2001 From: Dolan Date: Wed, 8 Aug 2018 01:53:44 +0100 Subject: [PATCH 4/4] Update README.md --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 207401f56c..a24abcc0a7 100644 --- a/README.md +++ b/README.md @@ -19,7 +19,7 @@ # docx -drawing +drawing ## Install