11; ( function ( ) {
2- /** @preserve jsPDF 0.9.0rc2 ( 2013-08-06T13:32 commit ID e3938214f1ad4a4ab0009b7230531d255f20bdc5 )
2+ /** @preserve jsPDF 0.9.0rc2 ( 2013-08-06T14:54 commit ID 7ca766ff8f49a839d86faccebf95a1267bb8afcc )
33Copyright (c) 2010-2012 James Hall, james@snapshotmedia.co.uk, https://github.com/MrRio/jsPDF
44Copyright (c) 2012 Willow Systems Corporation, willow-systems.com
55MIT license.
@@ -3634,6 +3634,7 @@ API.events.push([
36343634/** ====================================================================
36353635 * jsPDF Cell plugin
36363636 * Copyright (c) 2013 Youssef Beddad, youssef.beddad@gmail.com
3637+ * 2013 Eduardo Menezes de Morais, eduardo.morais@usp.br
36373638 *
36383639 * Permission is hereby granted, free of charge, to any person obtaining
36393640 * a copy of this software and associated documentation files (the
@@ -3661,25 +3662,18 @@ API.events.push([
36613662 /*jslint browser:true */
36623663 /*global document: false, jsPDF */
36633664
3664- var lnP = 0 ,
3665- fontName ,
3665+ var fontName ,
36663666 fontSize ,
36673667 fontStyle ,
36683668 padding = 3 ,
3669+ margin = 10 ,
36693670 lastCellPos = { x : undefined , y : undefined , w : undefined , h : undefined , ln : undefined } ,
36703671 pages = 1 ,
3671- newPage = false ,
36723672 setLastCellPosition = function ( x , y , w , h , ln ) {
3673- lastCellPos = { x : x , y : y , w : w , h : h , ln : ln } ;
3673+ lastCellPos = { 'x' : x , 'y' : y , 'w' : w , 'h' : h , 'ln' : ln } ;
36743674 } ,
36753675 getLastCellPosition = function ( ) {
36763676 return lastCellPos ;
3677- } ,
3678- setLnP = function ( x ) {
3679- lnP = x ;
3680- } ,
3681- getLnP = function ( x ) {
3682- return lnP ;
36833677 } ;
36843678
36853679 jsPDFAPI . getTextDimensions = function ( txt ) {
@@ -3711,69 +3705,46 @@ API.events.push([
37113705 jsPDFAPI . cellAddPage = function ( ) {
37123706 this . addPage ( ) ;
37133707 setLastCellPosition ( undefined , undefined , undefined , undefined , undefined ) ;
3714- newPage = true ;
37153708 pages += 1 ;
3716- setLnP ( 1 ) ;
37173709 } ;
37183710
37193711 jsPDFAPI . cellInitialize = function ( ) {
37203712 lastCellPos = { x : undefined , y : undefined , w : undefined , h : undefined , ln : undefined } ;
37213713 pages = 1 ;
3722- newPage = false ;
3723- setLnP ( 0 ) ;
37243714 } ;
37253715
37263716 jsPDFAPI . cell = function ( x , y , w , h , txt , ln ) {
3727- this . lnMod = this . lnMod === undefined ? 0 : this . lnMod ;
3728- if ( this . printingHeaderRow !== true && this . lnMod !== 0 ) {
3729- ln = ln + this . lnMod ;
3730- }
3731-
3732- if ( ( ( ( ln * h ) + y + ( h * 2 ) ) / pages ) >= this . internal . pageSize . height && pages === 1 && ! newPage ) {
3733- this . cellAddPage ( ) ;
3717+ var curCell = getLastCellPosition ( ) ;
3718+
3719+ // If this is not the first cell, we must change its position
3720+ if ( curCell . ln !== undefined ) {
3721+
3722+ if ( curCell . ln === ln ) {
3723+ //Same line
3724+ x = curCell . x + curCell . w ;
3725+ y = curCell . y ;
3726+ } else {
3727+ //New line
3728+ if ( ( curCell . y + curCell . h + h + margin ) >= this . internal . pageSize . height ) {
3729+ this . cellAddPage ( ) ;
37343730
3735- if ( this . printHeaders && this . tableHeaderRow ) {
3736- this . printHeaderRow ( ln ) ;
3737- this . lnMod += 1 ;
3738- ln += 1 ;
3739- }
3740- } else if ( newPage && getLastCellPosition ( ) . ln !== ln && getLnP ( ) === getMaxLn ( ) ) {
3741- this . cellAddPage ( ) ;
3731+ if ( this . printHeaders && this . tableHeaderRow ) {
3732+ this . printHeaderRow ( ln ) ;
3733+ }
3734+ }
3735+ //We ignore the passed y: the lines may have diferent heights
3736+ y = ( getLastCellPosition ( ) . y + getLastCellPosition ( ) . h ) ;
37423737
3743- if ( this . printHeaders && this . tableHeaderRow ) {
3744- this . printHeaderRow ( ln ) ;
3745- this . lnMod += 1 ;
3746- ln += 1 ;
37473738 }
37483739 }
3749-
3750- var curCell = getLastCellPosition ( ) ,
3751- isNewLn = 1 ;
3752- if ( curCell . x !== undefined && curCell . ln === ln ) {
3753- x = curCell . x + curCell . w ;
3754- }
3755- if ( curCell . ln !== undefined && curCell . ln === ln ) {
3756- ln = curCell . ln ;
3757- isNewLn = 0 ;
3758- }
3759- if ( curCell . y !== undefined ) {
3760- //We ignore the passed y: the lines may have diferent heights
3761- if ( isNewLn === 1 )
3762- y = ( curCell . y + curCell . h ) ;
3763- else
3764- y = curCell . y ;
3765- }
37663740
3767- if ( newPage ) {
3768- y = h * ( getLnP ( ) + isNewLn ) ;
3769- }
3741+
37703742 if ( this . printingHeaderRow ) {
37713743 this . rect ( x , y , w , h , 'F' ) ;
37723744 } else {
37733745 this . rect ( x , y , w , h ) ;
37743746 }
37753747 this . text ( txt , x + padding , y + this . internal . getLineHeight ( ) ) ;
3776- setLnP ( getLnP ( ) + isNewLn ) ;
37773748 setLastCellPosition ( x , y , w , h , ln ) ;
37783749 return this ;
37793750 } ;
@@ -3937,7 +3908,7 @@ API.events.push([
39373908 // Construct the header row
39383909 for ( i = 0 , ln = headerNames . length ; i < ln ; i += 1 ) {
39393910 header = headerNames [ i ] ;
3940- tableHeaderConfigs . push ( [ 10 , 10 , columnWidths [ header ] , lineHeight , String ( headerPrompts . length ? headerPrompts [ i ] : header ) ] ) ;
3911+ tableHeaderConfigs . push ( [ margin , margin , columnWidths [ header ] , lineHeight , String ( headerPrompts . length ? headerPrompts [ i ] : header ) ] ) ;
39413912 }
39423913
39433914 // Store the table header config
@@ -3955,18 +3926,18 @@ API.events.push([
39553926
39563927 for ( j = 0 , jln = headerNames . length ; j < jln ; j += 1 ) {
39573928 header = headerNames [ j ] ;
3958- this . cell ( 10 , 10 , columnWidths [ header ] , lineHeight , model [ header ] , i + 2 ) ;
3929+ this . cell ( margin , margin , columnWidths [ header ] , lineHeight , model [ header ] , i + 2 ) ;
39593930 }
39603931 }
39613932
39623933 return this ;
39633934 } ;
39643935
39653936 /**
3966- * Store the config for outputting a table header
3967- * @param {Object [] } config
3968- * An array of cell configs that would define a header row: Each config matches the config used by jsPDFAPI.cell
3969- * except the ln parameter is excluded
3937+ * Calculate the height for containing the highest column
3938+ * @param {String [] } headerNames is the header, used as keys to the data
3939+ * @param { Integer[] } columnWidths is size of each column
3940+ * @param { Object[] } model is the line of data we want to calculate the height of
39703941 */
39713942 jsPDFAPI . calculateLineHeight = function ( headerNames , columnWidths , model ) {
39723943 var header , lineHeight = 0 ;
0 commit comments