]> git.parisson.com Git - pdf.js.git/commitdiff
Split compilation up in preCompile and Compile.
authorJulian Viereck <julian.viereck@gmail.com>
Tue, 6 Sep 2011 00:01:02 +0000 (17:01 -0700)
committerJulian Viereck <julian.viereck@gmail.com>
Thu, 15 Sep 2011 15:17:19 +0000 (08:17 -0700)
pdf.js

diff --git a/pdf.js b/pdf.js
index 475137475ad5deec45339318cd62f37c0d062811..bc75e8b521667ef4612965119d19e21a088e6dcf 100644 (file)
--- 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) {