Skip to content

Commit

Permalink
Merge pull request #908 from gitbrent/pr855
Browse files Browse the repository at this point in the history
Pr855
  • Loading branch information
gitbrent authored Feb 25, 2021
2 parents 87a55dc + a67b701 commit 9d76c7e
Show file tree
Hide file tree
Showing 11 changed files with 64 additions and 16 deletions.
16 changes: 11 additions & 5 deletions demos/common/demos.js
Original file line number Diff line number Diff line change
Expand Up @@ -2790,14 +2790,20 @@ function genSlides_Text(pptx) {
{ x: 7.0, y: 1.0, w: 5.75, h: 1.6, valign: 'middle', align: 'center', color: '6c6c6c', fontSize: 16, fill: 'F2F2F2', line: { color: 'C7C7C7', width: '2' } }
);

// 2: Line-Spacing
slide.addText("Line-Spacing (text):", { x:7.0, y:3.3, w:'40%', h:0.3, margin:0, color:'0088CC' });
// 2: Line-Spacing (exact)
slide.addText("Line-Spacing (text):", { x:7.0, y:2.7, w:'40%', h:0.3, margin:0, color:'0088CC' });
slide.addText(
'lineSpacing\n40pt',
{ x:7.0, y:3.72, w:5.75, h:1.17, align:'center', fill:{color:'F1F1F1'}, color:'363636', lineSpacing:39.9 } // TEST-CASE: `lineSpacing` decimal value
'lineSpacing (Exactly)\n40pt',
{ x:7.0, y:3.1, w:5.75, h:1.17, align:'center', fill:{color:'F1F1F1'}, color:'363636', lineSpacing:39.9 } // TEST-CASE: `lineSpacing` decimal value
);

// 3: Line-Spacing
// 3: Line-Spacing (multiple)
slide.addText(
'lineSpacing (Multiple)\n1.5',
{ x: 7.0, y: 4.5, w: 5.75, h: 1.0, align: 'center', fill: { color: 'E6E9EC' }, color: '363636', lineSpacingMultiple: 1.5 }
);

// 4: Line-Spacing (bullets)
slide.addText("Line-Spacing (bullets):", { x:7.0, y:5.6, w:'40%', h:0.3, margin:0, color:'0088CC' });
slide.addText(
[
Expand Down
4 changes: 2 additions & 2 deletions dist/pptxgen.bundle.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion dist/pptxgen.bundle.js.map

Large diffs are not rendered by default.

10 changes: 8 additions & 2 deletions dist/pptxgen.cjs.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/* PptxGenJS 3.5.0-beta @ 2021-02-25T04:01:04.061Z */
/* PptxGenJS 3.5.0-beta @ 2021-02-25T04:05:48.293Z */
'use strict';

var JSZip = require('jszip');
Expand Down Expand Up @@ -2102,8 +2102,12 @@ function genXmlParagraphProperties(textObj, isDefault) {
break;
}
}
if (textObj.options.lineSpacing)
if (textObj.options.lineSpacing) {
strXmlLnSpc = "<a:lnSpc><a:spcPts val=\"" + Math.round(textObj.options.lineSpacing * 100) + "\"/></a:lnSpc>";
}
else if (textObj.options.lineSpacingMultiple) {
strXmlLnSpc = "<a:lnSpc><a:spcPct val=\"" + Math.round(textObj.options.lineSpacingMultiple * 100000) + "\"/></a:lnSpc>";
}
// OPTION: indent
if (textObj.options.indentLevel && !isNaN(Number(textObj.options.indentLevel)) && textObj.options.indentLevel > 0) {
paragraphPropXml += " lvl=\"" + textObj.options.indentLevel + "\"";
Expand Down Expand Up @@ -2474,6 +2478,7 @@ function genXmlTextBody(slideObj) {
// B: Inherit pPr-type options from parent shape's `options`
textObj.options.align = textObj.options.align || opts.align;
textObj.options.lineSpacing = textObj.options.lineSpacing || opts.lineSpacing;
textObj.options.lineSpacingMultiple = textObj.options.lineSpacingMultiple || opts.lineSpacingMultiple;
textObj.options.indentLevel = textObj.options.indentLevel || opts.indentLevel;
textObj.options.paraSpaceBefore = textObj.options.paraSpaceBefore || opts.paraSpaceBefore;
textObj.options.paraSpaceAfter = textObj.options.paraSpaceAfter || opts.paraSpaceAfter;
Expand Down Expand Up @@ -3890,6 +3895,7 @@ function addTextDefinition(target, text, opts, isPlaceholder) {
}
// C
newObject.options.lineSpacing = opt.lineSpacing && !isNaN(opt.lineSpacing) ? opt.lineSpacing : null;
newObject.options.lineSpacingMultiple = opt.lineSpacingMultiple && !isNaN(opt.lineSpacingMultiple) ? opt.lineSpacingMultiple : null;
// D: Transform text options to bodyProperties as thats how we build XML
newObject.options._bodyProp.autoFit = opt.autoFit || false; // @deprecated (3.3.0) If true, shape will collapse to text size (Fit To shape)
newObject.options._bodyProp.anchor = !opt.placeholder ? TEXT_VALIGN.ctr : null; // VALS: [t,ctr,b]
Expand Down
10 changes: 8 additions & 2 deletions dist/pptxgen.es.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/* PptxGenJS 3.5.0-beta @ 2021-02-25T04:01:04.067Z */
/* PptxGenJS 3.5.0-beta @ 2021-02-25T04:05:48.300Z */
import JSZip from 'jszip';

/**
Expand Down Expand Up @@ -2096,8 +2096,12 @@ function genXmlParagraphProperties(textObj, isDefault) {
break;
}
}
if (textObj.options.lineSpacing)
if (textObj.options.lineSpacing) {
strXmlLnSpc = "<a:lnSpc><a:spcPts val=\"" + Math.round(textObj.options.lineSpacing * 100) + "\"/></a:lnSpc>";
}
else if (textObj.options.lineSpacingMultiple) {
strXmlLnSpc = "<a:lnSpc><a:spcPct val=\"" + Math.round(textObj.options.lineSpacingMultiple * 100000) + "\"/></a:lnSpc>";
}
// OPTION: indent
if (textObj.options.indentLevel && !isNaN(Number(textObj.options.indentLevel)) && textObj.options.indentLevel > 0) {
paragraphPropXml += " lvl=\"" + textObj.options.indentLevel + "\"";
Expand Down Expand Up @@ -2468,6 +2472,7 @@ function genXmlTextBody(slideObj) {
// B: Inherit pPr-type options from parent shape's `options`
textObj.options.align = textObj.options.align || opts.align;
textObj.options.lineSpacing = textObj.options.lineSpacing || opts.lineSpacing;
textObj.options.lineSpacingMultiple = textObj.options.lineSpacingMultiple || opts.lineSpacingMultiple;
textObj.options.indentLevel = textObj.options.indentLevel || opts.indentLevel;
textObj.options.paraSpaceBefore = textObj.options.paraSpaceBefore || opts.paraSpaceBefore;
textObj.options.paraSpaceAfter = textObj.options.paraSpaceAfter || opts.paraSpaceAfter;
Expand Down Expand Up @@ -3884,6 +3889,7 @@ function addTextDefinition(target, text, opts, isPlaceholder) {
}
// C
newObject.options.lineSpacing = opt.lineSpacing && !isNaN(opt.lineSpacing) ? opt.lineSpacing : null;
newObject.options.lineSpacingMultiple = opt.lineSpacingMultiple && !isNaN(opt.lineSpacingMultiple) ? opt.lineSpacingMultiple : null;
// D: Transform text options to bodyProperties as thats how we build XML
newObject.options._bodyProp.autoFit = opt.autoFit || false; // @deprecated (3.3.0) If true, shape will collapse to text size (Fit To shape)
newObject.options._bodyProp.anchor = !opt.placeholder ? TEXT_VALIGN.ctr : null; // VALS: [t,ctr,b]
Expand Down
4 changes: 2 additions & 2 deletions dist/pptxgen.min.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion dist/pptxgen.min.js.map

Large diffs are not rendered by default.

12 changes: 12 additions & 0 deletions src/core-interfaces.ts
Original file line number Diff line number Diff line change
Expand Up @@ -866,7 +866,19 @@ export interface TextPropsOptions extends PositionProps, DataOrPathProps, TextBa
inset?: number
isTextBox?: boolean
line?: ShapeLineProps
/**
* Line spacing (pt)
* - PowerPoint: Paragraph > Indents and Spacing > Line Spacing: > "Exactly"
* @example 28 // 28pt
*/
lineSpacing?: number
/**
* line spacing multiple (percent)
* - range (0.0 - 9.99)
* - PowerPoint: Paragraph > Indents and Spacing > Line Spacing: > "Multiple"
* @example 1.5 // 1.5X line spacing
*/
lineSpacingMultiple?: number
margin?: Margin
outline?: { color: Color; size: number }
paraSpaceAfter?: number
Expand Down
1 change: 1 addition & 0 deletions src/gen-objects.ts
Original file line number Diff line number Diff line change
Expand Up @@ -949,6 +949,7 @@ export function addTextDefinition(target: PresSlide, text: string | TextProps[],

// C
newObject.options.lineSpacing = opt.lineSpacing && !isNaN(opt.lineSpacing) ? opt.lineSpacing : null
newObject.options.lineSpacingMultiple = opt.lineSpacingMultiple && !isNaN(opt.lineSpacingMultiple) ? opt.lineSpacingMultiple : null

// D: Transform text options to bodyProperties as thats how we build XML
newObject.options._bodyProp.autoFit = opt.autoFit || false // @deprecated (3.3.0) If true, shape will collapse to text size (Fit To shape)
Expand Down
7 changes: 6 additions & 1 deletion src/gen-xml.ts
Original file line number Diff line number Diff line change
Expand Up @@ -849,7 +849,11 @@ function genXmlParagraphProperties(textObj: ISlideObject | TextProps, isDefault:
}
}

if (textObj.options.lineSpacing) strXmlLnSpc = `<a:lnSpc><a:spcPts val="${Math.round(textObj.options.lineSpacing * 100)}"/></a:lnSpc>`
if (textObj.options.lineSpacing) {
strXmlLnSpc = `<a:lnSpc><a:spcPts val="${Math.round(textObj.options.lineSpacing * 100)}"/></a:lnSpc>`
} else if (textObj.options.lineSpacingMultiple) {
strXmlLnSpc = `<a:lnSpc><a:spcPct val="${Math.round(textObj.options.lineSpacingMultiple * 100000)}"/></a:lnSpc>`
}

// OPTION: indent
if (textObj.options.indentLevel && !isNaN(Number(textObj.options.indentLevel)) && textObj.options.indentLevel > 0) {
Expand Down Expand Up @@ -1246,6 +1250,7 @@ export function genXmlTextBody(slideObj: ISlideObject | TableCell): string {
// B: Inherit pPr-type options from parent shape's `options`
textObj.options.align = textObj.options.align || opts.align
textObj.options.lineSpacing = textObj.options.lineSpacing || opts.lineSpacing
textObj.options.lineSpacingMultiple = textObj.options.lineSpacingMultiple || opts.lineSpacingMultiple
textObj.options.indentLevel = textObj.options.indentLevel || opts.indentLevel
textObj.options.paraSpaceBefore = textObj.options.paraSpaceBefore || opts.paraSpaceBefore
textObj.options.paraSpaceAfter = textObj.options.paraSpaceAfter || opts.paraSpaceAfter
Expand Down
12 changes: 12 additions & 0 deletions types/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1621,7 +1621,19 @@ declare namespace PptxGenJS {
inset?: number
isTextBox?: boolean
line?: ShapeLineProps
/**
* Line spacing (pt)
* - PowerPoint: Paragraph > Indents and Spacing > Line Spacing: > "Exactly"
* @example 28 // 28pt
*/
lineSpacing?: number
/**
* line spacing multiple (percent)
* - range (0.0 - 9.99)
* - PowerPoint: Paragraph > Indents and Spacing > Line Spacing: > "Multiple"
* @example 1.5 // 1.5X line spacing
*/
lineSpacingMultiple?: number
margin?: Margin
outline?: { color: Color; size: number }
paraSpaceAfter?: number
Expand Down

0 comments on commit 9d76c7e

Please # to comment.