1
1
/** @preserve
2
2
* jsPDF - PDF Document creation from JavaScript
3
- * Version 1.0.150 -git Built on 2014-05-30T00:40
4
- * CommitID dcbc9fcb9b
3
+ * Version 1.0.178 -git Built on 2014-06-27T15:34
4
+ * CommitID 78eac7128d
5
5
*
6
6
* Copyright (c) 2010-2014 James Hall, https://github.com/MrRio/jsPDF
7
7
* 2010 Aaron Spike, https://github.com/acspike
@@ -1697,7 +1697,7 @@ var jsPDF = (function(global) {
1697
1697
* pdfdoc.mymethod() // <- !!!!!!
1698
1698
*/
1699
1699
jsPDF . API = { events :[ ] } ;
1700
- jsPDF . version = "1.0.150 -debug 2014-05-30T00:40 :diegocr" ;
1700
+ jsPDF . version = "1.0.178 -debug 2014-06-27T15:34 :diegocr" ;
1701
1701
1702
1702
if ( typeof define === 'function' && define . amd ) {
1703
1703
define ( function ( ) {
@@ -2925,6 +2925,8 @@ var jsPDF = (function(global) {
2925
2925
FontNameDB ,
2926
2926
FontStyleMap ,
2927
2927
FontWeightMap ,
2928
+ FloatMap ,
2929
+ ClearMap ,
2928
2930
GetCSS ,
2929
2931
PurgeWhiteSpace ,
2930
2932
Renderer ,
@@ -2993,6 +2995,8 @@ var jsPDF = (function(global) {
2993
2995
this . x = x ;
2994
2996
this . y = y ;
2995
2997
this . settings = settings ;
2998
+ //list of functions which are called after each element-rendering process
2999
+ this . watchFunctions = [ ] ;
2996
3000
this . init ( ) ;
2997
3001
return this ;
2998
3002
} ;
@@ -3100,6 +3104,9 @@ var jsPDF = (function(global) {
3100
3104
css [ "padding-left" ] = ResolveUnitedNumber ( computedCSSElement ( "padding-left" ) ) || 0 ;
3101
3105
css [ "padding-right" ] = ResolveUnitedNumber ( computedCSSElement ( "padding-right" ) ) || 0 ;
3102
3106
}
3107
+ //float and clearing of floats
3108
+ css [ "float" ] = FloatMap [ computedCSSElement ( "cssFloat" ) ] || "none" ;
3109
+ css [ "clear" ] = ClearMap [ computedCSSElement ( "clear" ) ] || "none" ;
3103
3110
return css ;
3104
3111
} ;
3105
3112
elementHandledElsewhere = function ( element , renderer , elementHandlers ) {
@@ -3215,6 +3222,9 @@ var jsPDF = (function(global) {
3215
3222
while ( i < l ) {
3216
3223
cn = cns [ i ] ;
3217
3224
if ( typeof cn === "object" ) {
3225
+
3226
+ //execute all watcher functions to e.g. reset floating
3227
+ renderer . executeWatchFunctions ( cn ) ;
3218
3228
3219
3229
/*** HEADER rendering **/
3220
3230
if ( cn . nodeType === 1 && cn . nodeName === 'HEADER' ) {
@@ -3239,14 +3249,74 @@ var jsPDF = (function(global) {
3239
3249
renderer . pdf . addPage ( ) ;
3240
3250
renderer . y = renderer . pdf . margins_doc . top ;
3241
3251
}
3252
+
3242
3253
} else if ( cn . nodeType === 1 && ! SkipNode [ cn . nodeName ] ) {
3254
+ /*** IMAGE RENDERING ***/
3243
3255
if ( cn . nodeName === "IMG" && images [ cn . getAttribute ( "src" ) ] ) {
3244
3256
if ( ( renderer . pdf . internal . pageSize . height - renderer . pdf . margins_doc . bottom < renderer . y + cn . height ) && ( renderer . y > renderer . pdf . margins_doc . top ) ) {
3245
3257
renderer . pdf . addPage ( ) ;
3246
3258
renderer . y = renderer . pdf . margins_doc . top ;
3259
+ //check if we have to set back some values due to e.g. header rendering for new page
3260
+ renderer . executeWatchFunctions ( cn ) ;
3261
+ }
3262
+
3263
+ var imagesCSS = GetCSS ( cn ) ;
3264
+ var imageX = renderer . x ;
3265
+ //if float is set to right, move the image to the right border
3266
+ if ( imagesCSS [ 'float' ] !== undefined && imagesCSS [ 'float' ] === 'right' ) {
3267
+ imageX += renderer . settings . width - cn . width ;
3247
3268
}
3248
- renderer . pdf . addImage ( images [ cn . getAttribute ( "src" ) ] , renderer . x , renderer . y , cn . width , cn . height ) ;
3249
- renderer . y += cn . height ;
3269
+
3270
+ renderer . pdf . addImage ( images [ cn . getAttribute ( "src" ) ] , imageX , renderer . y , cn . width , cn . height ) ;
3271
+ //if the float prop is specified we have to float the text around the image
3272
+ if ( imagesCSS [ 'float' ] !== undefined ) {
3273
+ if ( imagesCSS [ 'float' ] === 'right' || imagesCSS [ 'float' ] === 'left' ) {
3274
+
3275
+ //add functiont to set back coordinates after image rendering
3276
+ renderer . watchFunctions . push ( ( function ( diffX , thresholdY , diffWidth , el ) {
3277
+ //undo drawing box adaptions which were set by floating
3278
+ if ( renderer . y >= thresholdY ) {
3279
+ renderer . x += diffX ;
3280
+ renderer . settings . width += diffWidth ;
3281
+ return true ;
3282
+ } else if ( el && el . nodeType === 1 && ! SkipNode [ el . nodeName ] && renderer . x + el . width > ( renderer . pdf . margins_doc . left + renderer . pdf . margins_doc . width ) ) {
3283
+ renderer . x += diffX ;
3284
+ renderer . y = thresholdY ;
3285
+ renderer . settings . width += diffWidth ;
3286
+ return true ;
3287
+ } else {
3288
+ return false ;
3289
+ }
3290
+ } ) . bind ( this , ( imagesCSS [ 'float' ] === 'left' ) ? - cn . width : 0 , renderer . y + cn . height , cn . width ) ) ;
3291
+
3292
+ //reset floating by clear:both divs
3293
+ //just set cursorY after the floating element
3294
+ renderer . watchFunctions . push ( ( function ( yPositionAfterFloating , pages , el ) {
3295
+ if ( renderer . y < yPositionAfterFloating && pages === renderer . pdf . internal . getNumberOfPages ( ) ) {
3296
+ if ( el . nodeType === 1 && GetCSS ( el ) . clear === 'both' ) {
3297
+ renderer . y = yPositionAfterFloating ;
3298
+ return true ;
3299
+ } else {
3300
+ return false ;
3301
+ }
3302
+ } else {
3303
+ return true ;
3304
+ }
3305
+ } ) . bind ( this , renderer . y + cn . height , renderer . pdf . internal . getNumberOfPages ( ) ) ) ;
3306
+
3307
+ //if floating is set we decrease the available width by the image width
3308
+ renderer . settings . width -= cn . width ;
3309
+ //if left just add the image width to the X coordinate
3310
+ if ( imagesCSS [ 'float' ] === 'left' ) {
3311
+ renderer . x += cn . width ;
3312
+ }
3313
+ }
3314
+ //if no floating is set, move the rendering cursor after the image height
3315
+ } else {
3316
+ renderer . y += cn . height ;
3317
+ }
3318
+
3319
+ /*** TABLE RENDERING ***/
3250
3320
} else if ( cn . nodeName === "TABLE" ) {
3251
3321
table2json = tableToJson ( cn , renderer ) ;
3252
3322
renderer . y += 10 ;
@@ -3466,6 +3536,25 @@ var jsPDF = (function(global) {
3466
3536
y : this . y
3467
3537
} ;
3468
3538
} ;
3539
+
3540
+ //Checks if we have to execute some watcher functions
3541
+ //e.g. to end text floating around an image
3542
+ Renderer . prototype . executeWatchFunctions = function ( el ) {
3543
+ var ret = false ;
3544
+ var narray = [ ] ;
3545
+ if ( this . watchFunctions . length > 0 ) {
3546
+ for ( var i = 0 ; i < this . watchFunctions . length ; ++ i ) {
3547
+ if ( this . watchFunctions [ i ] ( el ) === true ) {
3548
+ ret = true ;
3549
+ } else {
3550
+ narray . push ( this . watchFunctions [ i ] ) ;
3551
+ }
3552
+ }
3553
+ this . watchFunctions = narray ;
3554
+ }
3555
+ return ret ;
3556
+ } ;
3557
+
3469
3558
Renderer . prototype . splitFragmentsIntoLines = function ( fragments , styles ) {
3470
3559
var currentLineLength ,
3471
3560
defaultFontSize ,
@@ -3561,14 +3650,22 @@ var jsPDF = (function(global) {
3561
3650
} ;
3562
3651
Renderer . prototype . RenderTextFragment = function ( text , style ) {
3563
3652
var defaultFontSize ,
3564
- font ;
3653
+ font ,
3654
+ maxLineHeight ;
3655
+
3656
+ maxLineHeight = 0 ;
3657
+ defaultFontSize = 12 ;
3658
+
3565
3659
if ( this . pdf . internal . pageSize . height - this . pdf . margins_doc . bottom < this . y + this . pdf . internal . getFontSize ( ) ) {
3566
3660
this . pdf . internal . write ( "ET" , "Q" ) ;
3567
3661
this . pdf . addPage ( ) ;
3568
3662
this . y = this . pdf . margins_doc . top ;
3569
3663
this . pdf . internal . write ( "q" , "BT" , this . pdf . internal . getCoordinateString ( this . x ) , this . pdf . internal . getVerticalCoordinateString ( this . y ) , "Td" ) ;
3664
+ //move cursor by one line on new page
3665
+ maxLineHeight = Math . max ( maxLineHeight , style [ "line-height" ] , style [ "font-size" ] ) ;
3666
+ this . pdf . internal . write ( 0 , ( - 1 * defaultFontSize * maxLineHeight ) . toFixed ( 2 ) , "Td" ) ;
3570
3667
}
3571
- defaultFontSize = 12 ;
3668
+
3572
3669
font = this . pdf . internal . getFont ( style [ "font-family" ] , style [ "font-style" ] ) ;
3573
3670
3574
3671
//set the word spacing for e.g. justify style
@@ -3627,6 +3724,7 @@ var jsPDF = (function(global) {
3627
3724
3628
3725
//stores the current indent of cursor position
3629
3726
var currentIndent = 0 ;
3727
+
3630
3728
while ( lines . length ) {
3631
3729
line = lines . shift ( ) ;
3632
3730
maxLineHeight = 0 ;
@@ -3658,6 +3756,32 @@ var jsPDF = (function(global) {
3658
3756
i ++ ;
3659
3757
}
3660
3758
this . y += maxLineHeight * fontToUnitRatio ;
3759
+
3760
+ //if some watcher function was executed sucessful, so e.g. margin and widths were changed,
3761
+ //reset line drawing and calculate position and lines again
3762
+ //e.g. to stop text floating around an image
3763
+ if ( this . executeWatchFunctions ( line [ 0 ] [ 1 ] ) && lines . length > 0 ) {
3764
+ var localFragments = [ ] ;
3765
+ var localStyles = [ ] ;
3766
+ //create fragement array of
3767
+ lines . forEach ( function ( localLine ) {
3768
+ var i = 0 ;
3769
+ var l = localLine . length ;
3770
+ while ( i !== l ) {
3771
+ if ( localLine [ i ] [ 0 ] ) {
3772
+ localFragments . push ( localLine [ i ] [ 0 ] + ' ' ) ;
3773
+ localStyles . push ( localLine [ i ] [ 1 ] ) ;
3774
+ }
3775
+ ++ i ;
3776
+ }
3777
+ } ) ;
3778
+ //split lines again due to possible coordinate changes
3779
+ lines = this . splitFragmentsIntoLines ( PurgeWhiteSpace ( localFragments ) , localStyles ) ;
3780
+ //reposition the current cursor
3781
+ out ( "ET" , "Q" ) ;
3782
+ out ( "q" , "BT" , this . pdf . internal . getCoordinateString ( this . x ) , this . pdf . internal . getVerticalCoordinateString ( this . y ) , "Td" ) ;
3783
+ }
3784
+
3661
3785
}
3662
3786
if ( cb && typeof cb === "function" ) {
3663
3787
cb . call ( this , this . x - 9 , this . y - fontSize / 2 ) ;
@@ -3710,6 +3834,15 @@ var jsPDF = (function(global) {
3710
3834
center : "center" ,
3711
3835
justify : "justify"
3712
3836
} ;
3837
+ FloatMap = {
3838
+ none : 'none' ,
3839
+ right : 'right' ,
3840
+ left : 'left'
3841
+ } ;
3842
+ ClearMap = {
3843
+ none : 'none' ,
3844
+ both : 'both'
3845
+ } ;
3713
3846
UnitedNumberMap = {
3714
3847
normal : 1
3715
3848
} ;
@@ -3743,7 +3876,8 @@ var jsPDF = (function(global) {
3743
3876
settings = { } ;
3744
3877
if ( ! settings . elementHandlers )
3745
3878
settings . elementHandlers = { } ;
3746
- return process ( this , HTML , x || 4 , y || 4 , settings , callback ) ;
3879
+
3880
+ return process ( this , HTML , isNaN ( x ) ? 4 : x , isNaN ( y ) ? 4 : y , settings , callback ) ;
3747
3881
} ;
3748
3882
} ) ( jsPDF . API ) ;
3749
3883
/** ====================================================================
@@ -4361,7 +4495,7 @@ jsPDFAPI.addSVG = function(svgtext, x, y, w, h) {
4361
4495
4362
4496
var undef
4363
4497
4364
- if ( x === undef || x === undef ) {
4498
+ if ( x === undef || y === undef ) {
4365
4499
throw new Error ( "addSVG needs values for 'x' and 'y'" ) ;
4366
4500
}
4367
4501
@@ -5257,7 +5391,7 @@ jsPDFAPI.putTotalPages = function(pageExpression) {
5257
5391
} ) ( jsPDF . API ) ;
5258
5392
/* Blob.js
5259
5393
* A Blob implementation.
5260
- * 2014-05-27
5394
+ * 2014-05-31
5261
5395
*
5262
5396
* By Eli Grey, http://eligrey.com
5263
5397
* By Devin Samarin, https://github.com/eboyjr
@@ -5417,7 +5551,8 @@ jsPDFAPI.putTotalPages = function(pageExpression) {
5417
5551
return "[object Blob]" ;
5418
5552
} ;
5419
5553
FB_proto . close = function ( ) {
5420
- this . size = this . data . length = 0 ;
5554
+ this . size = 0 ;
5555
+ delete this . data ;
5421
5556
} ;
5422
5557
return FakeBlobBuilder ;
5423
5558
} ( view ) ) ;
@@ -5669,7 +5804,7 @@ var saveAs = saveAs
5669
5804
5670
5805
if ( typeof module !== "undefined" && module !== null ) {
5671
5806
module . exports = saveAs ;
5672
- } else if ( ( typeof define !== "undefined" && define !== null ) && ( define . amd != null ) ) {
5807
+ } else if ( ( typeof define !== "undefined" && 0 ) ) {
5673
5808
define ( [ ] , function ( ) {
5674
5809
return saveAs ;
5675
5810
} ) ;
0 commit comments