1
1
/** @preserve
2
2
* jsPDF - PDF Document creation from JavaScript
3
- * Version 1.0.119 -git Built on 2014-04-29T03:48
4
- * CommitID 119a246e55
3
+ * Version 1.0.131 -git Built on 2014-05-11T20:51
4
+ * CommitID 9ca4a6ded0
5
5
*
6
6
* Copyright (c) 2010-2014 James Hall, https://github.com/MrRio/jsPDF
7
7
* 2010 Aaron Spike, https://github.com/acspike
@@ -1693,7 +1693,7 @@ var jsPDF = (function(global) {
1693
1693
* pdfdoc.mymethod() // <- !!!!!!
1694
1694
*/
1695
1695
jsPDF . API = { events :[ ] } ;
1696
- jsPDF . version = "1.0.119 -debug 2014-04-29T03:48 :diegocr" ;
1696
+ jsPDF . version = "1.0.131 -debug 2014-05-11T20:51 :diegocr" ;
1697
1697
1698
1698
if ( typeof define === 'function' ) {
1699
1699
define ( function ( ) {
@@ -2831,6 +2831,7 @@ var jsPDF = (function(global) {
2831
2831
* Copyright (c) 2012 Willow Systems Corporation, willow-systems.com
2832
2832
* 2014 Juan Pablo Gaviria, https://github.com/juanpgaviria
2833
2833
* 2014 Diego Casorran, https://github.com/diegocr
2834
+ * 2014 Daniel Husar, https://github.com/danielhusar
2834
2835
*
2835
2836
* Permission is hereby granted, free of charge, to any person obtaining
2836
2837
* a copy of this software and associated documentation files (the
@@ -2854,7 +2855,11 @@ var jsPDF = (function(global) {
2854
2855
*/
2855
2856
2856
2857
( function ( jsPDFAPI ) {
2857
- var DrillForContent , FontNameDB , FontStyleMap , FontWeightMap , GetCSS , PurgeWhiteSpace , Renderer , ResolveFont , ResolveUnitedNumber , UnitedNumberMap , elementHandledElsewhere , images , loadImgs , process , tableToJson ;
2858
+ var clone , DrillForContent , FontNameDB , FontStyleMap , FontWeightMap , GetCSS , PurgeWhiteSpace , Renderer , ResolveFont , ResolveUnitedNumber , UnitedNumberMap , elementHandledElsewhere , images , loadImgs , process , tableToJson ;
2859
+ clone = ( function ( ) {
2860
+ return function ( obj ) { Clone . prototype = obj ; return new Clone ( ) } ;
2861
+ function Clone ( ) { }
2862
+ } ( ) ) ;
2858
2863
PurgeWhiteSpace = function ( array ) {
2859
2864
var fragment , i , l , lTrimmed , r , rTrimmed , trailingSpace ;
2860
2865
i = 0 ;
@@ -2913,6 +2918,16 @@ var jsPDF = (function(global) {
2913
2918
return name ;
2914
2919
} ;
2915
2920
ResolveUnitedNumber = function ( css_line_height_string ) {
2921
+
2922
+ //IE8 issues
2923
+ css_line_height_string = css_line_height_string === "auto" ? "0px" : css_line_height_string ;
2924
+ if ( css_line_height_string . indexOf ( "em" ) > - 1 && ! isNaN ( Number ( css_line_height_string . replace ( "em" , "" ) ) ) ) {
2925
+ css_line_height_string = Number ( css_line_height_string . replace ( "em" , "" ) ) * 18.719 + "px" ;
2926
+ }
2927
+ if ( css_line_height_string . indexOf ( "pt" ) > - 1 && ! isNaN ( Number ( css_line_height_string . replace ( "pt" , "" ) ) ) ) {
2928
+ css_line_height_string = Number ( css_line_height_string . replace ( "pt" , "" ) ) * 1.333 + "px" ;
2929
+ }
2930
+
2916
2931
var normal , undef , value ;
2917
2932
undef = void 0 ;
2918
2933
normal = 16.00 ;
@@ -2968,6 +2983,7 @@ var jsPDF = (function(global) {
2968
2983
tmp = void 0 ;
2969
2984
css [ "font-family" ] = ResolveFont ( computedCSSElement ( "font-family" ) ) || "times" ;
2970
2985
css [ "font-style" ] = FontStyleMap [ computedCSSElement ( "font-style" ) ] || "normal" ;
2986
+ css [ "text-align" ] = TextAlignMap [ computedCSSElement ( "text-align" ) ] || "left" ;
2971
2987
tmp = FontWeightMap [ computedCSSElement ( "font-weight" ) ] || "normal" ;
2972
2988
if ( tmp === "bold" ) {
2973
2989
if ( css [ "font-style" ] === "normal" ) {
@@ -3065,8 +3081,9 @@ var jsPDF = (function(global) {
3065
3081
OBJECT : 1 ,
3066
3082
EMBED : 1
3067
3083
} ;
3084
+ var listCount = 1 ;
3068
3085
DrillForContent = function ( element , renderer , elementHandlers ) {
3069
- var cn , cns , fragmentCSS , i , isBlock , l , px2pt , table2json ;
3086
+ var cn , cns , fragmentCSS , i , isBlock , l , px2pt , table2json , cb ;
3070
3087
cns = element . childNodes ;
3071
3088
cn = void 0 ;
3072
3089
fragmentCSS = GetCSS ( element ) ;
@@ -3103,21 +3120,51 @@ var jsPDF = (function(global) {
3103
3120
margins : renderer . pdf . margins_doc
3104
3121
} ) ;
3105
3122
renderer . y = renderer . pdf . lastCellPos . y + renderer . pdf . lastCellPos . h + 20 ;
3123
+ } else if ( cn . nodeName === "OL" || cn . nodeName === "UL" ) {
3124
+ listCount = 1 ;
3125
+ if ( ! elementHandledElsewhere ( cn , renderer , elementHandlers ) ) {
3126
+ DrillForContent ( cn , renderer , elementHandlers ) ;
3127
+ }
3128
+ renderer . y += 10 ;
3129
+ } else if ( cn . nodeName === "LI" ) {
3130
+ var temp = renderer . x ;
3131
+ renderer . x += cn . parentNode . nodeName === "UL" ? 22 : 10 ;
3132
+ renderer . y += 3 ;
3133
+ if ( ! elementHandledElsewhere ( cn , renderer , elementHandlers ) ) {
3134
+ DrillForContent ( cn , renderer , elementHandlers ) ;
3135
+ }
3136
+ renderer . x = temp ;
3106
3137
} else {
3107
3138
if ( ! elementHandledElsewhere ( cn , renderer , elementHandlers ) ) {
3108
3139
DrillForContent ( cn , renderer , elementHandlers ) ;
3109
3140
}
3110
3141
}
3111
3142
} else if ( cn . nodeType === 3 ) {
3112
- renderer . addText ( cn . nodeValue , fragmentCSS ) ;
3143
+ var value = cn . nodeValue ;
3144
+ if ( cn . nodeValue && cn . parentNode . nodeName === "LI" ) {
3145
+ if ( cn . parentNode . parentNode . nodeName === "OL" ) {
3146
+ value = listCount ++ + '. ' + value ;
3147
+ } else {
3148
+ var fontPx = fragmentCSS [ "font-size" ] * 16 ;
3149
+ var radius = 2 ;
3150
+ if ( fontPx > 20 ) {
3151
+ radius = 3 ;
3152
+ }
3153
+ cb = function ( x , y ) {
3154
+ this . pdf . circle ( x , y , radius , 'FD' ) ;
3155
+ } ;
3156
+ }
3157
+ }
3158
+ renderer . addText ( value , fragmentCSS ) ;
3113
3159
} else if ( typeof cn === "string" ) {
3114
3160
renderer . addText ( cn , fragmentCSS ) ;
3115
3161
}
3116
3162
}
3117
3163
i ++ ;
3118
3164
}
3165
+
3119
3166
if ( isBlock ) {
3120
- return renderer . setBlockBoundary ( ) ;
3167
+ return renderer . setBlockBoundary ( cb ) ;
3121
3168
}
3122
3169
} ;
3123
3170
images = { } ;
@@ -3227,8 +3274,36 @@ var jsPDF = (function(global) {
3227
3274
}
3228
3275
}
3229
3276
}
3277
+
3278
+ //if text alignment was set, set margin/indent of each line
3279
+ if ( style [ 'text-align' ] !== undefined && ( style [ 'text-align' ] === 'center' || style [ 'text-align' ] === 'right' || style [ 'text-align' ] === 'justify' ) ) {
3280
+ for ( var i = 0 ; i < lines . length ; ++ i ) {
3281
+ var length = this . pdf . getStringUnitWidth ( lines [ i ] [ 0 ] [ 0 ] , fragmentSpecificMetrics ) * fragmentSpecificMetrics . fontSize / k ;
3282
+ //if there is more than on line we have to clone the style object as all lines hold a reference on this object
3283
+ if ( i > 0 ) {
3284
+ lines [ i ] [ 0 ] [ 1 ] = clone ( lines [ i ] [ 0 ] [ 1 ] ) ;
3285
+ }
3286
+ var space = ( maxLineLength - length ) ;
3287
+
3288
+ if ( style [ 'text-align' ] === 'right' ) {
3289
+ lines [ i ] [ 0 ] [ 1 ] [ 'margin-left' ] = space ;
3290
+ //if alignment is not right, it has to be center so split the space to the left and the right
3291
+ } else if ( style [ 'text-align' ] === 'center' ) {
3292
+ lines [ i ] [ 0 ] [ 1 ] [ 'margin-left' ] = space / 2 ;
3293
+ //if justify was set, calculate the word spacing and define in by using the css property
3294
+ } else if ( style [ 'text-align' ] === 'justify' ) {
3295
+ var countSpaces = lines [ i ] [ 0 ] [ 0 ] . split ( ' ' ) . length - 1 ;
3296
+ lines [ i ] [ 0 ] [ 1 ] [ 'word-spacing' ] = space / countSpaces ;
3297
+ //ignore the last line in justify mode
3298
+ if ( i === ( lines . length - 1 ) ) {
3299
+ lines [ i ] [ 0 ] [ 1 ] [ 'word-spacing' ] = 0 ;
3300
+ }
3301
+ }
3302
+ }
3303
+ }
3304
+
3230
3305
return lines ;
3231
- } ;
3306
+ } ;
3232
3307
Renderer . prototype . RenderTextFragment = function ( text , style ) {
3233
3308
var defaultFontSize , font ;
3234
3309
if ( this . pdf . internal . pageSize . height - this . pdf . margins_doc . bottom < this . y + this . pdf . internal . getFontSize ( ) ) {
@@ -3239,10 +3314,22 @@ var jsPDF = (function(global) {
3239
3314
}
3240
3315
defaultFontSize = 12 ;
3241
3316
font = this . pdf . internal . getFont ( style [ "font-family" ] , style [ "font-style" ] ) ;
3242
- return this . pdf . internal . write ( "/" + font . id , ( defaultFontSize * style [ "font-size" ] ) . toFixed ( 2 ) , "Tf" , "(" + this . pdf . internal . pdfEscape ( text ) + ") Tj" ) ;
3317
+
3318
+ //set the word spacing for e.g. justify style
3319
+ if ( style [ 'word-spacing' ] !== undefined && style [ 'word-spacing' ] > 0 ) {
3320
+ this . pdf . internal . write ( style [ 'word-spacing' ] . toFixed ( 2 ) , "Tw" ) ;
3321
+ }
3322
+
3323
+ this . pdf . internal . write ( "/" + font . id , ( defaultFontSize * style [ "font-size" ] ) . toFixed ( 2 ) , "Tf" , "(" + this . pdf . internal . pdfEscape ( text ) + ") Tj" ) ;
3324
+
3325
+ //set the word spacing back to neutral => 0
3326
+ if ( style [ 'word-spacing' ] !== undefined ) {
3327
+ this . pdf . internal . write ( 0 , "Tw" ) ;
3328
+ }
3329
+
3243
3330
} ;
3244
- Renderer . prototype . renderParagraph = function ( ) {
3245
- var blockstyle , defaultFontSize , fontToUnitRatio , fragments , i , l , line , lines , maxLineHeight , out , paragraphspacing_after , paragraphspacing_before , priorblockstype , styles ;
3331
+ Renderer . prototype . renderParagraph = function ( cb ) {
3332
+ var blockstyle , defaultFontSize , fontToUnitRatio , fragments , i , l , line , lines , maxLineHeight , out , paragraphspacing_after , paragraphspacing_before , priorblockstype , styles , fontSize ;
3246
3333
fragments = PurgeWhiteSpace ( this . paragraph . text ) ;
3247
3334
styles = this . paragraph . style ;
3248
3335
blockstyle = this . paragraph . blockstyle ;
@@ -3268,18 +3355,32 @@ var jsPDF = (function(global) {
3268
3355
l = void 0 ;
3269
3356
this . y += paragraphspacing_before ;
3270
3357
out ( "q" , "BT" , this . pdf . internal . getCoordinateString ( this . x ) , this . pdf . internal . getVerticalCoordinateString ( this . y ) , "Td" ) ;
3271
- while ( lines . length ) {
3358
+
3359
+ //stores the current indent of cursor position
3360
+ var currentIndent = 0 ;
3361
+
3362
+ while ( lines . length ) {
3272
3363
line = lines . shift ( ) ;
3273
3364
maxLineHeight = 0 ;
3274
3365
i = 0 ;
3275
3366
l = line . length ;
3276
3367
while ( i !== l ) {
3277
3368
if ( line [ i ] [ 0 ] . trim ( ) ) {
3278
3369
maxLineHeight = Math . max ( maxLineHeight , line [ i ] [ 1 ] [ "line-height" ] , line [ i ] [ 1 ] [ "font-size" ] ) ;
3370
+ fontSize = line [ i ] [ 1 ] [ "font-size" ] * 7 ;
3279
3371
}
3280
3372
i ++ ;
3281
3373
}
3282
- out ( 0 , ( - 1 * defaultFontSize * maxLineHeight ) . toFixed ( 2 ) , "Td" ) ;
3374
+ //if we have to move the cursor to adapt the indent
3375
+ var indentMove = 0 ;
3376
+ //if a margin was added (by e.g. a text-alignment), move the cursor
3377
+ if ( line [ 0 ] [ 1 ] [ "margin-left" ] !== undefined && line [ 0 ] [ 1 ] [ "margin-left" ] > 0 ) {
3378
+ wantedIndent = this . pdf . internal . getCoordinateString ( line [ 0 ] [ 1 ] [ "margin-left" ] ) ;
3379
+ indentMove = wantedIndent - currentIndent ;
3380
+ currentIndent = wantedIndent ;
3381
+ }
3382
+ //move the cursor
3383
+ out ( indentMove , ( - 1 * defaultFontSize * maxLineHeight ) . toFixed ( 2 ) , "Td" ) ;
3283
3384
i = 0 ;
3284
3385
l = line . length ;
3285
3386
while ( i !== l ) {
@@ -3290,11 +3391,14 @@ var jsPDF = (function(global) {
3290
3391
}
3291
3392
this . y += maxLineHeight * fontToUnitRatio ;
3292
3393
}
3394
+ if ( cb && typeof cb === "function" ) {
3395
+ cb . call ( this , this . x - 9 , this . y - fontSize / 2 ) ;
3396
+ }
3293
3397
out ( "ET" , "Q" ) ;
3294
3398
return this . y += paragraphspacing_after ;
3295
3399
} ;
3296
- Renderer . prototype . setBlockBoundary = function ( ) {
3297
- return this . renderParagraph ( ) ;
3400
+ Renderer . prototype . setBlockBoundary = function ( cb ) {
3401
+ return this . renderParagraph ( cb ) ;
3298
3402
} ;
3299
3403
Renderer . prototype . setBlockStyle = function ( css ) {
3300
3404
return this . paragraph . blockstyle = css ;
@@ -3332,6 +3436,12 @@ var jsPDF = (function(global) {
3332
3436
italic : "italic" ,
3333
3437
oblique : "italic"
3334
3438
} ;
3439
+ TextAlignMap = {
3440
+ left : "left" ,
3441
+ right : "right" ,
3442
+ center : "center" ,
3443
+ justify : "justify"
3444
+ } ;
3335
3445
UnitedNumberMap = {
3336
3446
normal : 1
3337
3447
/*
@@ -8586,6 +8696,13 @@ var FlateStream = (function() {
8586
8696
} ;
8587
8697
}
8588
8698
8699
+
8700
+ if ( ! Array . isArray ) {
8701
+ Array . isArray = function ( arg ) {
8702
+ return Object . prototype . toString . call ( arg ) === '[object Array]' ;
8703
+ } ;
8704
+ }
8705
+
8589
8706
if ( ! Array . prototype . forEach ) {
8590
8707
Array . prototype . forEach = function ( fun , thisArg ) {
8591
8708
"use strict" ;
0 commit comments