]> git.parisson.com Git - pdf.js.git/commitdiff
Fix CIDFontType2 large cmap tables
authornotmasteryet <async.processingjs@yahoo.com>
Tue, 29 Nov 2011 01:47:37 +0000 (19:47 -0600)
committernotmasteryet <async.processingjs@yahoo.com>
Tue, 29 Nov 2011 01:47:37 +0000 (19:47 -0600)
src/fonts.js

index fb9bb9f0cdd07c54b87837dd78eb05278d73d811..734b38c4a1289970f9250576a51f12d55b134131 100644 (file)
@@ -1701,27 +1701,37 @@ var Font = (function Font() {
         }
 
         var glyphs = [], ids = [];
-        var usedUnicodes = [], unusedUnicode = kCmapGlyphOffset;
+        var usedUnicodes = [];
         var cidToGidMap = properties.cidToGidMap;
-        for (i = 1; i < numGlyphs; i++) {
+        var unassignedUnicodeItems = [];
+        for (var i = 1; i < numGlyphs; i++) {
           var cid = cidToGidMap ? cidToGidMap.indexOf(i) : i;
           var unicode = this.toUnicode[cid];
           if (!unicode || isSpecialUnicode(unicode) ||
               unicode in usedUnicodes) {
-            // overriding the special special symbols mapping
-            while (unusedUnicode in usedUnicodes)
-              unusedUnicode++;
-            this.toUnicode[cid] = unicode = unusedUnicode++;
-            if (unusedUnicode >= kCmapGlyphOffset + kSizeOfGlyphArea) {
-              // overflow of the user defined symblos range
-              // using symbols that a little bit lower than this range
-              unusedUnicode = kCmapGlyphOffset - numGlyphs;
-            }
+            unassignedUnicodeItems.push(i);
+            continue;
           }
           usedUnicodes[unicode] = true;
           glyphs.push({ unicode: unicode, code: cid });
           ids.push(i);
         }
+        // checking if unassigned symbols will fit the user defined symbols
+        // if those symbols too many, probably they will not be used anyway
+        if (unassignedUnicodeItems.length <= kSizeOfGlyphArea) {
+          var unusedUnicode = kCmapGlyphOffset;
+          for (var j = 0, jj = unassignedUnicodeItems.length; j < jj; j++) {
+            var i = unassignedUnicodeItems[j];
+            var cid = cidToGidMap ? cidToGidMap.indexOf(i) : i;
+            while (unusedUnicode in usedUnicodes)
+              unusedUnicode++;
+            var unicode = unusedUnicode++;
+            this.toUnicode[cid] = unicode;
+            usedUnicodes[unicode] = true;
+            glyphs.push({ unicode: unicode, code: cid });
+            ids.push(i);
+          }
+        }
         cmap.data = createCMapTable(glyphs, ids);
       } else {
         var cmapTable = readCMapTable(cmap, font);