Implement endInlineImage IR

This commit is contained in:
Julian Viereck 2011-09-08 17:55:38 -07:00
parent 7ee894c09c
commit a2bf701bfe
2 changed files with 71 additions and 76 deletions

133
pdf.js
View File

@ -4197,6 +4197,70 @@ var PartialEvaluator = (function() {
constructor.prototype = {
getIRQueue: function(stream, xref, resources, queue, fonts, images, uniquePrefix) {
function buildPaintImageXObject(image, inline) {
var dict = image.dict;
var w = dict.get('Width', 'W');
var h = dict.get('Height', 'H');
if (image instanceof JpegStream) {
var objId = ++objIdCounter;
images.push({
id: objId,
IR: image.getIR()
});
// Add the dependency on the image object.
fnArray.push("dependency");
argsArray.push([ objId ]);
// The normal fn.
fn = 'paintJpegXObject';
args = [ objId, w, h ];
} else {
// Needs to be rendered ourself.
// Figure out if the image has an imageMask.
var imageMask = dict.get('ImageMask', 'IM') || false;
// If there is no imageMask, create the PDFImage and a lot
// of image processing can be done here.
if (!imageMask) {
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 = "paintImageXObject";
args = [ imgData ];
} else /* imageMask == true */ {
// This depends on a tmpCanvas beeing filled with the
// current fillStyle, such that processing the pixel
// data can't be done here. Instead of creating a
// complete PDFImage, only read the information needed
// for later.
fn = "paintImageMaskXObject";
var width = dict.get('Width', 'W');
var height = dict.get('Height', 'H');
var bitStrideLength = (width + 7) >> 3;
var imgArray = image.getBytes(bitStrideLength * height);
var decode = dict.get('Decode', 'D');
var inverseDecode = !!decode && decode[0] > 0;
args = [ imgArray, inverseDecode, width, height ];
}
}
}
uniquePrefix = uniquePrefix || "";
if (!queue.argsArray) {
queue.argsArray = []
@ -4283,69 +4347,7 @@ var PartialEvaluator = (function() {
fn = "paintFormXObjectEnd";
args = [];
} else if ('Image' == type.name) {
var image = xobj;
var dict = image.dict;
var w = dict.get('Width', 'W');
var h = dict.get('Height', 'H');
if (image instanceof JpegStream) {
var objId = ++objIdCounter;
images.push({
id: objId,
IR: image.getIR()
});
// Add the dependency on the image object.
fnArray.push("dependency");
argsArray.push([ objId ]);
// The normal fn.
fn = 'paintJpegXObject';
args = [ objId, w, h ];
} else {
// Needs to be rendered ourself.
// Figure out if the image has an imageMask.
var imageMask = dict.get('ImageMask', 'IM') || false;
// If there is no imageMask, create the PDFImage and a lot
// of image processing can be done here.
if (!imageMask) {
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 = "paintImageXObject";
args = [ imgData ];
} else /* imageMask == true */ {
// This depends on a tmpCanvas beeing filled with the
// current fillStyle, such that processing the pixel
// data can't be done here. Instead of creating a
// complete PDFImage, only read the information needed
// for later.
fn = "paintImageMaskXObject";
var width = dict.get('Width', 'W');
var height = dict.get('Height', 'H');
var bitStrideLength = (width + 7) >> 3;
var imgArray = image.getBytes(bitStrideLength * height);
var decode = dict.get('Decode', 'D');
var inverseDecode = !!imageObj.decode && imageObj.decode[0] > 0;
args = [ imgArray, inverseDecode, width, height ];
}
}
buildPaintImageXObject(xobj, false)
} else {
error('Unhandled XObject subtype ' + type.name);
}
@ -4375,6 +4377,8 @@ var PartialEvaluator = (function() {
// TODO: TOASK: Is it possible to get here? If so, what does
// args[0].name should be like???
}
} else if (cmd == 'EI') {
buildPaintImageXObject(args[0], true);
}
// Transform some cmds.
@ -5383,9 +5387,6 @@ var CanvasGraphics = (function() {
beginImageData: function() {
error('Should not call beginImageData');
},
endInlineImage: function(image) {
this.paintImageXObject(null, image, true);
},
paintFormXObjectBegin: function(matrix, bbox) {
this.save();

View File

@ -37,16 +37,10 @@ MessageHandler.prototype = {
},
send: function(actionName, data) {
try {
this.comObj.postMessage({
action: actionName,
data: data
});
} catch (e) {
console.error("FAILED to send data from", this.name);
throw e;
}
this.comObj.postMessage({
action: actionName,
data: data
});
}
}