diff --git a/base/display/api.js b/base/display/api.js index 344cb20f..f1fd048f 100755 --- a/base/display/api.js +++ b/base/display/api.js @@ -862,8 +862,8 @@ var WorkerTransport = (function WorkerTransportClosure() { promise.resolve({ data: buf, width: width, height: height}); }).bind(this); //MQZ. Oct.17.2012 - disable image drawing -// img.src = imageUrl; - img.src = 'data:image/jpeg;base64,' + img.btoa(imageUrl); + img.src = imageUrl; +// img.src = 'data:image/jpeg;base64,' + img.btoa(imageUrl); }); }, diff --git a/base/shared/util.js b/base/shared/util.js index d7b3213d..a2a2de66 100755 --- a/base/shared/util.js +++ b/base/shared/util.js @@ -145,8 +145,11 @@ var OPS = PDFJS.OPS = { //MQZ.Mar.22 Disabled Operators (to prevent image painting & annotation default appearance) //paintJpegXObject, paintImageMaskXObject, paintImageMaskXObjectGroup, paintImageXObject, paintInlineImageXObject, paintInlineImageXObjectGroup -var NO_OPS = PDFJS.NO_OPS = [82, 83, 84, 85, 86, 87]; +var NO_OPS = PDFJS.NO_OPS = [83, 84, 86, 87]; var NO_OPS_RANGE = PDFJS.NO_OPS_RANGE = [78, 79, 80, 81]; //range pairs, all ops with each pair will be skipped. !important! +var HTMLElement = typeof HTMLElement === "undefined" ? + function() { } : HTMLElement; + // Use only for debugging purposes. This should not be used in any code that is // in mozilla master. @@ -1229,9 +1232,9 @@ function loadJpegStream(id, imageUrl, objs) { img.onload = (function loadJpegStream_onloadClosure() { objs.resolve(id, img); }); -// img.src = imageUrl; + img.src = imageUrl; //MQZ. Apr.09.2013 calls windows.btoa safely - img.src = 'data:image/jpeg;base64,' + img.btoa(imageUrl); +// img.src = 'data:image/jpeg;base64,' + img.btoa(imageUrl); } //MQZ Oct.18.2013 expose util methods diff --git a/lib/imagedata.js b/lib/imagedata.js new file mode 100644 index 00000000..8f405b60 --- /dev/null +++ b/lib/imagedata.js @@ -0,0 +1,13 @@ +function ImageData(width, height) { + if (width && width instanceof Object) { + this.width = width.width; + this.height = width.height; + this.data = width.data; + } else { + this.width = width; + this.height = height; + this.data = new Uint8Array(width * height * 4); + } +}; + +module.exports = ImageData; diff --git a/lib/pdf.js b/lib/pdf.js index d31a7626..fe1c35ca 100644 --- a/lib/pdf.js +++ b/lib/pdf.js @@ -5,6 +5,7 @@ let nodeUtil = require("util"), fs = require('fs'), _ = require('lodash'), DOMParser = require('xmldom').DOMParser, + ImageData = require('./imagedata.js'), PDFCanvas = require('./pdfcanvas.js'), PDFUnit = require('./pdfunit.js'), PDFField = require('./pdffield.js'), @@ -376,7 +377,8 @@ let PDFJSClass = (function () { // Content:pdfPage.getTextContent(), Texts: pageParser.Texts, Fields: pageParser.Fields, - Boxsets: pageParser.Boxsets + Boxsets: pageParser.Boxsets, + Images: pageParser.Images }; this.pages.push(page); diff --git a/lib/pdfcanvas.js b/lib/pdfcanvas.js index 6b94725e..8d2032d1 100644 --- a/lib/pdfcanvas.js +++ b/lib/pdfcanvas.js @@ -3,7 +3,8 @@ let nodeUtil = require("util"), _ = require('lodash'), PDFLine = require('./pdfline'), PDFFill = require('./pdffill'), - PDFFont = require('./pdffont'); + PDFFont = require('./pdffont'), + ImageData = require('./imagedata'); (function () { // private static @@ -104,6 +105,35 @@ let nodeUtil = require("util"), return 'square'; } } + + function addImage(image, images) { + if(images.indexOf(image) !== -1) { + return; + } + if(images.find(function(im) { + if (im.src) { + return im.src === image.src; + } else if ( + image.data && + im.data && + im.data.length === image.data.length && + im.width === image.width && + im.height === image.height + ) { + if (image.data === im.data) { + return true; + } + return im.data.find(function(v,i) { + return v !== image.data[i]; + }) === undefined; + } else { + return false; + } + }) !== undefined) { + return; + } + images.push(image); + } /** * This class implements CanvasRenderingContext2D interface as described by @@ -144,6 +174,8 @@ let nodeUtil = require("util"), canvasTarget.Fills = []; if (!_.has(canvasTarget, "Texts") || !_.isArray(canvasTarget.Texts)) canvasTarget.Texts = []; + if (!_.has(canvasTarget, "Images") || !_.isArray(canvasTarget.Images)) + canvasTarget.Images = []; this.canvas = canvasTarget; @@ -387,8 +419,23 @@ let nodeUtil = require("util"), return gradient; }; - contextPrototype.drawImage = function (image, var_args) { - //MQZ. no image drawing support for now + contextPrototype.drawImage = function(image) { + if (image instanceof CanvasRenderingContext2D_) { + image.canvas.Images.forEach(function(data) { + addImage(data, this.canvas.Images); + }, this); + } else { + addImage(image, this.canvas.Images); + } + }; + + contextPrototype.putImageData = function(image) { + addImage(image, this.canvas.Images); + }; + + + contextPrototype.createImageData = function(width, height) { + return new ImageData(width, height); }; contextPrototype.getImageData = function (x, y, w, h) {