Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Minimal images support #91

Closed
wants to merge 7 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions base/display/api.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
});
},

Expand Down
9 changes: 6 additions & 3 deletions base/shared/util.js
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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
Expand Down
13 changes: 13 additions & 0 deletions lib/imagedata.js
Original file line number Diff line number Diff line change
@@ -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;
4 changes: 3 additions & 1 deletion lib/pdf.js
Original file line number Diff line number Diff line change
Expand Up @@ -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'),
Expand Down Expand Up @@ -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);
Expand Down
53 changes: 50 additions & 3 deletions lib/pdfcanvas.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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;

Expand Down Expand Up @@ -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) {
Expand Down