11/** @preserve
22 * 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
55 *
66 * Copyright (c) 2010-2014 James Hall, https://github.com/MrRio/jsPDF
77 * 2010 Aaron Spike, https://github.com/acspike
@@ -1697,7 +1697,7 @@ var jsPDF = (function(global) {
16971697 * pdfdoc.mymethod() // <- !!!!!!
16981698 */
16991699 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" ;
17011701
17021702 if ( typeof define === 'function' && define . amd ) {
17031703 define ( function ( ) {
@@ -2925,6 +2925,8 @@ var jsPDF = (function(global) {
29252925 FontNameDB ,
29262926 FontStyleMap ,
29272927 FontWeightMap ,
2928+ FloatMap ,
2929+ ClearMap ,
29282930 GetCSS ,
29292931 PurgeWhiteSpace ,
29302932 Renderer ,
@@ -2993,6 +2995,8 @@ var jsPDF = (function(global) {
29932995 this . x = x ;
29942996 this . y = y ;
29952997 this . settings = settings ;
2998+ //list of functions which are called after each element-rendering process
2999+ this . watchFunctions = [ ] ;
29963000 this . init ( ) ;
29973001 return this ;
29983002 } ;
@@ -3100,6 +3104,9 @@ var jsPDF = (function(global) {
31003104 css [ "padding-left" ] = ResolveUnitedNumber ( computedCSSElement ( "padding-left" ) ) || 0 ;
31013105 css [ "padding-right" ] = ResolveUnitedNumber ( computedCSSElement ( "padding-right" ) ) || 0 ;
31023106 }
3107+ //float and clearing of floats
3108+ css [ "float" ] = FloatMap [ computedCSSElement ( "cssFloat" ) ] || "none" ;
3109+ css [ "clear" ] = ClearMap [ computedCSSElement ( "clear" ) ] || "none" ;
31033110 return css ;
31043111 } ;
31053112 elementHandledElsewhere = function ( element , renderer , elementHandlers ) {
@@ -3215,6 +3222,9 @@ var jsPDF = (function(global) {
32153222 while ( i < l ) {
32163223 cn = cns [ i ] ;
32173224 if ( typeof cn === "object" ) {
3225+
3226+ //execute all watcher functions to e.g. reset floating
3227+ renderer . executeWatchFunctions ( cn ) ;
32183228
32193229 /*** HEADER rendering **/
32203230 if ( cn . nodeType === 1 && cn . nodeName === 'HEADER' ) {
@@ -3239,14 +3249,74 @@ var jsPDF = (function(global) {
32393249 renderer . pdf . addPage ( ) ;
32403250 renderer . y = renderer . pdf . margins_doc . top ;
32413251 }
3252+
32423253 } else if ( cn . nodeType === 1 && ! SkipNode [ cn . nodeName ] ) {
3254+ /*** IMAGE RENDERING ***/
32433255 if ( cn . nodeName === "IMG" && images [ cn . getAttribute ( "src" ) ] ) {
32443256 if ( ( renderer . pdf . internal . pageSize . height - renderer . pdf . margins_doc . bottom < renderer . y + cn . height ) && ( renderer . y > renderer . pdf . margins_doc . top ) ) {
32453257 renderer . pdf . addPage ( ) ;
32463258 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 ;
32473268 }
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 ***/
32503320 } else if ( cn . nodeName === "TABLE" ) {
32513321 table2json = tableToJson ( cn , renderer ) ;
32523322 renderer . y += 10 ;
@@ -3466,6 +3536,25 @@ var jsPDF = (function(global) {
34663536 y : this . y
34673537 } ;
34683538 } ;
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+
34693558 Renderer . prototype . splitFragmentsIntoLines = function ( fragments , styles ) {
34703559 var currentLineLength ,
34713560 defaultFontSize ,
@@ -3561,14 +3650,22 @@ var jsPDF = (function(global) {
35613650 } ;
35623651 Renderer . prototype . RenderTextFragment = function ( text , style ) {
35633652 var defaultFontSize ,
3564- font ;
3653+ font ,
3654+ maxLineHeight ;
3655+
3656+ maxLineHeight = 0 ;
3657+ defaultFontSize = 12 ;
3658+
35653659 if ( this . pdf . internal . pageSize . height - this . pdf . margins_doc . bottom < this . y + this . pdf . internal . getFontSize ( ) ) {
35663660 this . pdf . internal . write ( "ET" , "Q" ) ;
35673661 this . pdf . addPage ( ) ;
35683662 this . y = this . pdf . margins_doc . top ;
35693663 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" ) ;
35703667 }
3571- defaultFontSize = 12 ;
3668+
35723669 font = this . pdf . internal . getFont ( style [ "font-family" ] , style [ "font-style" ] ) ;
35733670
35743671 //set the word spacing for e.g. justify style
@@ -3627,6 +3724,7 @@ var jsPDF = (function(global) {
36273724
36283725 //stores the current indent of cursor position
36293726 var currentIndent = 0 ;
3727+
36303728 while ( lines . length ) {
36313729 line = lines . shift ( ) ;
36323730 maxLineHeight = 0 ;
@@ -3658,6 +3756,32 @@ var jsPDF = (function(global) {
36583756 i ++ ;
36593757 }
36603758 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+
36613785 }
36623786 if ( cb && typeof cb === "function" ) {
36633787 cb . call ( this , this . x - 9 , this . y - fontSize / 2 ) ;
@@ -3710,6 +3834,15 @@ var jsPDF = (function(global) {
37103834 center : "center" ,
37113835 justify : "justify"
37123836 } ;
3837+ FloatMap = {
3838+ none : 'none' ,
3839+ right : 'right' ,
3840+ left : 'left'
3841+ } ;
3842+ ClearMap = {
3843+ none : 'none' ,
3844+ both : 'both'
3845+ } ;
37133846 UnitedNumberMap = {
37143847 normal : 1
37153848 } ;
@@ -3743,7 +3876,8 @@ var jsPDF = (function(global) {
37433876 settings = { } ;
37443877 if ( ! settings . elementHandlers )
37453878 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 ) ;
37473881 } ;
37483882} ) ( jsPDF . API ) ;
37493883/** ====================================================================
@@ -4361,7 +4495,7 @@ jsPDFAPI.addSVG = function(svgtext, x, y, w, h) {
43614495
43624496 var undef
43634497
4364- if ( x === undef || x === undef ) {
4498+ if ( x === undef || y === undef ) {
43654499 throw new Error ( "addSVG needs values for 'x' and 'y'" ) ;
43664500 }
43674501
@@ -5257,7 +5391,7 @@ jsPDFAPI.putTotalPages = function(pageExpression) {
52575391} ) ( jsPDF . API ) ;
52585392/* Blob.js
52595393 * A Blob implementation.
5260- * 2014-05-27
5394+ * 2014-05-31
52615395 *
52625396 * By Eli Grey, http://eligrey.com
52635397 * By Devin Samarin, https://github.com/eboyjr
@@ -5417,7 +5551,8 @@ jsPDFAPI.putTotalPages = function(pageExpression) {
54175551 return "[object Blob]" ;
54185552 } ;
54195553 FB_proto . close = function ( ) {
5420- this . size = this . data . length = 0 ;
5554+ this . size = 0 ;
5555+ delete this . data ;
54215556 } ;
54225557 return FakeBlobBuilder ;
54235558 } ( view ) ) ;
@@ -5669,7 +5804,7 @@ var saveAs = saveAs
56695804
56705805if ( typeof module !== "undefined" && module !== null ) {
56715806 module . exports = saveAs ;
5672- } else if ( ( typeof define !== "undefined" && define !== null ) && ( define . amd != null ) ) {
5807+ } else if ( ( typeof define !== "undefined" && 0 ) ) {
56735808 define ( [ ] , function ( ) {
56745809 return saveAs ;
56755810 } ) ;
0 commit comments