]> git.parisson.com Git - pdf.js.git/commitdiff
Change cmap encoding for Type 1
authornotmasteryet <async.processingjs@yahoo.com>
Sat, 29 Oct 2011 14:29:19 +0000 (09:29 -0500)
committernotmasteryet <async.processingjs@yahoo.com>
Sat, 29 Oct 2011 14:29:19 +0000 (09:29 -0500)
src/fonts.js

index 6202b3279688eaf43d3abe63e4bcbce86a8d5107..5d70bf5e48c2298c3d9b82beba69ce3e9e44c25a 100644 (file)
@@ -729,6 +729,12 @@ function isAdaptedUnicode(unicode) {
     unicode < kCmapGlyphOffset + kSizeOfGlyphArea;
 }
 
+function isSpecialUnicode(unicode) {
+  return (unicode <= 0x1F || (unicode >= 127 && unicode < kSizeOfGlyphArea)) ||
+    unicode >= kCmapGlyphOffset &&
+    unicode < kCmapGlyphOffset + kSizeOfGlyphArea;
+}
+
 /**
  * 'Font' is the class the outside world should use, it encapsulate all the font
  * decoding logics whatever type it is (assuming the font type is supported).
@@ -2744,11 +2750,28 @@ CFF.prototype = {
   getOrderedCharStrings: function cff_getOrderedCharStrings(glyphs,
                                                             properties) {
     var charstrings = [];
-    for (var i = 0; i < glyphs.length; i++) {
+    var reverseMapping = {};
+    var encoding = properties.baseEncoding;
+    var differences = properties.differences;
+    var i, length;
+    for (i = 0, length = encoding.length; i < length; ++i) {
+      if (encoding[i] && !isSpecialUnicode(i))
+        reverseMapping[encoding[i]] = i;
+    }
+    for (i = 0, length = differences.length; i < length; ++i) {
+      if (differences[i] && !isSpecialUnicode(i))
+        reverseMapping[differences[i]] = i;
+    }
+    reverseMapping['.notdef'] = 0;
+    var unusedUnicode = kCmapGlyphOffset;
+    for (i = 0, length = glyphs.length; i < length; i++) {
       var item = glyphs[i];
+      var glyphName = item.glyph;
+      var unicode = glyphName in reverseMapping ?
+        reverseMapping[glyphName] : unusedUnicode++;
       charstrings.push({
-        glyph: item.glyph,
-        unicode: adaptUnicode(i),
+        glyph: glyphName,
+        unicode: unicode,
         gid: i,
         charstring: item.data,
         width: item.width,