]> git.parisson.com Git - pdf.js.git/commitdiff
built-in fonts are not cached
authorChris Jones <jones.chris.g@gmail.com>
Tue, 5 Jul 2011 04:02:09 +0000 (00:02 -0400)
committerChris Jones <jones.chris.g@gmail.com>
Tue, 5 Jul 2011 04:02:09 +0000 (00:02 -0400)
fonts.js
viewer.js

index 47aeabc3ff163bde76e1d63f492dfb4cfc9daf91..8701f8e5fea184f0fda746c88c0a98540ce8d944 100644 (file)
--- a/fonts.js
+++ b/fonts.js
@@ -70,11 +70,14 @@ var Fonts = (function Fonts() {
       return fonts[fontName];
     },
     setActive: function fonts_setActive(fontName, size) {
-      current = fonts[fontName];
-      charsCache = current.charsCache;
-      var sizes = current.sizes;
-      if (!(measureCache = sizes[size]))
-        measureCache = sizes[size] = Object.create(null);
+      // |current| can be null is fontName is a built-in font
+      // (e.g. "sans-serif")
+      if ((current = fonts[fontName])) {
+        charsCache = current.charsCache;
+        var sizes = current.sizes;
+        if (!(measureCache = sizes[size]))
+          measureCache = sizes[size] = Object.create(null);
+      }
       ctx.font = (size * kScalePrecision) + 'px "' + fontName + '"';
     },
     charsToUnicode: function fonts_chars2Unicode(chars) {
@@ -87,7 +90,7 @@ var Fonts = (function Fonts() {
         return str;
 
       // translate the string using the font's encoding
-      var encoding = current.properties.encoding;
+      var encoding = current ? current.properties.encoding : null;
       if (!encoding)
         return chars;
 
index 4071151aaadae3273035507dffda5a88a8405eb9..6702a67359bb598dcddfa594173b363d6398d8f3 100644 (file)
--- a/viewer.js
+++ b/viewer.js
@@ -91,7 +91,9 @@ function displayPage(num) {
         infoDisplay.innerHTML = "Time to load/compile/fonts/render: "+ (t1 - t0) + "/" + (t2 - t1) + "/" + (t3 - t2) + "/" + (t4 - t3) + " ms";
     }
 
-    FontLoader.bind(fonts, displayPage);
+    // Always defer call to displayPage() to work around bug in
+    // Firefox error reporting from XHR callbacks.
+    FontLoader.bind(fonts, function () { setTimeout(displayPage, 0); });
 }
 
 function nextPage() {