Skip to content

Commit

Permalink
Add default tab stop
Browse files Browse the repository at this point in the history
  • Loading branch information
dolanmiu committed Dec 24, 2023
1 parent 1346eed commit 272e247
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 4 deletions.
7 changes: 4 additions & 3 deletions demo/75-tab-stops.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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: {},
Expand Down
1 change: 1 addition & 0 deletions src/file/core-properties/properties.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ export interface IPropertiesOptions {
readonly compatibility?: ICompatibilityOptions;
readonly customProperties?: readonly ICustomPropertyOptions[];
readonly evenAndOddHeaderAndFooters?: boolean;
readonly defaultTabStop?: number;
}

// <xs:element name="coreProperties" type="CT_CoreProperties"/>
Expand Down
1 change: 1 addition & 0 deletions src/file/file.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
8 changes: 7 additions & 1 deletion src/file/settings/settings.ts
Original file line number Diff line number Diff line change
@@ -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";

Expand Down Expand Up @@ -152,6 +152,7 @@ export interface ISettingsOptions {
readonly trackRevisions?: boolean;
readonly updateFields?: boolean;
readonly compatibility?: ICompatibilityOptions;
readonly defaultTabStop?: number;
}

export class Settings extends XmlComponent {
Expand Down Expand Up @@ -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));
}

Check warning on line 205 in src/file/settings/settings.ts

View check run for this annotation

Codecov / codecov/patch

src/file/settings/settings.ts#L204-L205

Added lines #L204 - L205 were not covered by tests

this.root.push(
new Compatibility({
...(options.compatibility ?? {}),
Expand Down

0 comments on commit 272e247

Please sign in to comment.