]> git.parisson.com Git - pdf.js.git/commitdiff
If the font isn't supported, don't handle it
authorJulian Viereck <julian.viereck@gmail.com>
Fri, 16 Sep 2011 04:54:47 +0000 (21:54 -0700)
committerJulian Viereck <julian.viereck@gmail.com>
Fri, 16 Sep 2011 04:54:47 +0000 (21:54 -0700)
fonts.js
pdf.js

index 2aed3e9b38396c0b88be124226dcd622469defef..834064b46f50789bbef919c39333ae92666a1c5d 100755 (executable)
--- a/fonts.js
+++ b/fonts.js
@@ -184,6 +184,7 @@ if (!isWorker) {
  */
 var FontLoader = {
   scratchCtx: null,
+  loading: {},
   
   /**
    * Create the canvas used for measuring the width of text.
@@ -221,18 +222,22 @@ var FontLoader = {
    * the font is loaded.
    */
   bind: function(objId, fontObj) {
-    console.log("load font", objId);
+    this.loading[objId] = true;
     var encoding = fontObj.encoding;
-    var testStr = "";
-    // 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) {
+    
+    // If the font has an encoding, build the test string based on it. If the
+    // font doesn't have an encoding, the font can't been used right now and
+    // we skip here.
+    if (fontObj.supported) {
+      var testStr = "";
       for (var enc in encoding) {
         testStr += String.fromCharCode(encoding[enc].unicode);
       }      
     } else {
-      console.log("empty font.encoding");
-      testStr = "abcdefghiklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789.-+='!";
+      // This font isn't fully supported yet. Resolve the object such that
+      // the execution continues but do nothing else.
+      Objects.resolve(objId);
+      return;
     }
 
     var before = this.measure(fontObj, testStr);
@@ -244,6 +249,7 @@ var FontLoader = {
       for (var i = 0; i < measure.length; i++) {
         if (measure[i] !== before[i]) {
             console.log("loaded font", objId);
+            delete this.loading[objId];
             Objects.resolve(objId);
             return;
         }        
@@ -448,6 +454,8 @@ var FontShape = (function FontShape() {
 
     this.$name1 = italic + ' ' + bold + ' ';
     this.$name2 = 'px "' + name + '", "';
+    
+    this.supported = Object.keys(this.encoding).length != 0;
   };
 
   function int16(bytes) {
diff --git a/pdf.js b/pdf.js
index ef6e04188c39ddb57cd513d3989c3b2581b8d314..faac047b3e0f52b45fe9e7f1ae8d95a73176fc29 100644 (file)
--- a/pdf.js
+++ b/pdf.js
@@ -5165,6 +5165,12 @@ var CanvasGraphics = (function() {
       this.moveText(0, this.current.leading);
     },
     showText: function(text) {
+      // If the current font isn't supported, we can't display the text and
+      // bail out.
+      if (!this.current.font.supported) {
+        return;
+      }
+      
       var ctx = this.ctx;
       var current = this.current;
       var originalText = text;
@@ -5213,6 +5219,12 @@ var CanvasGraphics = (function() {
       this.ctx.restore();
     },
     showSpacedText: function(arr) {
+      // If the current font isn't supported, we can't display the text and
+      // bail out.
+      if (!this.current.font.supported) {
+        return;
+      }
+      
       for (var i = 0; i < arr.length; ++i) {
         var e = arr[i];
         if (IsNum(e)) {