]> git.parisson.com Git - pdf.js.git/commitdiff
Re-enable TrueType and add a TODO about translating the ToUnicode entry (note TrueTyp...
authorVivien Nicolas <21@vingtetun.org>
Sun, 19 Jun 2011 02:35:25 +0000 (04:35 +0200)
committerVivien Nicolas <21@vingtetun.org>
Sun, 19 Jun 2011 02:35:25 +0000 (04:35 +0200)
fonts.js
pdf.js

index aa0ad2933e47a35273b5346a207a291a243778cf..8bc169aa615d61b4be9b7e2976f39b23e9400f05 100644 (file)
--- a/fonts.js
+++ b/fonts.js
@@ -100,18 +100,6 @@ var Font = function(aName, aFile, aProperties) {
       break;
 
     case "TrueType":
-      // TrueType is disabled for the moment since the sanitizer prevent it
-      // from loading because of an overdated cmap table
-      return Fonts[aName] = {
-        data: null,
-        properties: {
-          encoding: {},
-          charset: null
-        },
-        loading: false,
-        cache: Object.create(null)
-      };
-
       this.mimetype = "font/opentype";
       var ttf = new TrueType(aFile);
       this.font = ttf.data;
@@ -184,7 +172,7 @@ Font.prototype = {
     document.body.appendChild(canvas);
 
     // Retrieve font charset
-    var charset = Fonts[fontName].charset || [];
+    var charset = Fonts[fontName].properties.charset || [];
     // if the charset is too small make it repeat a few times
     var count = 30;
     while (count-- && charset.length <= 30)
@@ -205,7 +193,7 @@ Font.prototype = {
       }
     }
     ctx.font = "bold italic 20px " + fontName + ", Symbol, Arial";
-    var textWidth = ctx.measureText(testString);
+    var textWidth = ctx.measureText(testString).width;
 
     if (debug)
       ctx.fillText(testString, 20, 20);
@@ -220,7 +208,7 @@ Font.prototype = {
         window.clearInterval(interval);
         Fonts[fontName].loading = false;
         warn("Is " + fontName + " for charset: " + charset + " loaded?");
-      } else if (textWidth != ctx.measureText(testString)) {
+      } else if (textWidth != ctx.measureText(testString).width) {
         window.clearInterval(interval);
         Fonts[fontName].loading = false;
       }
diff --git a/pdf.js b/pdf.js
index 399708b8471205d3eb44bfa04cd470169a803146..2288654f353d7cea341e44576cf5dd9a79cc9139 100644 (file)
--- a/pdf.js
+++ b/pdf.js
@@ -1902,6 +1902,7 @@ var CanvasGraphics = (function() {
 
             // Generate the custom cmap of the font if needed
             var encodingMap = {};
+            var charset = [];
             if (fontDict.has("Encoding")) {
                 var encoding = xref.fetchIfRef(fontDict.get("Encoding"));
                 if (IsDict(encoding)) {
@@ -1923,16 +1924,23 @@ var CanvasGraphics = (function() {
                     if (!encoding)
                         error("Unknown font encoding");
 
-                    var widths = xref.fetchIfRef(fontDict.get("Widths"));
                     var firstChar = xref.fetchIfRef(fontDict.get("FirstChar"));
+
+                    var index = 0;
+                    for (var j = 0; j < encoding.length; j++) {
+                        encodingMap[firstChar + index++] = GlyphsUnicode[encoding[j]];
+                    }
+
+                    var widths = xref.fetchIfRef(fontDict.get("Widths"));
                     assertWellFormed(IsArray(widths) && IsInt(firstChar),
                                      "invalid font Widths or FirstChar");
-                    var charset = [];
                     for (var j = 0; j < widths.length; j++) {
                         if (widths[j])
                             charset.push(encoding[j + firstChar]);
                     }
                 }
+            } else if (fontDict.has("ToUnicode")) {
+              TODO("ToUnicode stream translation not implemented");
             }
 
             var subType = fontDict.get("Subtype");