From 67f745443e3cc7df8bcc1fba645ce3b5770682ca Mon Sep 17 00:00:00 2001 From: Julian Viereck Date: Mon, 5 Sep 2011 19:38:22 -0700 Subject: [PATCH] Add support for xobj embedded images that are not rendered by the platform + has no mask --- pdf.js | 54 +++++++++++++++++++++++++++++++++++++++++++++++------- 1 file changed, 47 insertions(+), 7 deletions(-) diff --git a/pdf.js b/pdf.js index f12f2213a..db4d23179 100644 --- a/pdf.js +++ b/pdf.js @@ -4272,6 +4272,21 @@ var PartialEvaluator = (function() { var inline = false; var imageObj = new PDFImage(xref, resources, image, inline); + + if (imageObj.imageMask) { + throw "Can't handle this in the web worker :/"; + } + + var imgData = { + width: w, + height: h, + data: new Uint8Array(w * h * 4) + }; + var pixels = imgData.data; + imageObj.fillRgbaBuffer(pixels, imageObj.decode); + + fn = "paintReadyImageXObject"; + args = [ imgData ]; console.log("xobj subtype image", w, h, imageObj.imageMask); } @@ -4306,13 +4321,13 @@ var PartialEvaluator = (function() { } } - var skips = ["paintXObject"]; - - if (skips.indexOf(fn) != -1) { - // console.log("skipping", fn); - args = []; - continue; - } + // var skips = ["paintXObject"]; + // + // if (skips.indexOf(fn) != -1) { + // // console.log("skipping", fn); + // args = []; + // continue; + // } fnArray.push(fn); argsArray.push(args); @@ -5403,6 +5418,31 @@ var CanvasGraphics = (function() { ctx.drawImage(tmpCanvas, 0, -h); this.restore(); }, + + paintReadyImageXObject: function(imgData) { + this.save(); + + var ctx = this.ctx; + var w = imgData.width; + var h = imgData.height; + // scale the image to the unit square + ctx.scale(1 / w, -1 / h); + + + var tmpCanvas = new this.ScratchCanvas(w, h); + var tmpCtx = tmpCanvas.getContext('2d'); + var tmpImgData = tmpCtx.getImageData(0, 0, w, h); + + // Copy over the imageData. + var tmpImgDataPixels = tmpImgData.data; + var len = tmpImgDataPixels.length; + while (len--) + tmpImgDataPixels[len] = imgData.data[len]; + + tmpCtx.putImageData(tmpImgData, 0, 0); + ctx.drawImage(tmpCanvas, 0, -h); + this.restore(); + }, // Marked content