]> git.parisson.com Git - pdf.js.git/commitdiff
Fixing large cmap-s; reduce changes in the indent encoding
authornotmasteryet <async.processingjs@yahoo.com>
Sat, 17 Sep 2011 22:13:22 +0000 (17:13 -0500)
committernotmasteryet <async.processingjs@yahoo.com>
Sat, 17 Sep 2011 22:13:22 +0000 (17:13 -0500)
fonts.js
test/pdfs/wnv_chinese.pdf.link [new file with mode: 0644]
test/test_manifest.json

index 4f95d16f035784a2ddf0aa2cec16ef0836c16876..f9462ccbb0abe01ec6ea06a95e0ffc430e6f05fd 100644 (file)
--- a/fonts.js
+++ b/fonts.js
@@ -594,19 +594,24 @@ var Font = (function Font() {
     var codes = [];
     var length = glyphs.length;
     for (var n = 0; n < length; ++n)
-      codes.push(String.fromCharCode(glyphs[n].unicode));
-    codes.sort();
+      codes.push({ unicode: glyphs[n].unicode, code: n });
+    codes.sort(function(a, b) {
+      return a.unicode - b.unicode;
+    });
 
     // Split the sorted codes into ranges.
     var ranges = [];
     for (var n = 0; n < length; ) {
-      var start = codes[n++].charCodeAt(0);
+      var start = codes[n].unicode;
+      var startCode = codes[n].code;
+      ++n;
       var end = start;
-      while (n < length && end + 1 == codes[n].charCodeAt(0)) {
+      while (n < length && end + 1 == codes[n].unicode) {
         ++end;
         ++n;
       }
-      ranges.push([start, end]);
+      var endCode = codes[n - 1].code;
+      ranges.push([start, end, startCode, endCode]);
     }
 
     return ranges;
@@ -635,21 +640,38 @@ var Font = (function Font() {
     var idRangeOffsets = '';
     var glyphsIds = '';
     var bias = 0;
-    for (var i = 0; i < segCount - 1; i++) {
-      var range = ranges[i];
-      var start = range[0];
-      var end = range[1];
-      var offset = (segCount - i) * 2 + bias * 2;
-      bias += (end - start + 1);
-
-      startCount += string16(start);
-      endCount += string16(end);
-      idDeltas += string16(0);
-      idRangeOffsets += string16(offset);
-    }
 
-    for (var i = 0; i < glyphs.length; i++)
-      glyphsIds += string16(deltas ? deltas[i] : i + 1);
+    if (deltas) {
+      for (var i = 0; i < segCount - 1; i++) {
+        var range = ranges[i];
+        var start = range[0];
+        var end = range[1];
+        var offset = (segCount - i) * 2 + bias * 2;
+        bias += (end - start + 1);
+
+        startCount += string16(start);
+        endCount += string16(end);
+        idDeltas += string16(0);
+        idRangeOffsets += string16(offset);
+
+        var startCode = range[2];
+        var endCode = range[3];
+        for (var j = startCode; j <= endCode; ++j)
+          glyphsIds += string16(deltas[j]);
+      }
+    } else {
+      for (var i = 0; i < segCount - 1; i++) {
+        var range = ranges[i];
+        var start = range[0];
+        var end = range[1];
+        var startCode = range[2];
+
+        startCount += string16(start);
+        endCount += string16(end);
+        idDeltas += string16((startCode - start + 1) & 0xFFFF);
+        idRangeOffsets += string16(0);
+      }
+    }
 
     endCount += '\xFF\xFF';
     startCount += '\xFF\xFF';
@@ -1124,7 +1146,7 @@ var Font = (function Font() {
           tables.push(cmap);
         }
 
-        var encoding = properties.encoding;
+        var encoding = properties.encoding, i;
         if (!encoding[0]) {
           // the font is directly characters to glyphs with no encoding
           // so create an identity encoding
@@ -1132,18 +1154,25 @@ var Font = (function Font() {
           for (i = 0; i < numGlyphs; i++) {
             var width = widths[i];
             encoding[i] = {
-              unicode: i + kCmapGlyphOffset,
+              unicode: i <= 0x1f || (i >= 127 && i <= 255) ?
+                i + kCmapGlyphOffset : i,
               width: IsNum(width) ? width : properties.defaultWidth
             };
           }
         } else {
-          for (var code in encoding)
-            encoding[code].unicode += kCmapGlyphOffset;
+          for (i = 0; i <= 0x1f; i++)
+            encoding[i].unicode += kCmapGlyphOffset;
+          for (i = 127; i <= 255; i++)
+            encoding[i].unicode += kCmapGlyphOffset;
         }
 
         var glyphs = [];
-        for (var i = 1; i < numGlyphs; i++)
-          glyphs.push({ unicode: i + kCmapGlyphOffset });
+        for (i = 1; i < numGlyphs; i++) {
+          glyphs.push({
+            unicode: i <= 0x1f || (i >= 127 && i <= 255) ?
+              i + kCmapGlyphOffset : i
+          });
+        }
         cmap.data = createCMapTable(glyphs);
       } else {
         replaceCMapTable(cmap, font, properties);
diff --git a/test/pdfs/wnv_chinese.pdf.link b/test/pdfs/wnv_chinese.pdf.link
new file mode 100644 (file)
index 0000000..fbbc817
--- /dev/null
@@ -0,0 +1 @@
+http://www.cdc.gov/ncidod/dvbid/westnile/languages/chinese.pdf
index 926e37c187b5d0786a4c13d006cd6c2c6a9e6dc5..66d26c4e96c3a36562eff1972a96c7b66acdf1b9 100644 (file)
        "rounds": 1,
        "type": "load"
     },
+    {  "id": "wnv_chinese-pdf",
+       "file": "pdfs/wnv_chinese.pdf",
+       "link": true,
+       "rounds": 1,
+       "type": "eq"
+    },
     {  "id": "i9-pdf",
        "file": "pdfs/i9.pdf",
        "link": true,