]> git.parisson.com Git - pdf.js.git/commitdiff
Simplify the cmap format 6 conversion - fix #449
authorVivien Nicolas <21@vingtetun.org>
Sat, 10 Sep 2011 11:41:07 +0000 (13:41 +0200)
committerVivien Nicolas <21@vingtetun.org>
Sat, 10 Sep 2011 11:41:07 +0000 (13:41 +0200)
fonts.js

index 32de47c56389e0f4b3981bb8822d3d01d35d9449..9f835f9bc00f8e66ab5e3a58fe379466eb75ca04 100755 (executable)
--- a/fonts.js
+++ b/fonts.js
@@ -1001,43 +1001,17 @@ var Font = (function Font() {
             var entryCount = int16(font.getBytes(2));
 
             var glyphs = [];
-            var min = 0xffff, max = 0;
-            for (var j = 0; j < entryCount; j++) {
-              var charcode = int16(font.getBytes(2));
-              if (!charcode)
-                continue;
-              glyphs.push(charcode);
-
-              if (charcode < min)
-                min = charcode;
-              if (charcode > max)
-                max = charcode;
-            }
-
-            // Since Format 6 is a dense array, check for gaps
-            for (var j = min; j < max; j++) {
-              if (glyphs.indexOf(j) == -1)
-                glyphs.push(j);
-            }
-
-            for (var j = 0; j < glyphs.length; j++)
-              glyphs[j] = { unicode: glyphs[j] + firstCode };
-
-            var ranges = getRanges(glyphs);
-            assert(ranges.length == 1, 'Got ' + ranges.length +
-                   ' ranges in a dense array');
-
-            var denseRange = ranges[0];
-            var start = denseRange[0];
-            var end = denseRange[1];
-            var index = firstCode;
-            for (var j = start; j <= end; j++) {
-              var code = glyphs[j - start];
-              var mapping = encoding[index] || {};
-              mapping.unicode = code.unicode;
-              encoding[index++] = mapping;
+            var ids = [];
+            for (var j = 0; j < firstCode + entryCount; j++) {
+              var code = (j >= firstCode) ? int16(font.getBytes(2)) : j;
+              glyphs.push({ unicode: j + kCmapGlyphOffset });
+              ids.push(code);
+
+              var mapping = encoding[j] || {};
+              mapping.unicode = glyphs[j].unicode;
+              encoding[j] = mapping;
             }
-            return cmap.data = createCMapTable(glyphs);
+            return cmap.data = createCMapTable(glyphs, ids);
           }
         }
         return cmap.data;