diff --git a/.nycrc b/.nycrc index efbb818eff..b50b7553fb 100644 --- a/.nycrc +++ b/.nycrc @@ -1,9 +1,9 @@ { "check-coverage": true, - "lines": 98.19, - "functions": 94.79, - "branches": 95.35, - "statements": 98.17, + "lines": 98.31, + "functions": 95.83, + "branches": 95.38, + "statements": 98.29, "include": [ "src/**/*.ts" ], diff --git a/demo/46-shading-text.ts b/demo/46-shading-text.ts index e662e6dffe..2c440d73e5 100644 --- a/demo/46-shading-text.ts +++ b/demo/46-shading-text.ts @@ -43,7 +43,20 @@ doc.addSection({ ], }), }, - children: [], + children: [ + new Paragraph({ + children: [ + new TextRun({ + emboss: true, + text: "Embossed text - hello world", + }), + new TextRun({ + imprint: true, + text: "Imprinted text - hello world", + }), + ], + }), + ], }); Packer.toBuffer(doc).then((buffer) => { diff --git a/src/file/paragraph/run/formatting.spec.ts b/src/file/paragraph/run/formatting.spec.ts new file mode 100644 index 0000000000..43a1de1fd0 --- /dev/null +++ b/src/file/paragraph/run/formatting.spec.ts @@ -0,0 +1,22 @@ +import { expect } from "chai"; + +import { Formatter } from "export/formatter"; + +import { Bold } from "./formatting"; + +describe("Bold", () => { + describe("#constructor()", () => { + it("should create", () => { + const currentBold = new Bold(); + + const tree = new Formatter().format(currentBold); + expect(tree).to.deep.equal({ + "w:b": { + _attr: { + "w:val": true, + }, + }, + }); + }); + }); +}); diff --git a/src/file/paragraph/run/formatting.ts b/src/file/paragraph/run/formatting.ts index 3ef041d7d9..36c202b8d5 100644 --- a/src/file/paragraph/run/formatting.ts +++ b/src/file/paragraph/run/formatting.ts @@ -1,10 +1,5 @@ import { Attributes, XmlComponent } from "file/xml-components"; -export { Underline } from "./underline"; -export { EmphasisMark } from "./emphasis-mark"; -export { SubScript, SuperScript } from "./script"; -export { RunFonts, IFontAttributesProperties } from "./run-fonts"; - export class Bold extends XmlComponent { constructor() { super("w:b"); diff --git a/src/file/paragraph/run/properties.ts b/src/file/paragraph/run/properties.ts index 0bd082afc5..7fb054d545 100644 --- a/src/file/paragraph/run/properties.ts +++ b/src/file/paragraph/run/properties.ts @@ -8,8 +8,10 @@ import { CharacterSpacing, Color, DoubleStrike, + Emboss, Highlight, HighlightComplexScript, + Imprint, Italics, ItalicsComplexScript, RightToLeft, @@ -63,6 +65,8 @@ export interface IRunStylePropertiesOptions { }; readonly shadingComplexScript?: boolean | IRunStylePropertiesOptions["shading"]; readonly shadow?: IRunStylePropertiesOptions["shading"]; + readonly emboss?: boolean; + readonly imprint?: boolean; } export interface IRunPropertiesOptions extends IRunStylePropertiesOptions { @@ -169,6 +173,14 @@ export class RunProperties extends IgnoreIfEmptyXmlComponent { this.push(new CharacterSpacing(options.characterSpacing)); } + if (options.emboss) { + this.push(new Emboss()); + } + + if (options.imprint) { + this.push(new Imprint()); + } + const shading = options.shading || options.shadow; if (shading) { this.push(new Shading(shading.type, shading.fill, shading.color)); diff --git a/src/file/paragraph/run/run.spec.ts b/src/file/paragraph/run/run.spec.ts index 017c616938..5dc7c270d0 100644 --- a/src/file/paragraph/run/run.spec.ts +++ b/src/file/paragraph/run/run.spec.ts @@ -146,7 +146,7 @@ describe("Run", () => { }); describe("#doubleStrike()", () => { - it("it should add caps to the properties", () => { + it("it should add double strike to the properties", () => { const run = new Run({ doubleStrike: true, }); @@ -157,6 +157,30 @@ describe("Run", () => { }); }); + describe("#emboss()", () => { + it("it should add emboss to the properties", () => { + const run = new Run({ + emboss: true, + }); + const tree = new Formatter().format(run); + expect(tree).to.deep.equal({ + "w:r": [{ "w:rPr": [{ "w:emboss": { _attr: { "w:val": true } } }] }], + }); + }); + }); + + describe("#imprint()", () => { + it("it should add imprint to the properties", () => { + const run = new Run({ + imprint: true, + }); + const tree = new Formatter().format(run); + expect(tree).to.deep.equal({ + "w:r": [{ "w:rPr": [{ "w:imprint": { _attr: { "w:val": true } } }] }], + }); + }); + }); + describe("#subScript()", () => { it("it should add subScript to the properties", () => { const run = new Run({