})();
var JpegStreamIR = (function() {
- function JpegStreamIR(objId, IR) {
+ function JpegStreamIR(objId, IR, objs) {
var src = 'data:image/jpeg;base64,' + window.btoa(IR);
// create DOM image
img.onload = (function() {
this.loaded = true;
- Objects.resolve(objId, this);
+ objs.resolve(objId, this);
if (this.onLoad)
this.onLoad();
for (var i = 0; i < fonts.length; i++) {
// HACK FOR NOW. Access the data directly. This isn't allowed as the
// font object isn't resolved yet.
- fonts[i] = Objects.objs[fonts[i]].data;
+ fonts[i] = this.objs.objs[fonts[i]].data;
}
// Load all the fonts
this.stats.fonts = Date.now();
callback.call(this);
- }.bind(this)
+ }.bind(this),
+ this.objs
);
},
// if we execute longer then `kExecutionTime`.
var kExecutionTimeCheck = 500;
- function constructor(canvasCtx, imageCanvas) {
+ function constructor(canvasCtx, objs) {
this.ctx = canvasCtx;
this.current = new CanvasExtraState();
this.stateStack = [];
this.pendingClip = null;
this.res = null;
this.xobjs = null;
- this.ScratchCanvas = imageCanvas || ScratchCanvas;
+ this.ScratchCanvas = ScratchCanvas;
+ this.objs = objs;
}
var LINE_CAP_STYLES = ['butt', 'round', 'square'];
var executionEndIdx;
var startTime = Date.now();
+ var objs = this.objs;
+
do {
executionEndIdx = Math.min(argsArrayLen, i + kExecutionTimeCheck);
// If the promise isn't resolved yet, add the continueCallback
// to the promise and bail out.
- if (!Objects.isResolved(depObjId)) {
- Objects.get(depObjId, continueCallback);
+ if (!objs.isResolved(depObjId)) {
+ objs.get(depObjId, continueCallback);
return i;
}
}
setFont: function(fontRef, size) {
// Lookup the fontObj using fontRef only.
var fontRefName = fontRef.name;
- var fontObj = Objects.get(fontRefName);
+ var fontObj = this.objs.get(fontRefName);
if (!fontObj) {
throw "Can't find font for " + fontRefName;
}
// Build the pattern based on the IR data.
- var pattern = new TilingPatternIR(IR, color, this.ctx);
+ var pattern = new TilingPatternIR(IR, color, this.ctx, this.objs);
} else if (IR[0] == "RadialAxialShading" || IR[0] == "DummyShading") {
var pattern = Pattern.shadingFromIR(this.ctx, IR);
} else {
},
paintJpegXObject: function(objId, w, h) {
- var image = Objects.get(objId);
+ var image = this.objs.get(objId);
if (!image) {
error("Dependent image isn't ready yet");
}
var TilingPatternIR = (function() {
var PAINT_TYPE_COLORED = 1, PAINT_TYPE_UNCOLORED = 2;
- function TilingPatternIR(IR, color, ctx) {
+ function TilingPatternIR(IR, color, ctx, objs) {
// "Unfolding" the IR.
var IRQueue = IR[2];
this.matrix = IR[3];
// set the new canvas element context as the graphics context
var tmpCtx = tmpCanvas.getContext('2d');
- var graphics = new CanvasGraphics(tmpCtx);
+ var graphics = new CanvasGraphics(tmpCtx, objs);
switch (paintType) {
case PAINT_TYPE_COLORED:
var useWorker = false;
var WorkerPage = (function() {
- function constructor(workerPDF, page) {
+ function constructor(workerPDF, page, objs) {
this.workerPDF = workerPDF;
this.page = page;
+ this.objs = objs;
this.ref = page.ref;
}
},
startRenderingFromIRQueue: function(IRQueue, fonts) {
- var gfx = new CanvasGraphics(this.ctx);
+ var gfx = new CanvasGraphics(this.ctx, this.objs);
var startTime = Date.now();
var callback = function(err) {
return Promise;
})();
-var Objects = new PDFObjects();
-
var WorkerPDFDoc = (function() {
function constructor(data) {
this.pdf = new PDFDoc(this.stream);
this.catalog = this.pdf.catalog;
+ this.objs = new PDFObjects();
this.pageCache = [];
// aren't loaded on the page yet.
var depFonts = data.depFonts;
var fontsToLoad = [];
+ var objs = this.objs;
function checkFontData() {
// Check if all fontObjs have been processed. If not, shedule a
// the next fonts.
for (var i = 0; i < depFonts.length; i++) {
var fontName = depFonts[i];
- if (!Objects.hasData(fontName)) {
+ if (!objs.hasData(fontName)) {
console.log('need to wait for fontData', fontName);
- Objects.onData(fontObj, checkFontData);
+ objs.onData(fontObj, checkFontData);
return;
- } else if (!Objects.isResolved(fontName)) {
+ } else if (!objs.isResolved(fontName)) {
fontsToLoad.push(fontName);
}
}
switch (objType) {
case "JpegStream":
var IR = data[2];
- new JpegStreamIR(objId, IR);
+ new JpegStreamIR(objId, IR, this.objs);
console.log('got image');
break;
case "Font":
// If there is no string, then there is nothing to attach to the DOM.
if (!fontObj.str) {
- Objects.resolve(objId, fontObj);
+ this.objs.resolve(objId, fontObj);
} else {
- Objects.setData(objId, fontObj);
+ this.objs.setData(objId, fontObj);
}
- });
+ }.bind(this));
if (!useWorker) {
// If the main thread is our worker, setup the handling for the messages
}
var page = this.pdf.getPage(n);
- return this.pageCache[n] = new WorkerPage(this, page);
+ // Add a reference to the objects such that Page can forward the reference
+ // to the CanvasGraphics and so on.
+ page.objs = this.objs;
+ return this.pageCache[n] = new WorkerPage(this, page, this.objs);
},
destroy: function() {