1
1
/** @preserve
2
2
* 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
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.116 -debug 2014-04-26T23:33 :diegocr" ;
1696
+ jsPDF . version = "1.0.118 -debug 2014-04-28T19:38 :diegocr" ;
1697
1697
1698
1698
if ( typeof define === 'function' ) {
1699
1699
define ( function ( ) {
@@ -4112,11 +4112,11 @@ jsPDFAPI.addSVG = function(svgtext, x, y, w, h) {
4112
4112
}
4113
4113
4114
4114
} ) ( 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
+ */
4120
4120
/**
4121
4121
* Permission is hereby granted, free of charge, to any person obtaining
4122
4122
* a copy of this software and associated documentation files (the
@@ -4125,10 +4125,10 @@ MIT license.
4125
4125
* distribute, sublicense, and/or sell copies of the Software, and to
4126
4126
* permit persons to whom the Software is furnished to do so, subject to
4127
4127
* the following conditions:
4128
- *
4128
+ *
4129
4129
* The above copyright notice and this permission notice shall be
4130
4130
* included in all copies or substantial portions of the Software.
4131
- *
4131
+ *
4132
4132
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
4133
4133
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
4134
4134
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
@@ -4162,20 +4162,19 @@ var getCharWidthsArray = API.getCharWidthsArray = function(text, options){
4162
4162
, widthsFractionOf = widths . fof ? widths . fof : 1
4163
4163
, kerning = options . kerning ? options . kerning : this . internal . getFont ( ) . metadata . Unicode . kerning
4164
4164
, kerningFractionOf = kerning . fof ? kerning . fof : 1
4165
-
4165
+
4166
4166
// console.log("widths, kergnings", widths, kerning)
4167
4167
4168
4168
var i , l
4169
4169
, char_code
4170
- , char_width
4171
4170
, prior_char_code = 0 // for kerning
4172
4171
, default_char_width = widths [ 0 ] || widthsFractionOf
4173
4172
, output = [ ]
4174
4173
4175
4174
for ( i = 0 , l = text . length ; i < l ; i ++ ) {
4176
4175
char_code = text . charCodeAt ( i )
4177
4176
output . push (
4178
- ( widths [ char_code ] || default_char_width ) / widthsFractionOf +
4177
+ ( widths [ char_code ] || default_char_width ) / widthsFractionOf +
4179
4178
( kerning [ char_code ] && kerning [ char_code ] [ prior_char_code ] || 0 ) / kerningFractionOf
4180
4179
)
4181
4180
prior_char_code = char_code
@@ -4210,7 +4209,7 @@ var getStringUnitWidth = API.getStringUnitWidth = function(text, options) {
4210
4209
return getArraySum ( getCharWidthsArray . call ( this , text , options ) )
4211
4210
}
4212
4211
4213
- /**
4212
+ /**
4214
4213
returns array of lines
4215
4214
*/
4216
4215
var splitLongWord = function ( word , widths_array , firstLineMaxLen , maxLen ) {
@@ -4256,25 +4255,50 @@ var splitParagraphIntoLines = function(text, maxlen, options){
4256
4255
options = { }
4257
4256
}
4258
4257
4259
- var spaceCharWidth = getCharWidthsArray ( ' ' , options ) [ 0 ]
4260
-
4261
- var words = text . split ( ' ' )
4262
-
4263
4258
var line = [ ]
4264
4259
, lines = [ line ]
4265
4260
, line_length = options . textIndent || 0
4266
4261
, separator_length = 0
4267
4262
, current_word_length = 0
4268
4263
, word
4269
4264
, 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
+ }
4270
4289
4271
- var i , l , tmp
4272
4290
for ( i = 0 , l = words . length ; i < l ; i ++ ) {
4291
+ var force = 0 ;
4292
+
4273
4293
word = words [ i ]
4294
+ if ( lineIndent && word [ 0 ] == "\n" ) {
4295
+ word = word . substr ( 1 ) ;
4296
+ force = 1 ;
4297
+ }
4274
4298
widths_array = getCharWidthsArray ( word , options )
4275
4299
current_word_length = getArraySum ( widths_array )
4276
4300
4277
- if ( line_length + separator_length + current_word_length > maxlen ) {
4301
+ if ( line_length + separator_length + current_word_length > maxlen || force ) {
4278
4302
if ( current_word_length > maxlen ) {
4279
4303
// this happens when you have space-less long URLs for example.
4280
4304
// we just chop these to size. We do NOT insert hiphens
@@ -4295,8 +4319,7 @@ var splitParagraphIntoLines = function(text, maxlen, options){
4295
4319
4296
4320
// now we attach new line to lines
4297
4321
lines . push ( line )
4298
-
4299
- line_length = current_word_length
4322
+ line_length = current_word_length + lineIndent
4300
4323
separator_length = spaceCharWidth
4301
4324
4302
4325
} else {
@@ -4307,12 +4330,15 @@ var splitParagraphIntoLines = function(text, maxlen, options){
4307
4330
}
4308
4331
}
4309
4332
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 ( " " ) } ;
4313
4339
}
4314
- return output
4315
4340
4341
+ return lines . map ( postProcess ) ;
4316
4342
}
4317
4343
4318
4344
/**
@@ -4360,7 +4386,7 @@ API.splitTextToSize = function(text, maxlen, options) {
4360
4386
return {
4361
4387
widths : options . widths
4362
4388
, kerning : options . kerning
4363
- }
4389
+ }
4364
4390
}
4365
4391
4366
4392
// then use default values
@@ -4371,11 +4397,11 @@ API.splitTextToSize = function(text, maxlen, options) {
4371
4397
} ) . call ( this , options )
4372
4398
4373
4399
// 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 ;
4377
4403
} else {
4378
- paragraphs = [ text ]
4404
+ paragraphs = text . split ( / \r ? \n / ) ;
4379
4405
}
4380
4406
4381
4407
// now we convert size (max length of line) into "font size units"
@@ -4386,13 +4412,14 @@ API.splitTextToSize = function(text, maxlen, options) {
4386
4412
// this may change in the future?
4387
4413
// until then, proportional_maxlen is likely to be in 'points'
4388
4414
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
4390
4416
// we indicate that by using CSS-style "text-indent" option.
4391
4417
// here it's in font units too (which is likely 'points')
4392
4418
// 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 :
4395
4421
0
4422
+ newOptions . lineIndent = options . lineIndent ;
4396
4423
4397
4424
var i , l
4398
4425
, output = [ ]
@@ -4406,7 +4433,7 @@ API.splitTextToSize = function(text, maxlen, options) {
4406
4433
)
4407
4434
}
4408
4435
4409
- return output
4436
+ return output
4410
4437
}
4411
4438
4412
4439
} ) ( jsPDF . API ) ;
@@ -7563,7 +7590,7 @@ var Deflater = (function(obj) {
7563
7590
APNG_BLEND_OP_OVER = 1 ;
7564
7591
7565
7592
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 ;
7567
7594
this . data = data ;
7568
7595
this . pos = 8 ;
7569
7596
this . palette = [ ] ;
@@ -7642,10 +7669,10 @@ var Deflater = (function(obj) {
7642
7669
/*
7643
7670
* According to the PNG spec trns should be increased to the same size as palette if shorter
7644
7671
*/
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 ) {
7649
7676
this . transparency . indexed . push ( 255 ) ;
7650
7677
}
7651
7678
}
@@ -7728,7 +7755,7 @@ var Deflater = (function(obj) {
7728
7755
} ;
7729
7756
7730
7757
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 ;
7732
7759
if ( data == null ) {
7733
7760
data = this . imgData ;
7734
7761
}
@@ -7753,31 +7780,31 @@ var Deflater = (function(obj) {
7753
7780
break ;
7754
7781
case 1 :
7755
7782
for ( i = _j = 0 ; _j < scanlineLength ; i = _j += 1 ) {
7756
- byte = data [ pos ++ ] ;
7783
+ abyte = data [ pos ++ ] ;
7757
7784
left = i < pixelBytes ? 0 : pixels [ c - pixelBytes ] ;
7758
- pixels [ c ++ ] = ( byte + left ) % 256 ;
7785
+ pixels [ c ++ ] = ( abyte + left ) % 256 ;
7759
7786
}
7760
7787
break ;
7761
7788
case 2 :
7762
7789
for ( i = _k = 0 ; _k < scanlineLength ; i = _k += 1 ) {
7763
- byte = data [ pos ++ ] ;
7790
+ abyte = data [ pos ++ ] ;
7764
7791
col = ( i - ( i % pixelBytes ) ) / pixelBytes ;
7765
7792
upper = row && pixels [ ( row - 1 ) * scanlineLength + col * pixelBytes + ( i % pixelBytes ) ] ;
7766
- pixels [ c ++ ] = ( upper + byte ) % 256 ;
7793
+ pixels [ c ++ ] = ( upper + abyte ) % 256 ;
7767
7794
}
7768
7795
break ;
7769
7796
case 3 :
7770
7797
for ( i = _l = 0 ; _l < scanlineLength ; i = _l += 1 ) {
7771
- byte = data [ pos ++ ] ;
7798
+ abyte = data [ pos ++ ] ;
7772
7799
col = ( i - ( i % pixelBytes ) ) / pixelBytes ;
7773
7800
left = i < pixelBytes ? 0 : pixels [ c - pixelBytes ] ;
7774
7801
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 ;
7776
7803
}
7777
7804
break ;
7778
7805
case 4 :
7779
7806
for ( i = _m = 0 ; _m < scanlineLength ; i = _m += 1 ) {
7780
- byte = data [ pos ++ ] ;
7807
+ abyte = data [ pos ++ ] ;
7781
7808
col = ( i - ( i % pixelBytes ) ) / pixelBytes ;
7782
7809
left = i < pixelBytes ? 0 : pixels [ c - pixelBytes ] ;
7783
7810
if ( row === 0 ) {
@@ -7797,7 +7824,7 @@ var Deflater = (function(obj) {
7797
7824
} else {
7798
7825
paeth = upperLeft ;
7799
7826
}
7800
- pixels [ c ++ ] = ( byte + paeth ) % 256 ;
7827
+ pixels [ c ++ ] = ( abyte + paeth ) % 256 ;
7801
7828
}
7802
7829
break ;
7803
7830
default :
0 commit comments