Skip to content

Commit

Permalink
Fixed Issue #61
Browse files Browse the repository at this point in the history
  • Loading branch information
GitBrent authored and GitBrent committed Apr 1, 2017
1 parent db24408 commit b6b8b94
Show file tree
Hide file tree
Showing 5 changed files with 45 additions and 33 deletions.
13 changes: 13 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,18 @@
# Change Log

## [v1.4.0](https://github.com/gitbrent/pptxgenjs/tree/v1.4.0) (2017-04-??)
[Full Changelog](https://github.com/gitbrent/pptxgenjs/compare/v1.3.0...v1.4.0)

**Fixed Bugs:**
- Auto Paging does not include master template on additional slides [\#61](https://github.com/gitbrent/PptxGenJS/issues/61) ([tb23911](https://github.com/tb23911))

**Implemented Enhancements:**
- Add Slide Number formatting options [\#68](https://github.com/gitbrent/PptxGenJS/issues/68) ([ZouhaierSebri](https://github.com/ZouhaierSebri))





## [v1.3.0](https://github.com/gitbrent/pptxgenjs/tree/v1.3.0) (2017-03-22)
[Full Changelog](https://github.com/gitbrent/pptxgenjs/compare/v1.2.1...v1.3.0)

Expand Down
46 changes: 19 additions & 27 deletions dist/pptxgen.js
Original file line number Diff line number Diff line change
Expand Up @@ -1935,14 +1935,12 @@ var PptxGenJS = function(){
* @returns {Object[]} slideObj - The new Slide object
*/
this.addNewSlide = function addNewSlide(inMaster, inMasterOpts) {
var inMasterOpts = ( inMasterOpts && typeof inMasterOpts === 'object' ? inMasterOpts : {} );
var slideObj = {};
var slideNum = gObjPptx.slides.length;
var slideObjNum = 0;
var pageNum = (slideNum + 1);

var inMasterOpts = inMasterOpts || {};
if ( inMaster && inMasterOpts && inMasterOpts.bkgd ) inMaster.bkgd = inMasterOpts.bkgd; // ISSUE#7: Allow bkgd image/color override on a per-slide basic

// A: Add this SLIDE to PRESENTATION, Add default values as well
gObjPptx.slides[slideNum] = {};
gObjPptx.slides[slideNum].slide = slideObj;
Expand All @@ -1954,7 +1952,7 @@ var PptxGenJS = function(){
gObjPptx.slides[slideNum].hasSlideNumber = false; // DEPRECATED

// ==========================================================================
// SLIDE METHODS:
// PUBLIC METHODS:
// ==========================================================================

slideObj.getPageNumber = function() {
Expand Down Expand Up @@ -2218,38 +2216,29 @@ var PptxGenJS = function(){
// STEP 6: Auto-Paging: (via {options} and used internally)
// (used internally by `addSlidesForTable()` to not engage recursion - we've already paged the table data, just add this one)
if ( opt && opt.autoPage == false ) {
// A: Grab Slide object count
var slideObjNum = gObjPptx.slides[slideNum].data.length;

// B: Add data (NOTE: Use `extend` to avoid mutation)
gObjPptx.slides[slideNum].data[slideObjNum] = {
// Add data (NOTE: Use `extend` to avoid mutation)
gObjPptx.slides[slideNum].data[gObjPptx.slides[slideNum].data.length] = {
type: 'table',
arrTabRows: arrRows,
options: $.extend(true,{},opt)
};
}
else {
// STEP 5: Loop over rows and create one+ tables as needed (ISSUE#21)
// STEP 5: Loop over rows and create 1-N tables as needed (ISSUE#21)
getSlidesForTableRows(arrRows,opt).forEach(function(arrRows,idx){
// A: We've got a the current Slide already, so add first slides' worth of rows to that, BUT, create new ones going forward!
if ( !gObjPptx.slides[slideNum+idx] ) {
gObjPptx.slides[slideNum+idx] = $.extend(true,{},gObjPptx.slides[slideNum]);
gObjPptx.slides[slideNum+idx].data = [];
}
// A: Create new Slide when needed, otherwise, use existing (NOTE: More than 1 table can be on a Slide, so we will go up AND down the Slide chain)
var currSlide = ( !gObjPptx.slides[slideNum+idx] ? addNewSlide(inMaster, inMasterOpts) : gObjPptx.slides[slideNum+idx].slide );

// B: Reset opt.y to option or margin on subsequent Slides (ISSUE#43, ISSUE#47, ISSUE#48)
// B: Reset opt.y (before copying below) to `option`/`margin` after first Slide (ISSUE#43, ISSUE#47, ISSUE#48)
if ( idx > 0 ) opt.y = inch2Emu( opt.newPageStartY || ( (opt.y/EMU) < DEF_SLIDE_MARGIN_IN[0] ? (opt.y/EMU) : DEF_SLIDE_MARGIN_IN[0] ) );

// C: Add data (NOTE: Use `extend` to avoid mutation)
gObjPptx.slides[slideNum+idx].data[gObjPptx.slides[slideNum+idx].data.length] = {
type: 'table',
arrTabRows: arrRows,
options: $.extend(true,{},opt)
};
// C: Add this table to new Slide
opt.autoPage = false;
currSlide.addTable(arrRows, $.extend(true,{},opt));
});
}

// LAST: Return this Slide object
// LAST: Return this Slide
return this;
};

Expand Down Expand Up @@ -2324,11 +2313,14 @@ var PptxGenJS = function(){
// POST-METHODS:
// ==========================================================================

// C: Add 'Master Slide' attr to Slide if a valid master was provided
if ( inMaster && this.masters ) {
// Add Master-Slide objects (if any)
if ( inMaster && typeof inMaster === 'object' ) {
// Add Slide Master objects in order
$.each(inMaster, function(key,val){
// Backgrund color/image
// ISSUE#7: Allow bkgd image/color override on Slide-level
if ( key == "bkgd" && inMasterOpts.bkgd ) val = inMasterOpts.bkgd;

// Background color/image
if ( key == "bkgd" && typeof val === 'object' && (val.src || val.data) ) {
// Allow the use of only the data key (no src reqd)
if (!val.src) val.src = 'preencoded.png';
Expand Down Expand Up @@ -2386,7 +2378,7 @@ var PptxGenJS = function(){
if ( inMaster.slideNumber ) slideObj.slideNumber(inMaster.slideNumber);
}

// LAST: Return this Slide to allow command chaining
// LAST: Return this Slide
return slideObj;
};

Expand Down
2 changes: 1 addition & 1 deletion dist/pptxgen.masters.js
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ var gObjPptxMasters = {
shapes: [
{ type:'text', text:'S.T.A.R. Laboratories - Confidential', x:0, y:6.8, w:'100%', h:0.3, align:'center', valign:'top', color:'7F7F7F', font_size:9, bold:true }
],
slideNumber: { x:0.3, y:'90%' }
slideNumber: { x:0.3, y:'90%', color:'0088CC', fontFace:'Courier' }
},
THANKS_SLIDE: {
title: 'Thanks Slide to be added as final Slide',
Expand Down
2 changes: 2 additions & 0 deletions examples/pptxgenjs-demo.html
Original file line number Diff line number Diff line change
Expand Up @@ -293,6 +293,8 @@
+ "// Set Slide background color and default text colors:\n"
+ "slide.bkgd = 'F1F1F1';\n"
+ "slide.color = 'CC00FF';\n"
+ "slide.slideNumber({ x:0.5, y:'90%' });\n"
+ "slide.slideNumber({ x:0.5, y:'90%', fontSize:32, fontFace:'Courier', color:'CF0101' });\n"
+ "\n"
+ "slide.addText('RECTANGLE', {shape:pptx.shapes.RECTANGLE, x:0.5, y:4.2, w:2.25, h:2.0, fill:'006699', align:'c', font_size:14});\n"
+ "\n"
Expand Down
15 changes: 10 additions & 5 deletions examples/pptxgenjs-demo.js
Original file line number Diff line number Diff line change
Expand Up @@ -70,8 +70,8 @@ function execGenSlidesFuncs(type) {
pptx.setAuthor('Brent Ely');
pptx.setCompany('S.T.A.R. Laboratories');
pptx.setRevision('15');
pptx.setSubject('Test Suite Export');
pptx.setTitle('PptxGenJS Demo Presentation');
pptx.setSubject('PptxGenJS Test Suite Export');
pptx.setTitle('PptxGenJS Test Suite Presentation');

// STEP 2: Run requested test
var arrTypes = ( typeof type === 'string' ? [type] : type );
Expand Down Expand Up @@ -399,8 +399,9 @@ function genSlides_Table(pptx) {
var arrRows = [];
var arrText = [];
for (var idx=0; idx<gArrNamesF.length; idx++) {
arrRows.push( [idx, gArrNamesF[idx], gStrLorumIpsum.substring(idx*100,idx*200)] );
arrText.push( [gStrLorumIpsum.substring(idx*100,idx*200)] );
var strText = ( idx == 0 ? gStrLorumIpsum.substring(0,100) : gStrLorumIpsum.substring(idx*100,idx*200) );
arrRows.push( [idx, gArrNamesF[idx], strText] );
arrText.push( [strText] );
}

var slide = pptx.addNewSlide();
Expand All @@ -412,13 +413,17 @@ function genSlides_Table(pptx) {
slide.addTable( arrRows, { x:3.0, y:0.6, colW:[0.75,1.75, 7], margin:5, border:'CFCFCF' } );

var slide = pptx.addNewSlide();
slide.addText( [{text:'Table Examples: ', options:textTitle},{text:'Test for correct starting Y location upon paging', options:textSubtt}], {x:0.5, y:0.13, w:'90%'} );
slide.addText( [{text:'Table Examples: ', options:textTitle},{text:'Test: Correct starting Y location upon paging', options:textSubtt}], {x:0.5, y:0.13, w:'90%'} );
slide.addTable( arrRows, { x:3.0, y:4.0, colW:[0.75,1.75, 7], margin:5, border:'CFCFCF' } );

var slide = pptx.addNewSlide();
slide.addText( [{text:'Table Examples: ', options:textTitle},{text:'Test: `{ newPageStartY: 0.5 }`', options:textSubtt}], {x:0.5, y:0.13, w:'90%'} );
slide.addTable( arrRows, { x:3.0, y:4.0, newPageStartY:0.5, colW:[0.75,1.75, 7], margin:5, border:'CFCFCF' } );

var slide = pptx.addNewSlide( pptx.masters.MASTER_SLIDE, {bkgd:'CCFFCC'} );
slide.addText( [{text:'Table Examples: ', options:textTitle},{text:'Master Page with Auto-Paging', options:textSubtt}], {x:0.5, y:0.13, w:'90%'} );
slide.addTable( arrRows, { x:1.0, y:0.6, colW:[0.75,1.75, 7], margin:5, border:'CFCFCF' } );

var slide = pptx.addNewSlide();
slide.addText( [{text:'Table Examples: ', options:textTitle},{text:'Auto-Paging Disabled', options:textSubtt}], {x:0.5, y:0.13, w:'90%'} );
slide.addTable( arrRows, { x:1.0, y:0.6, colW:[0.75,1.75, 7], margin:5, border:'CFCFCF', autoPage:false } );
Expand Down

0 comments on commit b6b8b94

Please sign in to comment.