1
1
/** @preserve
2
2
* jsPDF - PDF Document creation from JavaScript
3
- * Version 1.0.178 -git Built on 2014-06-27T15:34
4
- * CommitID 78eac7128d
3
+ * Version 1.0.198 -git Built on 2014-07-17T20:58
4
+ * CommitID 8fb976ef54
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.178 -debug 2014-06-27T15:34 :diegocr" ;
1700
+ jsPDF . version = "1.0.198 -debug 2014-07-17T20:58 :diegocr" ;
1701
1701
1702
1702
if ( typeof define === 'function' && define . amd ) {
1703
1703
define ( 'jsPDF' , function ( ) {
@@ -1999,8 +1999,12 @@ var jsPDF = (function(global) {
1999
1999
, createDataURIFromElement = function ( element , format ) {
2000
2000
2001
2001
//if element is an image which uses data url defintion, just return the dataurl
2002
- if ( element . nodeName === 'IMG' && element . hasAttribute ( 'src' ) && ( '' + element . getAttribute ( 'src' ) ) . indexOf ( 'data:image/' ) === 0 ) {
2003
- return element . getAttribute ( 'src' ) ;
2002
+ if ( element . nodeName === 'IMG' && element . hasAttribute ( 'src' ) ) {
2003
+ var src = '' + element . getAttribute ( 'src' ) ;
2004
+ if ( src . indexOf ( 'data:image/' ) === 0 ) return src ;
2005
+
2006
+ // only if the user doesn't care about a format
2007
+ if ( ! format && / \. p n g (?: [ ? # ] .* ) ? $ / i. test ( src ) ) format = 'png' ;
2004
2008
}
2005
2009
2006
2010
if ( element . nodeName === 'CANVAS' ) {
@@ -2017,7 +2021,7 @@ var jsPDF = (function(global) {
2017
2021
ctx . drawImage ( element , 0 , 0 , canvas . width , canvas . height ) ;
2018
2022
}
2019
2023
2020
- return canvas . toDataURL ( format == 'png' ? 'image/png' : 'image/jpeg' ) ;
2024
+ return canvas . toDataURL ( ( '' + format ) . toLowerCase ( ) == 'png' ? 'image/png' : 'image/jpeg' ) ;
2021
2025
}
2022
2026
, checkImagesForAlias = function ( imageData , images ) {
2023
2027
var cached_info ;
@@ -2312,11 +2316,9 @@ var jsPDF = (function(global) {
2312
2316
}
2313
2317
2314
2318
var images = getImages . call ( this ) , //initalises internals and events on first run
2315
- cached_info ,
2316
2319
dataAsBinaryString ;
2317
2320
2318
2321
compression = checkCompressValue ( compression ) ;
2319
- format = ( format || 'JPEG' ) . toLowerCase ( ) ;
2320
2322
2321
2323
if ( notDefined ( alias ) )
2322
2324
alias = generateAliasFromData ( imageData ) ;
@@ -2333,30 +2335,33 @@ var jsPDF = (function(global) {
2333
2335
format = base64Info [ 2 ] ;
2334
2336
imageData = atob ( base64Info [ 3 ] ) ; //convert to binary string
2335
2337
2336
- /*
2337
- * need to test if it's more efficent to convert all binary strings
2338
- * to TypedArray - or should we just leave and process as string?
2339
- */
2340
- if ( this . supportsArrayBuffer ( ) ) {
2341
- dataAsBinaryString = imageData ;
2342
- imageData = this . binaryStringToUint8Array ( imageData ) ;
2343
- }
2338
+ } else {
2344
2339
2345
- } else {
2346
- // This is neither raw jpeg-data nor a data uri; alias?
2347
- if ( imageData . charCodeAt ( 0 ) !== 0xff )
2348
- cached_info = checkImagesForAlias ( imageData , images ) ;
2340
+ if ( imgData . charCodeAt ( 0 ) === 0x89 &&
2341
+ imgData . charCodeAt ( 1 ) === 0x50 &&
2342
+ imgData . charCodeAt ( 2 ) === 0x4e &&
2343
+ imgData . charCodeAt ( 3 ) === 0x47 ) format = 'png' ;
2349
2344
}
2350
2345
}
2346
+ format = ( format || 'JPEG' ) . toLowerCase ( ) ;
2351
2347
2352
2348
if ( doesNotSupportImageType ( format ) )
2353
2349
throw new Error ( 'addImage currently only supports formats ' + supported_image_types + ', not \'' + format + '\'' ) ;
2354
2350
2355
2351
if ( processMethodNotEnabled ( format ) )
2356
2352
throw new Error ( 'please ensure that the plugin for \'' + format + '\' support is added' ) ;
2357
2353
2354
+ /*
2355
+ * need to test if it's more efficent to convert all binary strings
2356
+ * to TypedArray - or should we just leave and process as string?
2357
+ */
2358
+ if ( this . supportsArrayBuffer ( ) ) {
2359
+ dataAsBinaryString = imageData ;
2360
+ imageData = this . binaryStringToUint8Array ( imageData ) ;
2361
+ }
2362
+
2358
2363
var imageIndex = getImageIndex ( images ) ,
2359
- info = cached_info ;
2364
+ info = checkImagesForAlias ( dataAsBinaryString || imageData , images ) ;
2360
2365
2361
2366
if ( ! info )
2362
2367
info = this [ 'process' + format . toUpperCase ( ) ] ( imageData , imageIndex , alias , compression , dataAsBinaryString ) ;
@@ -2378,7 +2383,7 @@ var jsPDF = (function(global) {
2378
2383
//Algorithm from: http://www.64lines.com/jpeg-width-height
2379
2384
var getJpegSize = function ( imgData ) {
2380
2385
'use strict'
2381
- var width , height ;
2386
+ var width , height , numcomponents ;
2382
2387
// Verify we have a valid jpeg header 0xff,0xd8,0xff,0xe0,?,?,'J','F','I','F',0x00
2383
2388
if ( ! imgData . charCodeAt ( 0 ) === 0xff ||
2384
2389
! imgData . charCodeAt ( 1 ) === 0xd8 ||
@@ -2408,7 +2413,8 @@ var jsPDF = (function(global) {
2408
2413
imgData . charCodeAt ( i + 1 ) === 0xc7 ) {
2409
2414
height = imgData . charCodeAt ( i + 5 ) * 256 + imgData . charCodeAt ( i + 6 ) ;
2410
2415
width = imgData . charCodeAt ( i + 7 ) * 256 + imgData . charCodeAt ( i + 8 ) ;
2411
- return [ width , height ] ;
2416
+ numcomponents = imgData . charCodeAt ( i + 9 ) ;
2417
+ return [ width , height , numcomponents ] ;
2412
2418
} else {
2413
2419
i += 2 ;
2414
2420
blockLength = imgData . charCodeAt ( i ) * 256 + imgData . charCodeAt ( i + 1 )
@@ -2425,7 +2431,7 @@ var jsPDF = (function(global) {
2425
2431
var len = data . length ,
2426
2432
block = ( data [ 4 ] << 8 ) + data [ 5 ] ,
2427
2433
pos = 4 ,
2428
- bytes , width , height ;
2434
+ bytes , width , height , numcomponents ;
2429
2435
2430
2436
while ( pos < len ) {
2431
2437
pos += block ;
@@ -2435,7 +2441,8 @@ var jsPDF = (function(global) {
2435
2441
bytes = readBytes ( data , pos + 5 ) ;
2436
2442
width = ( bytes [ 2 ] << 8 ) + bytes [ 3 ] ;
2437
2443
height = ( bytes [ 0 ] << 8 ) + bytes [ 1 ] ;
2438
- return { width :width , height :height } ;
2444
+ numcomponents = bytes [ 4 ] ;
2445
+ return { width :width , height :height , numcomponents : numcomponents } ;
2439
2446
}
2440
2447
2441
2448
pos += 2 ;
@@ -2444,7 +2451,7 @@ var jsPDF = (function(global) {
2444
2451
throw new Error ( 'getJpegSizeFromBytes could not find the size of the image' ) ;
2445
2452
}
2446
2453
, readBytes = function ( data , offset ) {
2447
- return data . subarray ( offset , offset + 4 ) ;
2454
+ return data . subarray ( offset , offset + 5 ) ;
2448
2455
} ;
2449
2456
2450
2457
jsPDFAPI . processJPEG = function ( data , index , alias , compression , dataAsBinaryString ) {
@@ -2456,7 +2463,7 @@ var jsPDF = (function(global) {
2456
2463
2457
2464
if ( this . isString ( data ) ) {
2458
2465
dims = getJpegSize ( data ) ;
2459
- return this . createImageInfo ( data , dims [ 0 ] , dims [ 1 ] , colorSpace , bpc , filter , index , alias ) ;
2466
+ return this . createImageInfo ( data , dims [ 0 ] , dims [ 1 ] , dims [ 3 ] == 1 ? this . color_spaces . DEVICE_GRAY : colorSpace , bpc , filter , index , alias ) ;
2460
2467
}
2461
2468
2462
2469
if ( this . isArrayBuffer ( data ) )
@@ -2469,7 +2476,7 @@ var jsPDF = (function(global) {
2469
2476
// if we already have a stored binary string rep use that
2470
2477
data = dataAsBinaryString || this . arrayBufferToBinaryString ( data ) ;
2471
2478
2472
- return this . createImageInfo ( data , dims . width , dims . height , colorSpace , bpc , filter , index , alias ) ;
2479
+ return this . createImageInfo ( data , dims . width , dims . height , dims . numcomponents == 1 ? this . color_spaces . DEVICE_GRAY : colorSpace , bpc , filter , index , alias ) ;
2473
2480
}
2474
2481
2475
2482
return null ;
@@ -3262,12 +3269,23 @@ var jsPDF = (function(global) {
3262
3269
3263
3270
var imagesCSS = GetCSS ( cn ) ;
3264
3271
var imageX = renderer . x ;
3272
+ var fontToUnitRatio = 12 / renderer . pdf . internal . scaleFactor ;
3273
+
3274
+ //define additional paddings, margins which have to be taken into account for margin calculations
3275
+ var additionalSpaceLeft = ( imagesCSS [ "margin-left" ] + imagesCSS [ "padding-left" ] ) * fontToUnitRatio ;
3276
+ var additionalSpaceRight = ( imagesCSS [ "margin-right" ] + imagesCSS [ "padding-right" ] ) * fontToUnitRatio ;
3277
+ var additionalSpaceTop = ( imagesCSS [ "margin-top" ] + imagesCSS [ "padding-top" ] ) * fontToUnitRatio ;
3278
+ var additionalSpaceBottom = ( imagesCSS [ "margin-bottom" ] + imagesCSS [ "padding-bottom" ] ) * fontToUnitRatio ;
3279
+
3265
3280
//if float is set to right, move the image to the right border
3281
+ //add space if margin is set
3266
3282
if ( imagesCSS [ 'float' ] !== undefined && imagesCSS [ 'float' ] === 'right' ) {
3267
- imageX += renderer . settings . width - cn . width ;
3283
+ imageX += renderer . settings . width - cn . width - additionalSpaceRight ;
3284
+ } else {
3285
+ imageX += additionalSpaceLeft ;
3268
3286
}
3269
3287
3270
- renderer . pdf . addImage ( images [ cn . getAttribute ( "src" ) ] , imageX , renderer . y , cn . width , cn . height ) ;
3288
+ renderer . pdf . addImage ( images [ cn . getAttribute ( "src" ) ] , imageX , renderer . y + additionalSpaceTop , cn . width , cn . height ) ;
3271
3289
//if the float prop is specified we have to float the text around the image
3272
3290
if ( imagesCSS [ 'float' ] !== undefined ) {
3273
3291
if ( imagesCSS [ 'float' ] === 'right' || imagesCSS [ 'float' ] === 'left' ) {
@@ -3287,7 +3305,7 @@ var jsPDF = (function(global) {
3287
3305
} else {
3288
3306
return false ;
3289
3307
}
3290
- } ) . bind ( this , ( imagesCSS [ 'float' ] === 'left' ) ? - cn . width : 0 , renderer . y + cn . height , cn . width ) ) ;
3308
+ } ) . bind ( this , ( imagesCSS [ 'float' ] === 'left' ) ? - cn . width - additionalSpaceLeft - additionalSpaceRight : 0 , renderer . y + cn . height + additionalSpaceTop + additionalSpaceBottom , cn . width ) ) ;
3291
3309
3292
3310
//reset floating by clear:both divs
3293
3311
//just set cursorY after the floating element
@@ -3305,15 +3323,15 @@ var jsPDF = (function(global) {
3305
3323
} ) . bind ( this , renderer . y + cn . height , renderer . pdf . internal . getNumberOfPages ( ) ) ) ;
3306
3324
3307
3325
//if floating is set we decrease the available width by the image width
3308
- renderer . settings . width -= cn . width ;
3326
+ renderer . settings . width -= cn . width + additionalSpaceLeft + additionalSpaceRight ;
3309
3327
//if left just add the image width to the X coordinate
3310
3328
if ( imagesCSS [ 'float' ] === 'left' ) {
3311
- renderer . x += cn . width ;
3329
+ renderer . x += cn . width + additionalSpaceLeft + additionalSpaceRight ;
3312
3330
}
3313
3331
}
3314
3332
//if no floating is set, move the rendering cursor after the image height
3315
3333
} else {
3316
- renderer . y += cn . height ;
3334
+ renderer . y += cn . height + additionalSpaceBottom ;
3317
3335
}
3318
3336
3319
3337
/*** TABLE RENDERING ***/
@@ -5391,7 +5409,7 @@ jsPDFAPI.putTotalPages = function(pageExpression) {
5391
5409
} ) ( jsPDF . API ) ;
5392
5410
/* Blob.js
5393
5411
* A Blob implementation.
5394
- * 2014-05-31
5412
+ * 2014-07-01
5395
5413
*
5396
5414
* By Eli Grey, http://eligrey.com
5397
5415
* By Devin Samarin, https://github.com/eboyjr
@@ -5557,7 +5575,7 @@ jsPDFAPI.putTotalPages = function(pageExpression) {
5557
5575
return FakeBlobBuilder ;
5558
5576
} ( view ) ) ;
5559
5577
5560
- view . Blob = function Blob ( blobParts , options ) {
5578
+ view . Blob = function ( blobParts , options ) {
5561
5579
var type = options ? ( options . type || "" ) : "" ;
5562
5580
var builder = new BlobBuilder ( ) ;
5563
5581
if ( blobParts ) {
@@ -5569,12 +5587,12 @@ jsPDFAPI.putTotalPages = function(pageExpression) {
5569
5587
} ;
5570
5588
} ( typeof self !== "undefined" && self || typeof window !== "undefined" && window || this . content || this ) ) ;
5571
5589
/* FileSaver.js
5572
- * A saveAs() FileSaver implementation.
5573
- * 2014-05-27
5590
+ * A saveAs() FileSaver implementation.
5591
+ * 2014-05-27
5574
5592
*
5575
- * By Eli Grey, http://eligrey.com
5576
- * License: X11/MIT
5577
- * See https://github.com/eligrey/FileSaver.js/blob/master/LICENSE.md
5593
+ * By Eli Grey, http://eligrey.com
5594
+ * License: X11/MIT
5595
+ * See https://github.com/eligrey/FileSaver.js/blob/master/LICENSE.md
5578
5596
*/
5579
5597
5580
5598
/*global self */
0 commit comments