From 272e247c97f3305d6de452c9817b1d8029b3160c Mon Sep 17 00:00:00 2001 From: Dolan Miu Date: Sun, 24 Dec 2023 03:19:21 +0000 Subject: [PATCH] Add default tab stop --- demo/75-tab-stops.ts | 7 ++++--- src/file/core-properties/properties.ts | 1 + src/file/file.ts | 1 + src/file/settings/settings.ts | 8 +++++++- 4 files changed, 13 insertions(+), 4 deletions(-) diff --git a/demo/75-tab-stops.ts b/demo/75-tab-stops.ts index 4f8768a6c85..b379fc01a6e 100644 --- a/demo/75-tab-stops.ts +++ b/demo/75-tab-stops.ts @@ -11,13 +11,14 @@ const receiptTabStops = [ // (end position of 1st) + (end position of current) // columnWidth + columnWidth = columnWidth * 2 - { type: TabStopType.RIGHT, position: columnWidth * 2 }, - { type: TabStopType.RIGHT, position: columnWidth * 3 }, - { type: TabStopType.RIGHT, position: TabStopPosition.MAX }, + { type: TabStopType.RIGHT, position: 0 }, + { type: TabStopType.RIGHT, position: 0 }, + { type: TabStopType.RIGHT, position: 0 }, ]; const twoTabStops = [{ type: TabStopType.RIGHT, position: TabStopPosition.MAX }]; const doc = new Document({ + defaultTabStop: 0, sections: [ { properties: {}, diff --git a/src/file/core-properties/properties.ts b/src/file/core-properties/properties.ts index b09b2d97d0c..d2628021428 100644 --- a/src/file/core-properties/properties.ts +++ b/src/file/core-properties/properties.ts @@ -39,6 +39,7 @@ export interface IPropertiesOptions { readonly compatibility?: ICompatibilityOptions; readonly customProperties?: readonly ICustomPropertyOptions[]; readonly evenAndOddHeaderAndFooters?: boolean; + readonly defaultTabStop?: number; } // diff --git a/src/file/file.ts b/src/file/file.ts index 136380be9fd..1046d874a57 100644 --- a/src/file/file.ts +++ b/src/file/file.ts @@ -77,6 +77,7 @@ export class File { evenAndOddHeaders: options.evenAndOddHeaderAndFooters ? true : false, trackRevisions: options.features?.trackRevisions, updateFields: options.features?.updateFields, + defaultTabStop: options.defaultTabStop, }); this.media = new Media(); diff --git a/src/file/settings/settings.ts b/src/file/settings/settings.ts index 76fe4c51fb7..ad89de7b497 100644 --- a/src/file/settings/settings.ts +++ b/src/file/settings/settings.ts @@ -1,4 +1,4 @@ -import { OnOffElement, XmlAttributeComponent, XmlComponent } from "@file/xml-components"; +import { NumberValueElement, OnOffElement, XmlAttributeComponent, XmlComponent } from "@file/xml-components"; import { Compatibility, ICompatibilityOptions } from "./compatibility"; @@ -152,6 +152,7 @@ export interface ISettingsOptions { readonly trackRevisions?: boolean; readonly updateFields?: boolean; readonly compatibility?: ICompatibilityOptions; + readonly defaultTabStop?: number; } export class Settings extends XmlComponent { @@ -198,6 +199,11 @@ export class Settings extends XmlComponent { this.root.push(new OnOffElement("w:updateFields", options.updateFields)); } + // https://c-rex.net/samples/ooxml/e1/Part4/OOXML_P4_DOCX_defaultTabStop_topic_ID0EIXSX.html + if (options.defaultTabStop !== undefined) { + this.root.push(new NumberValueElement("w:defaultTabStop", options.defaultTabStop)); + } + this.root.push( new Compatibility({ ...(options.compatibility ?? {}),