11/** @preserve
22 * 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
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.178 -debug 2014-06-27T15:34 :diegocr" ;
1700+ jsPDF . version = "1.0.198 -debug 2014-07-17T20:58 :diegocr" ;
17011701
17021702 if ( typeof define === 'function' && define . amd ) {
17031703 define ( 'jsPDF' , function ( ) {
@@ -1999,8 +1999,12 @@ var jsPDF = (function(global) {
19991999 , createDataURIFromElement = function ( element , format ) {
20002000
20012001 //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' ;
20042008 }
20052009
20062010 if ( element . nodeName === 'CANVAS' ) {
@@ -2017,7 +2021,7 @@ var jsPDF = (function(global) {
20172021 ctx . drawImage ( element , 0 , 0 , canvas . width , canvas . height ) ;
20182022 }
20192023
2020- return canvas . toDataURL ( format == 'png' ? 'image/png' : 'image/jpeg' ) ;
2024+ return canvas . toDataURL ( ( '' + format ) . toLowerCase ( ) == 'png' ? 'image/png' : 'image/jpeg' ) ;
20212025 }
20222026 , checkImagesForAlias = function ( imageData , images ) {
20232027 var cached_info ;
@@ -2312,11 +2316,9 @@ var jsPDF = (function(global) {
23122316 }
23132317
23142318 var images = getImages . call ( this ) , //initalises internals and events on first run
2315- cached_info ,
23162319 dataAsBinaryString ;
23172320
23182321 compression = checkCompressValue ( compression ) ;
2319- format = ( format || 'JPEG' ) . toLowerCase ( ) ;
23202322
23212323 if ( notDefined ( alias ) )
23222324 alias = generateAliasFromData ( imageData ) ;
@@ -2333,30 +2335,33 @@ var jsPDF = (function(global) {
23332335 format = base64Info [ 2 ] ;
23342336 imageData = atob ( base64Info [ 3 ] ) ; //convert to binary string
23352337
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 {
23442339
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' ;
23492344 }
23502345 }
2346+ format = ( format || 'JPEG' ) . toLowerCase ( ) ;
23512347
23522348 if ( doesNotSupportImageType ( format ) )
23532349 throw new Error ( 'addImage currently only supports formats ' + supported_image_types + ', not \'' + format + '\'' ) ;
23542350
23552351 if ( processMethodNotEnabled ( format ) )
23562352 throw new Error ( 'please ensure that the plugin for \'' + format + '\' support is added' ) ;
23572353
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+
23582363 var imageIndex = getImageIndex ( images ) ,
2359- info = cached_info ;
2364+ info = checkImagesForAlias ( dataAsBinaryString || imageData , images ) ;
23602365
23612366 if ( ! info )
23622367 info = this [ 'process' + format . toUpperCase ( ) ] ( imageData , imageIndex , alias , compression , dataAsBinaryString ) ;
@@ -2378,7 +2383,7 @@ var jsPDF = (function(global) {
23782383 //Algorithm from: http://www.64lines.com/jpeg-width-height
23792384 var getJpegSize = function ( imgData ) {
23802385 'use strict'
2381- var width , height ;
2386+ var width , height , numcomponents ;
23822387 // Verify we have a valid jpeg header 0xff,0xd8,0xff,0xe0,?,?,'J','F','I','F',0x00
23832388 if ( ! imgData . charCodeAt ( 0 ) === 0xff ||
23842389 ! imgData . charCodeAt ( 1 ) === 0xd8 ||
@@ -2408,7 +2413,8 @@ var jsPDF = (function(global) {
24082413 imgData . charCodeAt ( i + 1 ) === 0xc7 ) {
24092414 height = imgData . charCodeAt ( i + 5 ) * 256 + imgData . charCodeAt ( i + 6 ) ;
24102415 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 ] ;
24122418 } else {
24132419 i += 2 ;
24142420 blockLength = imgData . charCodeAt ( i ) * 256 + imgData . charCodeAt ( i + 1 )
@@ -2425,7 +2431,7 @@ var jsPDF = (function(global) {
24252431 var len = data . length ,
24262432 block = ( data [ 4 ] << 8 ) + data [ 5 ] ,
24272433 pos = 4 ,
2428- bytes , width , height ;
2434+ bytes , width , height , numcomponents ;
24292435
24302436 while ( pos < len ) {
24312437 pos += block ;
@@ -2435,7 +2441,8 @@ var jsPDF = (function(global) {
24352441 bytes = readBytes ( data , pos + 5 ) ;
24362442 width = ( bytes [ 2 ] << 8 ) + bytes [ 3 ] ;
24372443 height = ( bytes [ 0 ] << 8 ) + bytes [ 1 ] ;
2438- return { width :width , height :height } ;
2444+ numcomponents = bytes [ 4 ] ;
2445+ return { width :width , height :height , numcomponents : numcomponents } ;
24392446 }
24402447
24412448 pos += 2 ;
@@ -2444,7 +2451,7 @@ var jsPDF = (function(global) {
24442451 throw new Error ( 'getJpegSizeFromBytes could not find the size of the image' ) ;
24452452 }
24462453 , readBytes = function ( data , offset ) {
2447- return data . subarray ( offset , offset + 4 ) ;
2454+ return data . subarray ( offset , offset + 5 ) ;
24482455 } ;
24492456
24502457 jsPDFAPI . processJPEG = function ( data , index , alias , compression , dataAsBinaryString ) {
@@ -2456,7 +2463,7 @@ var jsPDF = (function(global) {
24562463
24572464 if ( this . isString ( data ) ) {
24582465 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 ) ;
24602467 }
24612468
24622469 if ( this . isArrayBuffer ( data ) )
@@ -2469,7 +2476,7 @@ var jsPDF = (function(global) {
24692476 // if we already have a stored binary string rep use that
24702477 data = dataAsBinaryString || this . arrayBufferToBinaryString ( data ) ;
24712478
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 ) ;
24732480 }
24742481
24752482 return null ;
@@ -3262,12 +3269,23 @@ var jsPDF = (function(global) {
32623269
32633270 var imagesCSS = GetCSS ( cn ) ;
32643271 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+
32653280 //if float is set to right, move the image to the right border
3281+ //add space if margin is set
32663282 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 ;
32683286 }
32693287
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 ) ;
32713289 //if the float prop is specified we have to float the text around the image
32723290 if ( imagesCSS [ 'float' ] !== undefined ) {
32733291 if ( imagesCSS [ 'float' ] === 'right' || imagesCSS [ 'float' ] === 'left' ) {
@@ -3287,7 +3305,7 @@ var jsPDF = (function(global) {
32873305 } else {
32883306 return false ;
32893307 }
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 ) ) ;
32913309
32923310 //reset floating by clear:both divs
32933311 //just set cursorY after the floating element
@@ -3305,15 +3323,15 @@ var jsPDF = (function(global) {
33053323 } ) . bind ( this , renderer . y + cn . height , renderer . pdf . internal . getNumberOfPages ( ) ) ) ;
33063324
33073325 //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 ;
33093327 //if left just add the image width to the X coordinate
33103328 if ( imagesCSS [ 'float' ] === 'left' ) {
3311- renderer . x += cn . width ;
3329+ renderer . x += cn . width + additionalSpaceLeft + additionalSpaceRight ;
33123330 }
33133331 }
33143332 //if no floating is set, move the rendering cursor after the image height
33153333 } else {
3316- renderer . y += cn . height ;
3334+ renderer . y += cn . height + additionalSpaceBottom ;
33173335 }
33183336
33193337 /*** TABLE RENDERING ***/
@@ -5391,7 +5409,7 @@ jsPDFAPI.putTotalPages = function(pageExpression) {
53915409} ) ( jsPDF . API ) ;
53925410/* Blob.js
53935411 * A Blob implementation.
5394- * 2014-05-31
5412+ * 2014-07-01
53955413 *
53965414 * By Eli Grey, http://eligrey.com
53975415 * By Devin Samarin, https://github.com/eboyjr
@@ -5557,7 +5575,7 @@ jsPDFAPI.putTotalPages = function(pageExpression) {
55575575 return FakeBlobBuilder ;
55585576 } ( view ) ) ;
55595577
5560- view . Blob = function Blob ( blobParts , options ) {
5578+ view . Blob = function ( blobParts , options ) {
55615579 var type = options ? ( options . type || "" ) : "" ;
55625580 var builder = new BlobBuilder ( ) ;
55635581 if ( blobParts ) {
@@ -5569,12 +5587,12 @@ jsPDFAPI.putTotalPages = function(pageExpression) {
55695587 } ;
55705588} ( typeof self !== "undefined" && self || typeof window !== "undefined" && window || this . content || this ) ) ;
55715589/* FileSaver.js
5572- * A saveAs() FileSaver implementation.
5573- * 2014-05-27
5590+ * A saveAs() FileSaver implementation.
5591+ * 2014-05-27
55745592 *
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
55785596 */
55795597
55805598/*global self */
0 commit comments