]> git.parisson.com Git - pdf.js.git/commitdiff
Set loadedName in Partial Eval
authorJulian Viereck <julian.viereck@gmail.com>
Mon, 5 Sep 2011 23:06:31 +0000 (16:06 -0700)
committerJulian Viereck <julian.viereck@gmail.com>
Thu, 15 Sep 2011 15:13:13 +0000 (08:13 -0700)
fonts.js
pdf.js

index 7d51e2c4b2acddf272cca0f70be6a6c47c6fefa9..ed2496727d97c73bfa969204700b5f753ab14fcf 100755 (executable)
--- a/fonts.js
+++ b/fonts.js
@@ -472,16 +472,18 @@ var Font = (function Font() {
     this.data = data;
     this.type = properties.type;
     this.textMatrix = properties.textMatrix;
-    this.loadedName = getUniqueName();
     this.composite = properties.composite;
+    this.loadedName = properties.loadedName;
+    
+    // TODO: Remove this once we can be sure nothing got broken to du changes
+    // in this commit.
+    if (!this.loadedName) {
+      throw "There has to be a `loadedName`";
+    }
+    
     this.loading = true;
   };
 
-  var numFonts = 0;
-  function getUniqueName() {
-    return 'pdfFont' + numFonts++;
-  }
-
   function stringToArray(str) {
     var array = [];
     for (var i = 0; i < str.length; ++i)
diff --git a/pdf.js b/pdf.js
index 13ec62e15cc40e37013e6f50759601aee6268d4d..7122c0eb4c4ade96f1e251cb9df76c1ddc1f4773 100644 (file)
--- a/pdf.js
+++ b/pdf.js
@@ -3373,28 +3373,51 @@ var Page = (function() {
         // Firefox error reporting from XHR callbacks.
         setTimeout(function() {
           var exc = null;
-          try {
+          // try {
             self.display(gfx);
             stats.render = Date.now();
-          } catch (e) {
-            exc = e.toString();
-          }
-          if (continuation) continuation(exc);
+          // } catch (e) {
+          //   exc = e.toString();
+          // }
+          continuation(exc);
         });
       };
+      
+      // Make a copy of the necessary datat to build a font later. The `font`
+      // object will be sent to the main thread later on.
+      var fontsBackup = fonts;
+      fonts = [];
+      for (var i = 0; i < fontsBackup.length; i++) {
+        var orgFont = fontsBackup[i];
+        var orgFontObj = orgFont.fontObj;
+      
+        var font = {
+          name:       orgFont.name,
+          file:       orgFont.file,
+          properties: orgFont.properties
+        }
+        fonts.push(font);
+      }
 
       var fontObjs = FontLoader.bind(
         fonts,
         function() {
+          // Rebuild the FontsMap. This is emulating the behavior of the main
+          // thread.
+          if (fontObjs) {
+            // Replace the FontsMap hash with the fontObjs.
+            for (var i = 0; i < fontObjs.length; i++) {
+              FontsMap[fontObjs[i].loadedName] = {fontObj: fontObjs[i]};
+            }
+          }
+
           stats.fonts = Date.now();
           images.notifyOnLoad(function() {
             stats.images = Date.now();
             displayContinuation();
           });
-        });
-
-      for (var i = 0, ii = fonts.length; i < ii; ++i)
-        fonts[i].dict.fontObj = fontObjs[i];
+        }
+      );
     },
 
 
@@ -4052,6 +4075,7 @@ var EvalState = (function() {
 })();
 
 var FontsMap = {};
+var FontLoadedCounter = 0;
 
 var PartialEvaluator = (function() {
   function constructor() {
@@ -4157,7 +4181,9 @@ var PartialEvaluator = (function() {
   };
 
   constructor.prototype = {
-    evaluate: function(stream, xref, resources, fonts, images) {
+    evalRaw: function(stream, xref, resources, fonts, images, uniquePrefix) {
+      uniquePrefix = uniquePrefix || "";
+      
       resources = xref.fetchIfRef(resources) || new Dict();
       var xobjs = xref.fetchIfRef(resources.get('XObject')) || new Dict();
       var patterns = xref.fetchIfRef(resources.get('Pattern')) || new Dict();
@@ -4223,10 +4249,13 @@ var PartialEvaluator = (function() {
                   // keep track of each font we translated so the caller can
                   // load them asynchronously before calling display on a page
                   fonts.push(font.translated);
-                  FontsMap[font.translated.name] = font;
+                  
+                  var loadedName = uniquePrefix + "font_" + (FontLoadedCounter++);
+                  font.translated.properties.loadedName = loadedName;
+                  FontsMap[loadedName] = font;
                 }
               }
-              args[0].name = font.translated.name;
+              args[0].name = font.translated.properties.loadedName;
             } else {
               // TODO: TOASK: Is it possible to get here? If so, what does
               // args[0].name should be like???
@@ -4246,7 +4275,18 @@ var PartialEvaluator = (function() {
       window.fnArray = fnArray;
       window.argsArray = argsArray;
 
+      return {
+        fnArray: fnArray,
+        argsArray: argsArray
+      };
+    },
+    
+    eval: function(stream, xref, resources, fonts, images, uniquePrefix) {
+      var ret = this.evalRaw(stream, xref, resources, fonts, images, uniquePrefix);
+      
       return function(gfx) {
+        var argsArray = ret.argsArray;
+        var fnArray =   ret.fnArray;
         for (var i = 0, length = argsArray.length; i < length; i++)
           gfx[fnArray[i]].apply(gfx, argsArray[i]);
       };