From c39eae3ce932832e1275ec0b1f3fec5226390cc6 Mon Sep 17 00:00:00 2001
From: sbarman <sbarman@L3CWZ5T.(none)>
Date: Thu, 7 Jul 2011 17:15:53 -0700
Subject: [PATCH] fixed up minor bugs

---
 fonts.js | 28 +++++++++++++---------------
 pdf.js   |  3 +--
 2 files changed, 14 insertions(+), 17 deletions(-)

diff --git a/fonts.js b/fonts.js
index d068e6714..48c99d8a7 100755
--- a/fonts.js
+++ b/fonts.js
@@ -31,11 +31,13 @@ var Fonts = (function Fonts() {
     ctx.scale(1 / kScalePrecision, 1);
   }
 
-  function FontInfo(name, data, properties, id) {
+  var fontCount = 0;
+  
+  function FontInfo(name, data, properties) {
     this.name = name;
     this.data = data;
     this.properties = properties;
-    this.id = id;
+    this.id = fontCount++;
     this.loading = true;
     this.charsCache = Object.create(null);
     this.sizes = [];
@@ -45,12 +47,11 @@ var Fonts = (function Fonts() {
   var charsCache;
   var measureCache;
 
-  var fontCount = 0;
-
   return {
     registerFont: function fonts_registerFont(fontName, data, properties) {
-      fonts.push(new FontInfo(fontName, data, properties, fontCount));
-      return fontCount++;
+      var font = new FontInfo(fontName, data, properties);
+      fonts.push(font);
+      return font.id;
     },
     blacklistFont: function fonts_blacklistFont(fontName) {
       var id = registerFont(fontName, null, {});
@@ -122,8 +123,8 @@ var FontLoader = {
 
   bind: function(fonts, callback) {
     function checkFontsLoaded() {
-      for (var i = 0; i < fonts.length; i++) {
-        var id = fonts[i].fontDict.fontObj.id;
+      for (var i = 0; i < allIds.length; i++) {
+        var id = allIds[i];
         if (Fonts.lookupById(id).loading) {
           return false;
         }
@@ -136,12 +137,15 @@ var FontLoader = {
       return true;
     }
 
+    var allIds = [];
     var rules = [], names = [], ids = [];
+
     for (var i = 0; i < fonts.length; i++) {
       var font = fonts[i];
 
       var obj = new Font(font.name, font.file, font.properties);
       font.fontDict.fontObj = obj;
+      allIds.push(obj.id);
 
       var str = '';
       var data = Fonts.lookupById(obj.id).data;
@@ -160,7 +164,7 @@ var FontLoader = {
     if (!isWorker && rules.length) {
       FontLoader.prepareFontLoadEvent(rules, names, ids);
     }
-
+    
     if (!checkFontsLoaded()) {
       document.documentElement.addEventListener(
         'pdfjsFontLoad', checkFontsLoaded, false);
@@ -407,12 +411,6 @@ var Font = (function() {
     this.name = name;
     this.encoding = properties.encoding;
 
-    // If the font has already been decoded simply return it
-    //if (Fonts.lookup(name)) {
-    //  this.font = Fonts.lookup(name).data;
-    //  return;
-    //}
-
     // If the font is to be ignored, register it like an already loaded font
     // to avoid the cost of waiting for it be be loaded by the platform.
     if (properties.ignore) {
diff --git a/pdf.js b/pdf.js
index 64a25210f..a2526f362 100644
--- a/pdf.js
+++ b/pdf.js
@@ -3687,7 +3687,6 @@ var CanvasGraphics = (function() {
               var font = xref.fetchIfRef(fontRes.get(args[0].name));
               assertWellFormed(IsDict(font));
               if (!font.translated) {
-                // sbarman marker
                 font.translated = this.translateFont(font, xref, resources);
                 if (fonts && font.translated) {
                   // keep track of each font we translated so the caller can
@@ -3886,7 +3885,7 @@ var CanvasGraphics = (function() {
         this.ctx.$setFont(fontName, size);
       } else {
         this.ctx.font = size + 'px "' + fontName + '"';
-        Fonts.setActive(font, size);
+        Fonts.setActive(fontObj, size);
       }
     },
     setTextRenderingMode: function(mode) {