Skip to content

Commit

Permalink
added textDirection for text/table cells
Browse files Browse the repository at this point in the history
  • Loading branch information
gitbrent committed May 17, 2023
1 parent 8c697bb commit 7c778ec
Show file tree
Hide file tree
Showing 6 changed files with 29 additions and 7 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

## [3.13.0] - 2023-0?-0?

- Added `textDirection` property for text and table cells to allow vertical rotation of text ([gitbrent](https://github.com/gitbrent))

## [3.12.0] - 2023-03-19

### Added
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "pptxgenjs",
"version": "3.13.0-beta",
"version": "3.13.0-beta.0",
"author": {
"name": "Brent Ely",
"url": "https://github.com/gitbrent/"
Expand Down
9 changes: 9 additions & 0 deletions src/core-interfaces.ts
Original file line number Diff line number Diff line change
Expand Up @@ -391,6 +391,15 @@ export interface TextBaseProps {
* @example [{ position:1 }, { position:3 }] // Set first tab stop to 1 inch, set second tab stop to 3 inches
*/
tabStops?: Array<{ position: number, alignment?: 'l' | 'r' | 'ctr' | 'dec' }>
/**
* text direction
* `horz` = horizontal
* `vert` = rotate 90^
* `vert270` = rotate 270^
* `wordArtVert` = stacked
* @default 'horz'
*/
textDirection?: 'horz' | 'vert' | 'vert270' | 'wordArtVert'
/**
* Transparency (percent)
* - MS-PPT > Format Shape > Text Options > Text Fill & Outline > Text Fill > Transparency
Expand Down
6 changes: 4 additions & 2 deletions src/gen-xml.ts
Original file line number Diff line number Diff line change
Expand Up @@ -299,13 +299,15 @@ function slideObjectToXml (slide: PresSlide | SlideLayout): string {

// B: Inherit some options from table when cell options dont exist
// @see: http://officeopenxml.com/drwTableCellProperties-alignment.php
;['align', 'bold', 'border', 'color', 'fill', 'fontFace', 'fontSize', 'margin', 'underline', 'valign'].forEach(name => {
;['align', 'bold', 'border', 'color', 'fill', 'fontFace', 'fontSize', 'margin', 'textDirection', 'underline', 'valign'].forEach(name => {
if (objTabOpts[name] && !cellOpts[name] && cellOpts[name] !== 0) cellOpts[name] = objTabOpts[name]
})

const cellValign = cellOpts.valign
? ` anchor="${cellOpts.valign.replace(/^c$/i, 'ctr').replace(/^m$/i, 'ctr').replace('center', 'ctr').replace('middle', 'ctr').replace('top', 't').replace('btm', 'b').replace('bottom', 'b')}"`
: ''
const cellTextDir = (cellOpts.textDirection && cellOpts.textDirection !== 'horz') ? ` vert="${cellOpts.textDirection}"` : ''

let fillColor =
cell._optImp?.fill?.color
? cell._optImp.fill.color
Expand Down Expand Up @@ -335,7 +337,7 @@ function slideObjectToXml (slide: PresSlide | SlideLayout): string {
// FUTURE: Cell NOWRAP property (textwrap: add to a:tcPr (horzOverflow="overflow" or whatever options exist)

// 4: Set CELL content and properties ==================================
strXml += `<a:tc${cellSpanAttrStr}>${genXmlTextBody(cell)}<a:tcPr${cellMarginXml}${cellValign}>`
strXml += `<a:tc${cellSpanAttrStr}>${genXmlTextBody(cell)}<a:tcPr${cellMarginXml}${cellValign}${cellTextDir}>`
// strXml += `<a:tc${cellColspan}${cellRowspan}>${genXmlTextBody(cell)}<a:tcPr${cellMarginXml}${cellValign}${cellTextDir}>`
// FIXME: 20200525: ^^^
// <a:tcPr marL="38100" marR="38100" marT="38100" marB="38100" vert="vert270">
Expand Down
2 changes: 1 addition & 1 deletion src/pptxgen.ts
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ import * as genMedia from './gen-media'
import * as genTable from './gen-tables'
import * as genXml from './gen-xml'

const VERSION = '3.13.0-beta-20230415-2112'
const VERSION = '3.13.0-beta.0-20230416-2140'

export default class PptxGenJS implements IPresentationProps {
// Property getters/setters
Expand Down
15 changes: 12 additions & 3 deletions types/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -906,7 +906,7 @@ declare namespace PptxGenJS {
* @deprecated v3.6.0 - use `DataOrPathProps` instead - remove in v4.0.0
*/
src?: string
}
}
/**
* Color in Hex format
* @example 'FF3399'
Expand Down Expand Up @@ -1220,6 +1220,15 @@ declare namespace PptxGenJS {
* @example [{ position:1 }, { position:3 }] // Set first tab stop to 1 inch, set second tab stop to 3 inches
*/
tabStops?: Array<{ position: number, alignment?: 'l' | 'r' | 'ctr' | 'dec' }>
/**
* text direction
* `horz` = horizontal
* `vert` = rotate 90^
* `vert270` = rotate 270^
* `wordArtVert` = stacked
* @default 'horz'
*/
textDirection?: 'horz' | 'vert' | 'vert270' | 'wordArtVert'
/**
* Transparency (percent)
* - MS-PPT > Format Shape > Text Options > Text Fill & Outline > Text Fill > Transparency
Expand Down Expand Up @@ -2486,7 +2495,7 @@ declare namespace PptxGenJS {
background?: BackgroundProps
margin?: Margin
slideNumber?: SlideNumberProps
objects?: Array< | { chart: IChartOpts }
objects?: Array<| { chart: IChartOpts }
| { image: ImageProps }
| { line: ShapeProps }
| { rect: ShapeProps }
Expand All @@ -2500,7 +2509,7 @@ declare namespace PptxGenJS {
*/
text?: string
}
}>
}>

/**
* @deprecated v3.3.0 - use `background`
Expand Down

0 comments on commit 7c778ec

Please sign in to comment.