11/** @preserve
22 * jsPDF - PDF Document creation from JavaScript
3- * Version 1.0.116 -git Built on 2014-04-26T23:33
4- * CommitID cbe6766903
3+ * Version 1.0.118 -git Built on 2014-04-28T19:38
4+ * CommitID ce42cbafba
55 *
66 * Copyright (c) 2010-2014 James Hall, https://github.com/MrRio/jsPDF
77 * 2010 Aaron Spike, https://github.com/acspike
@@ -1693,7 +1693,7 @@ var jsPDF = (function(global) {
16931693 * pdfdoc.mymethod() // <- !!!!!!
16941694 */
16951695 jsPDF . API = { events :[ ] } ;
1696- jsPDF . version = "1.0.116 -debug 2014-04-26T23:33 :diegocr" ;
1696+ jsPDF . version = "1.0.118 -debug 2014-04-28T19:38 :diegocr" ;
16971697
16981698 if ( typeof define === 'function' ) {
16991699 define ( function ( ) {
@@ -4112,11 +4112,11 @@ jsPDFAPI.addSVG = function(svgtext, x, y, w, h) {
41124112}
41134113
41144114} ) ( jsPDF . API ) ;
4115- /** @preserve
4116- jsPDF split_text_to_size plugin
4117- Copyright (c) 2012 Willow Systems Corporation, willow-systems.com
4118- MIT license.
4119- */
4115+ /** @preserve
4116+ * jsPDF split_text_to_size plugin - MIT license.
4117+ * Copyright (c) 2012 Willow Systems Corporation, willow-systems.com
4118+ * 2014 Diego Casorran, https://github.com/diegocr
4119+ */
41204120/**
41214121 * Permission is hereby granted, free of charge, to any person obtaining
41224122 * a copy of this software and associated documentation files (the
@@ -4125,10 +4125,10 @@ MIT license.
41254125 * distribute, sublicense, and/or sell copies of the Software, and to
41264126 * permit persons to whom the Software is furnished to do so, subject to
41274127 * the following conditions:
4128- *
4128+ *
41294129 * The above copyright notice and this permission notice shall be
41304130 * included in all copies or substantial portions of the Software.
4131- *
4131+ *
41324132 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
41334133 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
41344134 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
@@ -4162,20 +4162,19 @@ var getCharWidthsArray = API.getCharWidthsArray = function(text, options){
41624162 , widthsFractionOf = widths . fof ? widths . fof : 1
41634163 , kerning = options . kerning ? options . kerning : this . internal . getFont ( ) . metadata . Unicode . kerning
41644164 , kerningFractionOf = kerning . fof ? kerning . fof : 1
4165-
4165+
41664166 // console.log("widths, kergnings", widths, kerning)
41674167
41684168 var i , l
41694169 , char_code
4170- , char_width
41714170 , prior_char_code = 0 // for kerning
41724171 , default_char_width = widths [ 0 ] || widthsFractionOf
41734172 , output = [ ]
41744173
41754174 for ( i = 0 , l = text . length ; i < l ; i ++ ) {
41764175 char_code = text . charCodeAt ( i )
41774176 output . push (
4178- ( widths [ char_code ] || default_char_width ) / widthsFractionOf +
4177+ ( widths [ char_code ] || default_char_width ) / widthsFractionOf +
41794178 ( kerning [ char_code ] && kerning [ char_code ] [ prior_char_code ] || 0 ) / kerningFractionOf
41804179 )
41814180 prior_char_code = char_code
@@ -4210,7 +4209,7 @@ var getStringUnitWidth = API.getStringUnitWidth = function(text, options) {
42104209 return getArraySum ( getCharWidthsArray . call ( this , text , options ) )
42114210}
42124211
4213- /**
4212+ /**
42144213returns array of lines
42154214*/
42164215var splitLongWord = function ( word , widths_array , firstLineMaxLen , maxLen ) {
@@ -4256,25 +4255,50 @@ var splitParagraphIntoLines = function(text, maxlen, options){
42564255 options = { }
42574256 }
42584257
4259- var spaceCharWidth = getCharWidthsArray ( ' ' , options ) [ 0 ]
4260-
4261- var words = text . split ( ' ' )
4262-
42634258 var line = [ ]
42644259 , lines = [ line ]
42654260 , line_length = options . textIndent || 0
42664261 , separator_length = 0
42674262 , current_word_length = 0
42684263 , word
42694264 , widths_array
4265+ , words = text . split ( ' ' )
4266+ , spaceCharWidth = getCharWidthsArray ( ' ' , options ) [ 0 ]
4267+ , i , l , tmp , lineIndent
4268+
4269+ if ( options . lineIndent === - 1 ) {
4270+ lineIndent = words [ 0 ] . length + 2 ;
4271+ } else {
4272+ lineIndent = options . lineIndent || 0 ;
4273+ }
4274+ if ( lineIndent ) {
4275+ var pad = Array ( lineIndent ) . join ( " " ) , wrds = [ ] ;
4276+ words . map ( function ( wrd ) {
4277+ wrd = wrd . split ( / \s * \n / ) ;
4278+ if ( wrd . length > 1 ) {
4279+ wrds = wrds . concat ( wrd . map ( function ( wrd , idx ) {
4280+ return ( idx && wrd . length ? "\n" :"" ) + wrd ;
4281+ } ) ) ;
4282+ } else {
4283+ wrds . push ( wrd [ 0 ] ) ;
4284+ }
4285+ } ) ;
4286+ words = wrds ;
4287+ lineIndent = getStringUnitWidth ( pad , options ) ;
4288+ }
42704289
4271- var i , l , tmp
42724290 for ( i = 0 , l = words . length ; i < l ; i ++ ) {
4291+ var force = 0 ;
4292+
42734293 word = words [ i ]
4294+ if ( lineIndent && word [ 0 ] == "\n" ) {
4295+ word = word . substr ( 1 ) ;
4296+ force = 1 ;
4297+ }
42744298 widths_array = getCharWidthsArray ( word , options )
42754299 current_word_length = getArraySum ( widths_array )
42764300
4277- if ( line_length + separator_length + current_word_length > maxlen ) {
4301+ if ( line_length + separator_length + current_word_length > maxlen || force ) {
42784302 if ( current_word_length > maxlen ) {
42794303 // this happens when you have space-less long URLs for example.
42804304 // we just chop these to size. We do NOT insert hiphens
@@ -4295,8 +4319,7 @@ var splitParagraphIntoLines = function(text, maxlen, options){
42954319
42964320 // now we attach new line to lines
42974321 lines . push ( line )
4298-
4299- line_length = current_word_length
4322+ line_length = current_word_length + lineIndent
43004323 separator_length = spaceCharWidth
43014324
43024325 } else {
@@ -4307,12 +4330,15 @@ var splitParagraphIntoLines = function(text, maxlen, options){
43074330 }
43084331 }
43094332
4310- var output = [ ]
4311- for ( i = 0 , l = lines . length ; i < l ; i ++ ) {
4312- output . push ( lines [ i ] . join ( ' ' ) )
4333+ if ( lineIndent ) {
4334+ var postProcess = function ( ln , idx ) {
4335+ return ( idx ? pad : '' ) + ln . join ( " " ) ;
4336+ } ;
4337+ } else {
4338+ var postProcess = function ( ln ) { return ln . join ( " " ) } ;
43134339 }
4314- return output
43154340
4341+ return lines . map ( postProcess ) ;
43164342}
43174343
43184344/**
@@ -4360,7 +4386,7 @@ API.splitTextToSize = function(text, maxlen, options) {
43604386 return {
43614387 widths : options . widths
43624388 , kerning : options . kerning
4363- }
4389+ }
43644390 }
43654391
43664392 // then use default values
@@ -4371,11 +4397,11 @@ API.splitTextToSize = function(text, maxlen, options) {
43714397 } ) . call ( this , options )
43724398
43734399 // first we split on end-of-line chars
4374- var paragraphs
4375- if ( text . match ( / [ \n \r ] / ) ) {
4376- paragraphs = text . split ( / \r \n | \r | \n / g )
4400+ var paragraphs
4401+ if ( Array . isArray ( text ) ) {
4402+ paragraphs = text ;
43774403 } else {
4378- paragraphs = [ text ]
4404+ paragraphs = text . split ( / \r ? \n / ) ;
43794405 }
43804406
43814407 // now we convert size (max length of line) into "font size units"
@@ -4386,13 +4412,14 @@ API.splitTextToSize = function(text, maxlen, options) {
43864412 // this may change in the future?
43874413 // until then, proportional_maxlen is likely to be in 'points'
43884414
4389- // If first line is to be indented (shorter or longer) than maxLen
4415+ // If first line is to be indented (shorter or longer) than maxLen
43904416 // we indicate that by using CSS-style "text-indent" option.
43914417 // here it's in font units too (which is likely 'points')
43924418 // it can be negative (which makes the first line longer than maxLen)
4393- newOptions . textIndent = options . textIndent ?
4394- options . textIndent * 1.0 * this . internal . scaleFactor / fsize :
4419+ newOptions . textIndent = options . textIndent ?
4420+ options . textIndent * 1.0 * this . internal . scaleFactor / fsize :
43954421 0
4422+ newOptions . lineIndent = options . lineIndent ;
43964423
43974424 var i , l
43984425 , output = [ ]
@@ -4406,7 +4433,7 @@ API.splitTextToSize = function(text, maxlen, options) {
44064433 )
44074434 }
44084435
4409- return output
4436+ return output
44104437}
44114438
44124439} ) ( jsPDF . API ) ;
@@ -7563,7 +7590,7 @@ var Deflater = (function(obj) {
75637590 APNG_BLEND_OP_OVER = 1 ;
75647591
75657592 function PNG ( data ) {
7566- var chunkSize , colors , palLen , delayDen , delayNum , frame , i , index , key , section , short , text , _i , _j , _ref ;
7593+ var chunkSize , colors , palLen , delayDen , delayNum , frame , i , index , key , section , palShort , text , _i , _j , _ref ;
75677594 this . data = data ;
75687595 this . pos = 8 ;
75697596 this . palette = [ ] ;
@@ -7642,10 +7669,10 @@ var Deflater = (function(obj) {
76427669 /*
76437670 * According to the PNG spec trns should be increased to the same size as palette if shorter
76447671 */
7645- //short = 255 - this.transparency.indexed.length;
7646- short = palLen - this . transparency . indexed . length ;
7647- if ( short > 0 ) {
7648- for ( i = _j = 0 ; 0 <= short ? _j < short : _j > short ; i = 0 <= short ? ++ _j : -- _j ) {
7672+ //palShort = 255 - this.transparency.indexed.length;
7673+ palShort = palLen - this . transparency . indexed . length ;
7674+ if ( palShort > 0 ) {
7675+ for ( i = _j = 0 ; 0 <= palShort ? _j < palShort : _j > palShort ; i = 0 <= palShort ? ++ _j : -- _j ) {
76497676 this . transparency . indexed . push ( 255 ) ;
76507677 }
76517678 }
@@ -7728,7 +7755,7 @@ var Deflater = (function(obj) {
77287755 } ;
77297756
77307757 PNG . prototype . decodePixels = function ( data ) {
7731- var byte , c , col , i , left , length , p , pa , paeth , pb , pc , pixelBytes , pixels , pos , row , scanlineLength , upper , upperLeft , _i , _j , _k , _l , _m ;
7758+ var abyte , c , col , i , left , length , p , pa , paeth , pb , pc , pixelBytes , pixels , pos , row , scanlineLength , upper , upperLeft , _i , _j , _k , _l , _m ;
77327759 if ( data == null ) {
77337760 data = this . imgData ;
77347761 }
@@ -7753,31 +7780,31 @@ var Deflater = (function(obj) {
77537780 break ;
77547781 case 1 :
77557782 for ( i = _j = 0 ; _j < scanlineLength ; i = _j += 1 ) {
7756- byte = data [ pos ++ ] ;
7783+ abyte = data [ pos ++ ] ;
77577784 left = i < pixelBytes ? 0 : pixels [ c - pixelBytes ] ;
7758- pixels [ c ++ ] = ( byte + left ) % 256 ;
7785+ pixels [ c ++ ] = ( abyte + left ) % 256 ;
77597786 }
77607787 break ;
77617788 case 2 :
77627789 for ( i = _k = 0 ; _k < scanlineLength ; i = _k += 1 ) {
7763- byte = data [ pos ++ ] ;
7790+ abyte = data [ pos ++ ] ;
77647791 col = ( i - ( i % pixelBytes ) ) / pixelBytes ;
77657792 upper = row && pixels [ ( row - 1 ) * scanlineLength + col * pixelBytes + ( i % pixelBytes ) ] ;
7766- pixels [ c ++ ] = ( upper + byte ) % 256 ;
7793+ pixels [ c ++ ] = ( upper + abyte ) % 256 ;
77677794 }
77687795 break ;
77697796 case 3 :
77707797 for ( i = _l = 0 ; _l < scanlineLength ; i = _l += 1 ) {
7771- byte = data [ pos ++ ] ;
7798+ abyte = data [ pos ++ ] ;
77727799 col = ( i - ( i % pixelBytes ) ) / pixelBytes ;
77737800 left = i < pixelBytes ? 0 : pixels [ c - pixelBytes ] ;
77747801 upper = row && pixels [ ( row - 1 ) * scanlineLength + col * pixelBytes + ( i % pixelBytes ) ] ;
7775- pixels [ c ++ ] = ( byte + Math . floor ( ( left + upper ) / 2 ) ) % 256 ;
7802+ pixels [ c ++ ] = ( abyte + Math . floor ( ( left + upper ) / 2 ) ) % 256 ;
77767803 }
77777804 break ;
77787805 case 4 :
77797806 for ( i = _m = 0 ; _m < scanlineLength ; i = _m += 1 ) {
7780- byte = data [ pos ++ ] ;
7807+ abyte = data [ pos ++ ] ;
77817808 col = ( i - ( i % pixelBytes ) ) / pixelBytes ;
77827809 left = i < pixelBytes ? 0 : pixels [ c - pixelBytes ] ;
77837810 if ( row === 0 ) {
@@ -7797,7 +7824,7 @@ var Deflater = (function(obj) {
77977824 } else {
77987825 paeth = upperLeft ;
77997826 }
7800- pixels [ c ++ ] = ( byte + paeth ) % 256 ;
7827+ pixels [ c ++ ] = ( abyte + paeth ) % 256 ;
78017828 }
78027829 break ;
78037830 default :
0 commit comments