]> git.parisson.com Git - pdf.js.git/commitdiff
Clean up encoding parsing
authorVivien Nicolas <21@vingtetun.org>
Tue, 30 Aug 2011 00:34:35 +0000 (02:34 +0200)
committerVivien Nicolas <21@vingtetun.org>
Tue, 30 Aug 2011 00:34:35 +0000 (02:34 +0200)
fonts.js
pdf.js

index 94aee84454629a9d399ad8c246b3d576bdda5a3f..39936d43264e263a3fcf4c25a9ada500e07b8709 100755 (executable)
--- a/fonts.js
+++ b/fonts.js
@@ -385,6 +385,7 @@ var Font = (function Font() {
   var constructor = function font_constructor(name, file, properties) {
     this.name = name;
     this.encoding = properties.encoding;
+    this.glyphs = properties.glyphs;
     this.sizes = [];
 
     // If the font is to be ignored, register it like an already loaded font
@@ -1271,6 +1272,10 @@ var Font = (function Font() {
             unicode = charcode;
           }
 
+          // Check if the glyph has already been converted
+          if (!IsNum(unicode))
+            unicode = encoding[charcode] = this.glyphs[unicode];
+
           // Handle surrogate pairs
           if (unicode > 0xFFFF) {
             str += String.fromCharCode(unicode & 0xFFFF);
@@ -1703,9 +1708,9 @@ var Type1Parser = function() {
                 var index = parseInt(getToken());
                 var glyph = getToken();
               
-                if (!properties.encoding[index]) {
-                  var code = GlyphsUnicode[glyph];
-                  properties.glyphs[glyph] = properties.encoding[index] = code;
+                if ('undefined' == typeof(properties.differences[index])) {
+                  properties.encoding[index] = glyph;
+                  properties.glyphs[glyph] = GlyphsUnicode[glyph];
                 }
                 getToken(); // read the in 'put'
               }
diff --git a/pdf.js b/pdf.js
index 597e8b23f2701d1d269cb0c4e78fde87d9b8819a..550e729202d18ed23eff94ecf76af908526c9691 100644 (file)
--- a/pdf.js
+++ b/pdf.js
@@ -4290,7 +4290,7 @@ var PartialEvaluator = (function() {
             glyphsMap[glyph] = encodingMap[i] = GlyphsUnicode[glyph];
         }
 
-        if (fontDict.has('ToUnicode') && differences) {
+        if (fontType == 'TrueType' && fontDict.has('ToUnicode') && differences) {
           var cmapObj = xref.fetchIfRef(fontDict.get('ToUnicode'));
           if (IsName(cmapObj)) {
             error('ToUnicode file cmap translation not implemented');
@@ -4358,6 +4358,7 @@ var PartialEvaluator = (function() {
         var baseFontName = fontDict.get('BaseFont');
         if (!IsName(baseFontName))
           return null;
+
         // Using base font name as a font name.
         baseFontName = baseFontName.name.replace(/[\+,\-]/g, '_');
         if (/^Symbol(_?(Bold|Italic))*$/.test(baseFontName)) {