From 426338d38e83209b172dde390cbbdfba04b56493 Mon Sep 17 00:00:00 2001 From: Michael Brook Date: Wed, 2 Sep 2020 14:48:11 -0500 Subject: [PATCH 1/5] Fixed lineSpacing round-off error by rounding AFTER multiplying by 100 --- dist/pptxgen.es.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/dist/pptxgen.es.js b/dist/pptxgen.es.js index 6f087d5cb..1b0a093e8 100644 --- a/dist/pptxgen.es.js +++ b/dist/pptxgen.es.js @@ -2078,7 +2078,7 @@ function genXmlParagraphProperties(textObj, isDefault) { } } if (textObj.options.lineSpacing) - strXmlLnSpc = ""; + strXmlLnSpc = ""; // OPTION: indent if (textObj.options.indentLevel && !isNaN(Number(textObj.options.indentLevel)) && textObj.options.indentLevel > 0) { paragraphPropXml += " lvl=\"" + textObj.options.indentLevel + "\""; From db6222de17f20431a11deb77f58d5aace7acb9e1 Mon Sep 17 00:00:00 2001 From: Michael Brook Date: Wed, 2 Sep 2020 15:08:56 -0500 Subject: [PATCH 2/5] Updated CommonJS version --- dist/pptxgen.cjs.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/dist/pptxgen.cjs.js b/dist/pptxgen.cjs.js index 2dc379dea..bf2204f2c 100644 --- a/dist/pptxgen.cjs.js +++ b/dist/pptxgen.cjs.js @@ -2080,7 +2080,7 @@ function genXmlParagraphProperties(textObj, isDefault) { } } if (textObj.options.lineSpacing) - strXmlLnSpc = ""; + strXmlLnSpc = ""; // OPTION: indent if (textObj.options.indentLevel && !isNaN(Number(textObj.options.indentLevel)) && textObj.options.indentLevel > 0) { paragraphPropXml += " lvl=\"" + textObj.options.indentLevel + "\""; From b7b4ed0abfa0b6fbeb9bac33dae3bb222ad2f51c Mon Sep 17 00:00:00 2001 From: Michael Brook Date: Wed, 2 Sep 2020 17:10:24 -0500 Subject: [PATCH 3/5] Fixed rounding mistakes on lineSpacing (does not protect against round-off errors), all font sizes (resulting in greater accuracy), rotation angles (only accepted up to four decimal places before), shapeFill alpha and transparency (did not allow decimals), and chartColorsOpacity (same) --- dist/pptxgen.cjs.js | 44 ++++++++++++++++++++++---------------------- dist/pptxgen.es.js | 2 +- 2 files changed, 23 insertions(+), 23 deletions(-) diff --git a/dist/pptxgen.cjs.js b/dist/pptxgen.cjs.js index bf2204f2c..87b1f63d7 100644 --- a/dist/pptxgen.cjs.js +++ b/dist/pptxgen.cjs.js @@ -706,7 +706,7 @@ function valToPts(pt) { */ function convertRotationDegrees(d) { d = d || 0; - return (d > 360 ? d - 360 : d) * 60000; + return Math.round((d > 360 ? d - 360 : d) * 60000); } /** * Converts component value to hex value @@ -791,9 +791,9 @@ function genXmlColorSelection(shapeFill, backColor) { if (shapeFill.color) colorVal = shapeFill.color; if (shapeFill.alpha) - internalElements += ""; // @deprecated v3.3.0 + internalElements += ""; // @deprecated v3.3.0 if (shapeFill.transparency) - internalElements += ""; + internalElements += ""; } switch (fillType) { case 'solid': @@ -1938,7 +1938,7 @@ function slideObjectToXml(slide) { strSlideXml += ' '; strSlideXml += ' '; if (slide._slideNumberProps.fontFace || slide._slideNumberProps.fontSize || slide._slideNumberProps.color) { - strSlideXml += ''; + strSlideXml += ''; if (slide._slideNumberProps.color) strSlideXml += genXmlColorSelection(slide._slideNumberProps.color); if (slide._slideNumberProps.fontFace) @@ -2159,7 +2159,7 @@ function genXmlTextRunProperties(opts, isDefault) { var runPropsTag = isDefault ? 'a:defRPr' : 'a:rPr'; // BEGIN runProperties (ex: ``) runProps += '<' + runPropsTag + ' lang="' + (opts.lang ? opts.lang : 'en-US') + '"' + (opts.lang ? ' altLang="en-US"' : ''); - runProps += opts.fontSize ? ' sz="' + Math.round(opts.fontSize) + '00"' : ''; // NOTE: Use round so sizes like '7.5' wont cause corrupt pres. + runProps += opts.fontSize ? ' sz="' + Math.round(opts.fontSize * 100) + '"' : ''; // NOTE: Use round so sizes like '7.5' wont cause corrupt pres. runProps += opts.bold ? ' b="1"' : ''; runProps += opts.italic ? ' i="1"' : ''; runProps += opts.strike ? ' strike="sngStrike"' : ''; @@ -2465,19 +2465,19 @@ function genXmlTextBody(slideObj) { */ if (slideObj._type === SLIDE_OBJECT_TYPES.tablecell && (opts.fontSize || opts.fontFace)) { if (opts.fontFace) { - strSlideXml += "'; + strSlideXml += "'; strSlideXml += ""; strSlideXml += ""; strSlideXml += ""; strSlideXml += ''; } else { - strSlideXml += "'; + strSlideXml += "'; } } else if (reqsClosingFontSize) { // Empty [lineBreak] lines should not contain runProp, however, they need to specify fontSize in `endParaRPr` - strSlideXml += "'; + strSlideXml += "'; } else { strSlideXml += ""; // Added 20180101 to address PPT-2007 issues @@ -4611,7 +4611,7 @@ function makeXmlCharts(rel) { strXml += ' '; strXml += ' '; strXml += ' '; - strXml += " "; + strXml += " "; strXml += ' '; strXml += ' '; strXml += ' '; @@ -4645,7 +4645,7 @@ function makeXmlCharts(rel) { strXml += ' '; strXml += ' '; strXml += ' '; - strXml += rel.opts.legendFontSize ? '' : ''; + strXml += rel.opts.legendFontSize ? '' : ''; if (rel.opts.legendColor) strXml += genXmlColorSelection(rel.opts.legendColor); if (rel.opts.legendFontFace) @@ -4751,7 +4751,7 @@ function makeChartType(chartType, data, opts, valAxisId, catAxisId, isMultiTypeC strXml += ''; } else if (opts.chartColorsOpacity) { - strXml += '' + createColorElement(seriesColor, '') + ''; + strXml += '' + createColorElement(seriesColor, '') + ''; } else { strXml += '' + createColorElement(seriesColor) + ''; @@ -4789,7 +4789,7 @@ function makeChartType(chartType, data, opts, valAxisId, catAxisId, isMultiTypeC strXml += ' '; strXml += ' '; strXml += ' '; - strXml += ' '; + strXml += ' '; strXml += ' ' + createColorElement(opts.dataLabelColor || DEF_FONT_COLOR) + ''; strXml += ' '; strXml += ' '; @@ -4922,7 +4922,7 @@ function makeChartType(chartType, data, opts, valAxisId, catAxisId, isMultiTypeC strXml += ' '; strXml += ' '; strXml += - ' '; + ' '; strXml += ' ' + createColorElement(opts.dataLabelColor || DEF_FONT_COLOR) + ''; strXml += ' '; strXml += ' '; @@ -4996,7 +4996,7 @@ function makeChartType(chartType, data, opts, valAxisId, catAxisId, isMultiTypeC strXml += ''; } else if (opts.chartColorsOpacity) { - strXml += '' + createColorElement(tmpSerColor, '') + ''; + strXml += '' + createColorElement(tmpSerColor, '') + ''; } else { strXml += '' + createColorElement(tmpSerColor) + ''; @@ -5224,7 +5224,7 @@ function makeChartType(chartType, data, opts, valAxisId, catAxisId, isMultiTypeC strXml += ' '; strXml += ' '; strXml += ' '; - strXml += ' '; + strXml += ' '; strXml += ' ' + createColorElement(opts.dataLabelColor || DEF_FONT_COLOR) + ''; strXml += ' '; strXml += ' '; @@ -5281,7 +5281,7 @@ function makeChartType(chartType, data, opts, valAxisId, catAxisId, isMultiTypeC strXml += ''; } else if (opts.chartColorsOpacity) { - strXml += '' + createColorElement(tmpSerColor, '') + ''; + strXml += '' + createColorElement(tmpSerColor, '') + ''; } else { strXml += '' + createColorElement(tmpSerColor) + ''; @@ -5364,7 +5364,7 @@ function makeChartType(chartType, data, opts, valAxisId, catAxisId, isMultiTypeC strXml += ' '; strXml += ' '; strXml += ' '; - strXml += ' '; + strXml += ' '; strXml += ' ' + createColorElement(opts.dataLabelColor || DEF_FONT_COLOR) + ''; strXml += ' '; strXml += ' '; @@ -5453,7 +5453,7 @@ function makeChartType(chartType, data, opts, valAxisId, catAxisId, isMultiTypeC strXml += ' '; strXml += ' '; strXml += ' '; - strXml += " "; + strXml += " "; strXml += ' ' + createColorElement(opts.dataLabelColor || DEF_FONT_COLOR) + ''; strXml += " "; strXml += ' '; @@ -5595,7 +5595,7 @@ function makeCatAxis(opts, axisId, valAxisId) { strXml += ' '; strXml += ' '; strXml += ' '; - strXml += ' '; + strXml += ' '; strXml += ' '; strXml += ' '; strXml += ' '; @@ -5698,7 +5698,7 @@ function makeValAxis(opts, valAxisId) { strXml += ' '; strXml += ' '; strXml += ' '; - strXml += ' '; + strXml += ' '; strXml += ' '; strXml += ' '; strXml += ' '; @@ -5763,7 +5763,7 @@ function makeSerAxis(opts, axisId, valAxisId) { strXml += ' '; strXml += ' '; strXml += ' '; - strXml += ' '; + strXml += ' '; strXml += ' '; strXml += ' '; strXml += ' '; @@ -5807,7 +5807,7 @@ function makeSerAxis(opts, axisId, valAxisId) { function genXmlTitle(opts) { var align = opts.titleAlign === 'left' || opts.titleAlign === 'right' ? "" : ""; var rotate = opts.rotate ? "" : ""; // don't specify rotation to get default (ex. vertical for cat axis) - var sizeAttr = opts.fontSize ? 'sz="' + Math.round(opts.fontSize) + '00"' : ''; // only set the font size if specified. Powerpoint will handle the default size + var sizeAttr = opts.fontSize ? 'sz="' + Math.round(opts.fontSize * 100) + '"' : ''; // only set the font size if specified. Powerpoint will handle the default size var layout = opts.titlePos && opts.titlePos.x && opts.titlePos.y ? "" : ""; diff --git a/dist/pptxgen.es.js b/dist/pptxgen.es.js index 1b0a093e8..6f087d5cb 100644 --- a/dist/pptxgen.es.js +++ b/dist/pptxgen.es.js @@ -2078,7 +2078,7 @@ function genXmlParagraphProperties(textObj, isDefault) { } } if (textObj.options.lineSpacing) - strXmlLnSpc = ""; + strXmlLnSpc = ""; // OPTION: indent if (textObj.options.indentLevel && !isNaN(Number(textObj.options.indentLevel)) && textObj.options.indentLevel > 0) { paragraphPropXml += " lvl=\"" + textObj.options.indentLevel + "\""; From 1c3109cbb1413ca3bcd467886dd2725d78cb9e27 Mon Sep 17 00:00:00 2001 From: Michael Brook Date: Mon, 7 Sep 2020 10:54:07 -0500 Subject: [PATCH 4/5] Rounded additional values, and fixed a bug where word-level text with a bold, italic, strike, or underline value set explicitly to false inherits the value of the parent textbox instead of removing styling. --- dist/pptxgen.cjs.js | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/dist/pptxgen.cjs.js b/dist/pptxgen.cjs.js index 87b1f63d7..9f3c28796 100644 --- a/dist/pptxgen.cjs.js +++ b/dist/pptxgen.cjs.js @@ -762,7 +762,7 @@ function createColorElement(colorStr, innerElements) { * { size: 8, color: 'FFFFFF', opacity: 0.75 }; */ function createGlowElement(options, defaults) { - var strXml = '', opts = getMix(defaults, options), size = opts['size'] * ONEPT, color = opts['color'], opacity = opts['opacity'] * 100000; + var strXml = '', opts = getMix(defaults, options), size = Math.round(opts['size'] * ONEPT), color = opts['color'], opacity = Math.round(opts['opacity'] * 100000); strXml += ""; strXml += createColorElement(color, ""); strXml += ""; @@ -2087,10 +2087,10 @@ function genXmlParagraphProperties(textObj, isDefault) { } // OPTION: Paragraph Spacing: Before/After if (textObj.options.paraSpaceBefore && !isNaN(Number(textObj.options.paraSpaceBefore)) && textObj.options.paraSpaceBefore > 0) { - strXmlParaSpc += ""; + strXmlParaSpc += ""; } if (textObj.options.paraSpaceAfter && !isNaN(Number(textObj.options.paraSpaceAfter)) && textObj.options.paraSpaceAfter > 0) { - strXmlParaSpc += ""; + strXmlParaSpc += ""; } // OPTION: bullet // NOTE: OOXML uses the unicode character set for Bullets @@ -2160,12 +2160,12 @@ function genXmlTextRunProperties(opts, isDefault) { // BEGIN runProperties (ex: ``) runProps += '<' + runPropsTag + ' lang="' + (opts.lang ? opts.lang : 'en-US') + '"' + (opts.lang ? ' altLang="en-US"' : ''); runProps += opts.fontSize ? ' sz="' + Math.round(opts.fontSize * 100) + '"' : ''; // NOTE: Use round so sizes like '7.5' wont cause corrupt pres. - runProps += opts.bold ? ' b="1"' : ''; - runProps += opts.italic ? ' i="1"' : ''; - runProps += opts.strike ? ' strike="sngStrike"' : ''; - runProps += opts.underline || opts.hyperlink ? ' u="sng"' : ''; + runProps += opts.hasOwnProperty("bold") ? ' b="' + (opts.bold ? 1 : 0) + '"' : ''; + runProps += opts.hasOwnProperty("italic") ? ' i="' + (opts.italic ? 1 : 0) + '"' : ''; + runProps += opts.hasOwnProperty("strike") ? ' strike="' + (opts.strike ? 'sngStrike' : 'noStrike') + '"' : ''; + runProps += opts.hasOwnProperty("underline") || opts.hyperlink ? ' u="' + (opts.underline || opts.hyperlink ? 'sng' : 'none') + '"' : ''; runProps += opts.subscript ? ' baseline="-40000"' : opts.superscript ? ' baseline="30000"' : ''; - runProps += opts.charSpacing ? ' spc="' + opts.charSpacing * 100 + '" kern="0"' : ''; // IMPORTANT: Also disable kerning; otherwise text won't actually expand + runProps += opts.charSpacing ? ' spc="' + Math.round(opts.charSpacing * 100) + '" kern="0"' : ''; // IMPORTANT: Also disable kerning; otherwise text won't actually expand runProps += ' dirty="0">'; // Color / Font / Outline are children of , so add them now before closing the runProperties tag if (opts.color || opts.fontFace || opts.outline) { @@ -5845,7 +5845,7 @@ function createShadowElement(options, defaults) { console.warn("`shadow` options must be an object. Ex: `{shadow: {type:'none'}}`"); return ''; } - var strXml = '', opts = getMix(defaults, options), type = opts['type'] || 'outer', blur = valToPts(opts['blur']), offset = valToPts(opts['offset']), angle = opts['angle'] * 60000, color = opts['color'], opacity = opts['opacity'] * 100000, rotateWithShape = opts['rotateWithShape'] ? 1 : 0; + var strXml = '', opts = getMix(defaults, options), type = opts['type'] || 'outer', blur = valToPts(opts['blur']), offset = valToPts(opts['offset']), angle = Math.round(opts['angle'] * 60000), color = opts['color'], opacity = Math.round(opts['opacity'] * 100000), rotateWithShape = opts['rotateWithShape'] ? 1 : 0; strXml += ''; From f270d4ab2df155ad74569486865094a4fb80ad7d Mon Sep 17 00:00:00 2001 From: Michael Brook Date: Mon, 7 Sep 2020 12:52:47 -0500 Subject: [PATCH 5/5] Fix for last commit (negation of word-level formatting) --- dist/pptxgen.cjs.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/dist/pptxgen.cjs.js b/dist/pptxgen.cjs.js index 9f3c28796..93f26ca56 100644 --- a/dist/pptxgen.cjs.js +++ b/dist/pptxgen.cjs.js @@ -2449,7 +2449,7 @@ function genXmlTextBody(slideObj) { Object.entries(opts).forEach(function (_a) { var key = _a[0], val = _a[1]; // NOTE: This loop will pick up unecessary keys (`x`, etc.), but it doesnt hurt anything - if (key !== 'bullet' && !textObj.options[key]) + if (key !== 'bullet' && !textObj.options.hasOwnProperty(key)) textObj.options[key] = val; }); // D: Add formatted textrun