diff --git a/src/file/paragraph/run/formatting.ts b/src/file/paragraph/run/formatting.ts index 8b1be933ec..30d437e268 100644 --- a/src/file/paragraph/run/formatting.ts +++ b/src/file/paragraph/run/formatting.ts @@ -25,6 +25,17 @@ export class BoldComplexScript extends XmlComponent { } } +export class CharacterSpacing extends XmlComponent { + constructor(value: number) { + super("w:spacing"); + this.root.push( + new Attributes({ + val: value, + }), + ); + } +} + export class Italics extends XmlComponent { constructor() { super("w:i"); diff --git a/src/file/styles/style/index.ts b/src/file/styles/style/index.ts index 655cc28d2a..38bd92e1e1 100644 --- a/src/file/styles/style/index.ts +++ b/src/file/styles/style/index.ts @@ -133,6 +133,11 @@ export class ParagraphStyle extends Style { return this; } + public characterSpacing(value: number): ParagraphStyle { + this.addRunProperty(new formatting.CharacterSpacing(value)); + return this; + } + // --------------------- Paragraph formatting ------------------------ // public center(): ParagraphStyle { diff --git a/src/file/styles/styles.spec.ts b/src/file/styles/styles.spec.ts index 1c828337b2..6262b3cb9e 100644 --- a/src/file/styles/styles.spec.ts +++ b/src/file/styles/styles.spec.ts @@ -219,6 +219,20 @@ describe("ParagraphStyle", () => { }); }); + it("#character spacing", () => { + const style = new ParagraphStyle("myStyleId").characterSpacing(24); + const tree = new Formatter().format(style); + expect(tree).to.deep.equal({ + "w:style": [ + { _attr: { "w:type": "paragraph", "w:styleId": "myStyleId" } }, + { "w:pPr": [] }, + { + "w:rPr": [{ "w:spacing": [{ _attr: { "w:val": 24 } }] }], + }, + ], + }); + }); + it("#left", () => { const style = new ParagraphStyle("myStyleId").left(); const tree = new Formatter().format(style);