From 0134143c67d9995249e83b73cf42180daa3463e0 Mon Sep 17 00:00:00 2001 From: Julian Viereck Date: Mon, 5 Sep 2011 17:01:02 -0700 Subject: [PATCH] Split compilation up in preCompile and Compile. --- pdf.js | 28 +++++++++++++++++++++++----- 1 file changed, 23 insertions(+), 5 deletions(-) diff --git a/pdf.js b/pdf.js index 475137475..bc75e8b52 100644 --- a/pdf.js +++ b/pdf.js @@ -3408,7 +3408,7 @@ var Page = (function() { }) }, - compile: function(gfx, fonts, images) { + preCompile: function(gfx, fonts, images) { if (this.code) { // content was compiled return; @@ -3424,7 +3424,12 @@ var Page = (function() { content[i] = xref.fetchIfRef(content[i]); content = new StreamsSequenceStream(content); } - this.code = gfx.compile(content, xref, resources, fonts, images); + return gfx.preCompile(content, xref, resources, fonts, images); + }, + + compile: function(gfx, fonts, images) { + var preCompilation = this.preCompile(gfx, fonts, images); + this.code = gfx.postCompile(preCompilation); }, ensureFonts: function(fonts, callback) { @@ -4299,6 +4304,15 @@ var PartialEvaluator = (function() { gfx[fnArray[i]].apply(gfx, argsArray[i]); }; }, + + evalFromRaw: function(raw) { + return function(gfx) { + var argsArray = raw.argsArray; + var fnArray = raw.fnArray; + for (var i = 0, length = argsArray.length; i < length; i++) + gfx[fnArray[i]].apply(gfx, argsArray[i]); + }; + }, extractEncoding: function(dict, xref, properties) { var type = properties.type, encoding; @@ -4761,9 +4775,13 @@ var CanvasGraphics = (function() { this.ctx.scale(cw / mediaBox.width, ch / mediaBox.height); }, - compile: function(stream, xref, resources, fonts, images) { - var pe = new PartialEvaluator(); - return pe.evaluate(stream, xref, resources, fonts, images); + preCompile: function(stream, xref, resources, fonts, images) { + var pe = this.pe = new PartialEvaluator(); + return pe.evalRaw(stream, xref, resources, fonts, images); + }, + + postCompile: function(raw) { + return this.pe.evalFromRaw(raw); }, execute: function(code, xref, resources) {