From 5728d13949e2536a4562b336ff2007e6cff0ccb0 Mon Sep 17 00:00:00 2001 From: wangfengming Date: Sat, 17 Oct 2020 19:11:18 +0800 Subject: [PATCH] support tab stops --- src/core-interfaces.ts | 7 +++++++ src/gen-xml.ts | 15 +++++++++++++-- types/index.d.ts | 5 +++++ 3 files changed, 25 insertions(+), 2 deletions(-) diff --git a/src/core-interfaces.ts b/src/core-interfaces.ts index 30903ef86..a49ac3824 100644 --- a/src/core-interfaces.ts +++ b/src/core-interfaces.ts @@ -82,6 +82,8 @@ export type Color = HexColor | ThemeColor export type Margin = number | [number, number, number, number] export type HAlign = 'left' | 'center' | 'right' | 'justify' export type VAlign = 'top' | 'middle' | 'bottom' +export type TabStopAlign = 'l' | 'r' | 'ctr' | 'dec' + // used by charts, shape, text export interface BorderProps { /** @@ -375,6 +377,11 @@ export interface TextBaseProps { * @default 'top' */ valign?: VAlign + + /** + * tab stops + */ + tabStops?: (number | string | {position: number | string; alignment: TabStopAlign})[] } // image / media ================================================================================== diff --git a/src/gen-xml.ts b/src/gen-xml.ts index 4e899cceb..80fe9af5d 100644 --- a/src/gen-xml.ts +++ b/src/gen-xml.ts @@ -821,7 +821,8 @@ function slideObjectRelationsToXml(slide: PresSlide | SlideLayout, defaultRels: function genXmlParagraphProperties(textObj: ISlideObject | TextProps, isDefault: boolean): string { let strXmlBullet = '', strXmlLnSpc = '', - strXmlParaSpc = '' + strXmlParaSpc = '', + strXmlTabStops = '' let tag = isDefault ? 'a:lvl1pPr' : 'a:pPr' let bulletMarL = valToPts(DEF_BULLET_MARGIN) @@ -924,9 +925,19 @@ function genXmlParagraphProperties(textObj: ISlideObject | TextProps, isDefault: strXmlBullet = '' } + // OPTION: tabStops + if (textObj.options.tabStops?.length) { + let tabStopsXml = textObj.options.tabStops.map(stop => { + let pos = inch2Emu(typeof stop === "object" ? stop.position : stop) + let algn = typeof stop === "object" ? stop.alignment : 'l' + return `` + }).join('') + strXmlTabStops = `${tabStopsXml}` + } + // B: Close Paragraph-Properties // IMPORTANT: strXmlLnSpc, strXmlParaSpc, and strXmlBullet require strict ordering - anything out of order is ignored. (PPT-Online, PPT for Mac) - paragraphPropXml += '>' + strXmlLnSpc + strXmlParaSpc + strXmlBullet + paragraphPropXml += '>' + strXmlLnSpc + strXmlParaSpc + strXmlBullet + strXmlTabStops if (isDefault) paragraphPropXml += genXmlTextRunProperties(textObj.options, true) paragraphPropXml += '' } diff --git a/types/index.d.ts b/types/index.d.ts index 1445c913b..5348bbd9a 100644 --- a/types/index.d.ts +++ b/types/index.d.ts @@ -900,6 +900,7 @@ declare namespace PptxGenJS { export type Margin = number | [number, number, number, number] export type HAlign = 'left' | 'center' | 'right' | 'justify' export type VAlign = 'top' | 'middle' | 'bottom' + export type TabStopAlign = 'l' | 'r' | 'ctr' | 'dec' // used by charts, shape, text export interface BorderProps { /** @@ -1191,6 +1192,10 @@ declare namespace PptxGenJS { * @default 'top' */ valign?: VAlign + /** + * tab stops + */ + tabStops?: (number | string | {position: number | string; alignment: TabStopAlign})[] } // image / media ==================================================================================