|
146 | 146 |
|
147 | 147 | return imageIndex; |
148 | 148 | } |
149 | | - , noAliasDefined = function(alias) { |
150 | | - return typeof alias === 'undefined' || alias === null; |
| 149 | + , notDefined = function(value) { |
| 150 | + return typeof value === 'undefined' || value === null; |
151 | 151 | } |
152 | 152 | , generateAliasFromData = function(data) { |
153 | 153 | // TODO: Alias dynamic generation from imageData's checksum/hash |
|
448 | 448 | compress = compress || false; |
449 | 449 | format = format.toLowerCase(); |
450 | 450 |
|
451 | | - if(noAliasDefined(alias)) |
| 451 | + if(notDefined(alias)) |
452 | 452 | alias = generateAliasFromData(imageData); |
453 | 453 |
|
454 | 454 | if(isDOMElement(imageData)) |
|
488 | 488 | var imageIndex = getImageIndex(images), |
489 | 489 | info = cached_info; |
490 | 490 |
|
491 | | - if(!info) { |
492 | | - |
493 | | - if(format === 'jpg') |
494 | | - format = 'jpeg'; |
495 | | - |
| 491 | + if(!info) |
496 | 492 | info = this['process' + format.toUpperCase()](imageData, imageIndex, alias, compress, dataAsBinaryString); |
497 | | - } |
498 | 493 |
|
499 | | - if( !info ) |
| 494 | + if(!info) |
500 | 495 | throw new Error('An unkwown error occurred whilst processing the image'); |
501 | 496 |
|
502 | 497 | writeImageToPDF.call(this, x, y, w, h, info, imageIndex, images); |
|
553 | 548 | }; |
554 | 549 |
|
555 | 550 |
|
556 | | - jsPDFAPI.processJPEG = function(imageData, imageIndex, alias, compress, dataAsBinaryString) { |
| 551 | + jsPDFAPI.processJPEG = function(data, index, alias, compress, dataAsBinaryString) { |
557 | 552 | 'use strict' |
558 | 553 | var colorSpace = this.DEVICE_RGB, |
559 | 554 | filter = this.DCT_DECODE, |
560 | 555 | bpc = 8, |
561 | 556 | dims; |
562 | 557 |
|
563 | | - if(this.isString(imageData)) { |
564 | | - dims = getJpegSize(imageData); |
565 | | - return this.createImageInfo(imageData, dims[0], dims[1], colorSpace, bpc, filter, imageIndex, alias); |
| 558 | + if(this.isString(data)) { |
| 559 | + dims = getJpegSize(data); |
| 560 | + return this.createImageInfo(data, dims[0], dims[1], colorSpace, bpc, filter, index, alias); |
566 | 561 | } |
567 | 562 |
|
568 | | - if(this.isArrayBuffer(imageData)) |
569 | | - imageData = new Uint8Array(imageData); |
| 563 | + if(this.isArrayBuffer(data)) |
| 564 | + data = new Uint8Array(data); |
570 | 565 |
|
571 | | - if(this.isArrayBufferView(imageData)) { |
| 566 | + if(this.isArrayBufferView(data)) { |
572 | 567 |
|
573 | 568 | var img = new JpegImage(); |
574 | | - img.parse(imageData); |
| 569 | + img.parse(data); |
575 | 570 |
|
576 | 571 | /* |
577 | 572 | * if we already have a stored binary string rep use that |
578 | 573 | */ |
579 | | - imageData = dataAsBinaryString || this.arrayBufferToBinaryString(imageData); |
| 574 | + data = dataAsBinaryString || this.arrayBufferToBinaryString(data); |
580 | 575 |
|
581 | | - return this.createImageInfo(imageData, img.width, img.height, colorSpace, bpc, filter, imageIndex, alias); |
| 576 | + return this.createImageInfo(data, img.width, img.height, colorSpace, bpc, filter, index, alias); |
582 | 577 | } |
583 | 578 |
|
584 | 579 | return null; |
585 | 580 | }; |
| 581 | + |
| 582 | + jsPDFAPI.processJPG = function(data, index, alias, compress, dataAsBinaryString) { |
| 583 | + return this.processJPEG(data, index, alias, compress, dataAsBinaryString); |
| 584 | + } |
586 | 585 |
|
587 | 586 | })(jsPDF.API); |
0 commit comments