Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

support tab stops #853

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions src/core-interfaces.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
/**
Expand Down Expand Up @@ -381,6 +383,11 @@ export interface TextBaseProps {
* @default 'top'
*/
valign?: VAlign

/**
* tab stops
*/
tabStops?: (number | string | {position: number | string; alignment: TabStopAlign})[]
}

// image / media ==================================================================================
Expand Down
15 changes: 13 additions & 2 deletions src/gen-xml.ts
Original file line number Diff line number Diff line change
Expand Up @@ -820,7 +820,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)

Expand Down Expand Up @@ -927,9 +928,19 @@ function genXmlParagraphProperties(textObj: ISlideObject | TextProps, isDefault:
strXmlBullet = '<a:buNone/>'
}

// 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 `<a:tab pos="${pos}" algn="${algn}"/>`
}).join('')
strXmlTabStops = `<a:tabLst>${tabStopsXml}</a:tabLst>`
}

// B: Close Paragraph-Properties
// IMPORTANT: strXmlLnSpc, strXmlParaSpc, and strXmlBullet require strict ordering - anything out of order is ignored. (PPT-Online, PPT for Mac)
let childPropXml = strXmlLnSpc + strXmlParaSpc + strXmlBullet
let childPropXml = strXmlLnSpc + strXmlParaSpc + strXmlBullet + strXmlTabStops
if (isDefault) childPropXml += genXmlTextRunProperties(textObj.options, true)
if (childPropXml) {
paragraphPropXml += '>' + childPropXml + '</' + tag + '>'
Expand Down
5 changes: 5 additions & 0 deletions types/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -896,6 +896,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 {
/**
Expand Down Expand Up @@ -1193,6 +1194,10 @@ declare namespace PptxGenJS {
* @default 'top'
*/
valign?: VAlign
/**
* tab stops
*/
tabStops?: (number | string | {position: number | string; alignment: TabStopAlign})[]
}

// image / media ==================================================================================
Expand Down