]> git.parisson.com Git - pdf.js.git/commitdiff
Converting MacRoman symbols to Unicodes
authornotmasteryet <async.processingjs@yahoo.com>
Wed, 11 Jan 2012 01:41:45 +0000 (19:41 -0600)
committernotmasteryet <async.processingjs@yahoo.com>
Wed, 11 Jan 2012 01:41:45 +0000 (19:41 -0600)
src/fonts.js

index 4950a844a6cc059ddf091362a06c593f4770e96c..8f20deff95947519972821bb512bc08a19eed9b9 100644 (file)
@@ -835,7 +835,6 @@ var Font = (function FontClosure() {
     this.widthMultiplier = !properties.fontMatrix ? 1.0 :
       1.0 / properties.fontMatrix[0];
     this.encoding = properties.baseEncoding;
-    this.hasShortCmap = properties.hasShortCmap;
     this.loadedName = getUniqueName();
     this.loading = true;
   };
@@ -1805,7 +1804,20 @@ var Font = (function FontClosure() {
             this.useToUnicode = true;
           }
         }
-        properties.hasShortCmap = hasShortCmap;
+
+        if (hasShortCmap && this.hasEncoding && !this.isSymbolicFont) {
+          // Re-encode short map encoding to unicode -- that simplifies the
+          // resolution of MacRoman encoded glyphs logic for TrueType fonts.
+          for (var i = 0, ii = glyphs.length; i < ii; i++) {
+            var code = glyphs[i].unicode;
+            var glyphName = properties.baseEncoding[code];
+            if (!glyphName)
+              continue;
+            if (!(glyphName in GlyphsUnicode))
+              continue;
+            glyphs[i].unicode = GlyphsUnicode[glyphName];
+          }
+        }
 
         // remove glyph references outside range of avaialable glyphs
         for (var i = 0, ii = ids.length; i < ii; i++) {
@@ -2193,15 +2205,11 @@ var Font = (function FontClosure() {
             unicode = this.useToUnicode ? this.toUnicode[charcode] : charcode;
             break;
           }
-          if (this.hasShortCmap) {
-            var j = this.encoding.indexOf(glyphName);
-            unicode = j >= 0 ? j :
-              this.glyphNameMap[glyphName];
-          } else {
-            unicode = glyphName in GlyphsUnicode ?
-              GlyphsUnicode[glyphName] :
-              this.glyphNameMap[glyphName];
-          }
+
+          // MacRoman encoding address by re-encoding the cmap table
+          unicode = glyphName in GlyphsUnicode ?
+            GlyphsUnicode[glyphName] :
+            this.glyphNameMap[glyphName];
           break;
         default:
           warn('Unsupported font type: ' + this.type);