]> git.parisson.com Git - pdf.js.git/commitdiff
Add Objects.clear() and fallback for testStr in FontMeasure
authorJulian Viereck <julian.viereck@gmail.com>
Thu, 15 Sep 2011 21:06:24 +0000 (14:06 -0700)
committerJulian Viereck <julian.viereck@gmail.com>
Thu, 15 Sep 2011 21:06:24 +0000 (14:06 -0700)
fonts.js
pdf.js
worker.js

index ae8df88a5a3eaa1c346ff54535915776621671f1..2aed3e9b38396c0b88be124226dcd622469defef 100755 (executable)
--- a/fonts.js
+++ b/fonts.js
@@ -224,11 +224,15 @@ var FontLoader = {
     console.log("load font", objId);
     var encoding = fontObj.encoding;
     var testStr = "";
-    for (var enc in encoding) {
-      testStr += String.fromCharCode(encoding[enc].unicode);
-      if (testStr.length == 10) {
-        break;
-      }
+    // If the font has a encoding defined. If, use the characters of the
+    // encoding, otherwise use some dump string for testing.
+    if (Object.keys(encoding).length != 0) {
+      for (var enc in encoding) {
+        testStr += String.fromCharCode(encoding[enc].unicode);
+      }      
+    } else {
+      console.log("empty font.encoding");
+      testStr = "abcdefghiklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789.-+='!";
     }
 
     var before = this.measure(fontObj, testStr);
diff --git a/pdf.js b/pdf.js
index 141d1087638af8c12fed996889f411b2db08b843..d72b422fb251fdf7dd5305d2a31fdff9b97504ec 100644 (file)
--- a/pdf.js
+++ b/pdf.js
@@ -5400,7 +5400,7 @@ var CanvasGraphics = (function() {
     },
 
     paintJpegXObject: function(objId, w, h) {
-      var image = Objects[objId].data;
+      var image = Objects.get(objId);
       if (!image) {
         error("Dependent image isn't ready yet");
       }
index b463261602cfad01f09ed398addec8101dbd4021..e7c3d18da32b0790be8844c4b22c8b6b95ec8e95 100644 (file)
--- a/worker.js
+++ b/worker.js
@@ -60,11 +60,14 @@ var WorkerPage = (function() {
 
 // This holds a list of objects the IR queue depends on.
 var Objects = {
+  hash: {},
+  
   getPromise: function(objId) {
-         if (Objects[objId]) {
-           return this[objId];
+    var hash = this.hash;
+         if (hash[objId]) {
+           return hash[objId];
          } else {
-           return this[objId] = new Promise(objId);
+           return hash[objId] = new Promise(objId);
          }
   },
   
@@ -74,20 +77,26 @@ var Objects = {
   },
        
   resolve: function(objId, data) {
+    var hash = this.hash;
     // In case there is a promise already on this object, just resolve it.
-    if (Objects[objId]) {
-      Objects[objId].resolve(data);
+    if (hash[objId]) {
+      hash[objId].resolve(data);
     } else {
-      Objects[objId] = new Promise(objId, data);
+      hash[objId] = new Promise(objId, data);
     }
   },
 
   get: function(objId) {
-    var obj = Objects[objId];
+    var obj = this.hash[objId];
     if (!obj || !obj.isResolved) {
       throw "Requesting object that isn't resolved yet " + objId;
     }
     return obj.data;
+  },
+  
+  clear: function() {
+    delete this.hash;
+    this.hash = {};
   }
 };
 
@@ -154,6 +163,10 @@ var Promise = (function() {
 
 var WorkerPDFDoc = (function() {
   function constructor(data) {
+    // For now, as we create a new WorkerPDFDoc, we clear all objects.
+    // TODO: Have the objects per WorkerPDFDoc.
+    Objects.clear();
+    
     this.data = data;
     this.stream = new Stream(data);
     this.pdf = new PDFDoc(this.stream);