diff --git a/src/file/paragraph/formatting/tab-stop.spec.ts b/src/file/paragraph/formatting/tab-stop.spec.ts index 377e7bb060..0c4d04bfec 100644 --- a/src/file/paragraph/formatting/tab-stop.spec.ts +++ b/src/file/paragraph/formatting/tab-stop.spec.ts @@ -8,7 +8,7 @@ describe("LeftTabStop", () => { let tabStop: TabStop; beforeEach(() => { - tabStop = new TabStop(TabStopType.LEFT, 100); + tabStop = new TabStop({ type: TabStopType.LEFT, position: 100}); }); describe("#constructor()", () => { @@ -32,7 +32,7 @@ describe("RightTabStop", () => { let tabStop: TabStop; beforeEach(() => { - tabStop = new TabStop(TabStopType.RIGHT, 100, LeaderType.DOT); + tabStop = new TabStop({ type: TabStopType.RIGHT, position: 100, leader: LeaderType.DOT}); }); describe("#constructor()", () => { diff --git a/src/file/paragraph/formatting/tab-stop.ts b/src/file/paragraph/formatting/tab-stop.ts index 4e8fe3436f..0b646d6660 100644 --- a/src/file/paragraph/formatting/tab-stop.ts +++ b/src/file/paragraph/formatting/tab-stop.ts @@ -1,10 +1,22 @@ // http://officeopenxml.com/WPtab.php import { XmlAttributeComponent, XmlComponent } from "@file/xml-components"; +export interface TabStopDefinition { + type: TabStopType, + position: number | TabStopPosition, + leader?: LeaderType +} + export class TabStop extends XmlComponent { - public constructor(type: TabStopType, position: number, leader?: LeaderType) { + public constructor(tabDefs: (TabStopDefinition[] | TabStopDefinition)) { super("w:tabs"); - this.root.push(new TabStopItem(type, position, leader)); + if (Array.isArray(tabDefs)) { + tabDefs.forEach((function(tabDef) { + this.root.push(new TabStopItem(tabDef)); + }).bind(this)); + } else { + this.root.push(new TabStopItem(tabDefs)); + } } } @@ -41,14 +53,14 @@ export class TabAttributes extends XmlAttributeComponent<{ } export class TabStopItem extends XmlComponent { - public constructor(value: TabStopType, position: string | number, leader?: LeaderType) { + public constructor(tabDef: TabStopDefinition) { super("w:tab"); this.root.push( new TabAttributes({ - val: value, - pos: position, - leader, - }), + val: tabDef.type, + pos: tabDef.position, + leader: tabDef.leader, + }) ); } } diff --git a/src/file/paragraph/properties.ts b/src/file/paragraph/properties.ts index 6f0088ac98..2acbcd2c52 100644 --- a/src/file/paragraph/properties.ts +++ b/src/file/paragraph/properties.ts @@ -9,7 +9,7 @@ import { PageBreakBefore } from "./formatting/break"; import { IIndentAttributesProperties, Indent } from "./formatting/indent"; import { ISpacingProperties, Spacing } from "./formatting/spacing"; import { HeadingLevel, Style } from "./formatting/style"; -import { LeaderType, TabStop, TabStopPosition, TabStopType } from "./formatting/tab-stop"; +import { LeaderType, TabStop, TabStopDefinition, TabStopPosition, TabStopType } from "./formatting/tab-stop"; import { NumberProperties } from "./formatting/unordered-list"; import { FrameProperties, IFrameOptions } from "./frame/frame-properties"; import { OutlineLevel } from "./links"; @@ -132,20 +132,30 @@ export class ParagraphProperties extends IgnoreIfEmptyXmlComponent { this.push(new Shading(options.shading)); } + /** + * FIX: Multitab support for Libre Writer + * Ensure there is only one w:tabs tag with multiple w:tab + */ + let tabDefs: TabStopDefinition[] = []; if (options.rightTabStop) { - this.push(new TabStop(TabStopType.RIGHT, options.rightTabStop)); + tabDefs.push({ type: TabStopType.RIGHT, position: options.rightTabStop}); } if (options.tabStops) { - for (const tabStop of options.tabStops) { - this.push(new TabStop(tabStop.type, tabStop.position, tabStop.leader)); - } + tabDefs = tabDefs.concat(options.tabStops); } if (options.leftTabStop) { - this.push(new TabStop(TabStopType.LEFT, options.leftTabStop)); + tabDefs.push({ type: TabStopType.LEFT, position: options.leftTabStop }); } + if (tabDefs.length) { + this.push(new TabStop(tabDefs)); + } + /** + * FIX - END + */ + if (options.bidirectional !== undefined) { this.push(new OnOffElement("w:bidi", options.bidirectional)); }