]> git.parisson.com Git - pdf.js.git/commitdiff
Add and fix pdfkit_compressed.pdf
authornotmasteryet <async.processingjs@yahoo.com>
Fri, 2 Mar 2012 03:23:36 +0000 (21:23 -0600)
committernotmasteryet <async.processingjs@yahoo.com>
Fri, 2 Mar 2012 03:23:36 +0000 (21:23 -0600)
src/fonts.js
test/pdfs/.gitignore
test/pdfs/pdfkit_compressed.pdf [new file with mode: 0644]
test/test_manifest.json

index 261a907f2897d8d9f4f5d130f7b1663f1205e8c5..0d0e12fec9224c4810c93ef2c6d8439721a5b54d 100644 (file)
@@ -1881,6 +1881,7 @@ var Font = (function FontClosure() {
         var unusedUnicode = kCmapGlyphOffset;
         var glyphNames = properties.glyphNames || [];
         var encoding = properties.baseEncoding;
+        var differences = properties.differences;
         if (toFontChar && toFontChar.length > 0) {
           // checking if cmap is just identity map
           var isIdentity = true;
@@ -1945,35 +1946,51 @@ var Font = (function FontClosure() {
             }
           }
           this.useToFontChar = true;
-        } else if (!this.isSymbolicFont &&
-                   (this.hasEncoding || properties.glyphNames)) {
+        } else if (!this.isSymbolicFont && (this.hasEncoding ||
+                    properties.glyphNames || differences.length > 0)) {
           // Re-encode cmap encoding to unicode, based on the 'post' table data
-          // or base encoding
+          // diffrence array or base encoding
           var reverseMap = [];
           for (var i = 0, ii = glyphs.length; i < ii; i++)
             reverseMap[glyphs[i].unicode] = i;
 
           for (var i = 0, ii = glyphs.length; i < ii; i++) {
             var code = glyphs[i].unicode;
+            var changeCode = false;
             var gid = ids[i];
 
-            var glyphName = glyphNames[gid] || encoding[code];
+            var glyphName = glyphNames[gid];
+            if (!glyphName) {
+              glyphName = differences[code] || encoding[code];
+              changeCode = true;
+            }
             if (glyphName in GlyphsUnicode) {
               var unicode = GlyphsUnicode[glyphName];
               if (!unicode || reverseMap[unicode] === i)
                 continue; // unknown glyph name or in its own place
 
               var destination = reverseMap[unicode];
+              if (typeof destination === 'number' && destination > i)
+                continue;
+
               var j = i;
               // Flipping unicodes while next destination unicode has assigned
               // glyph and future glyph can be assigned to unicode.
               while (typeof destination === 'number') {
                 glyphs[j].unicode = unicode;
                 reverseMap[unicode] = j;
+                if (changeCode) {
+                  toFontChar[code] = unicode;
+                  changeCode = false;
+                }
 
                 code = glyphs[destination].unicode;
                 gid = ids[destination];
-                glyphName = glyphNames[gid] || encoding[code];
+                glyphName = glyphNames[gid];
+                if (!glyphName) {
+                  glyphName = differences[code] || encoding[code];
+                  changeCode = true;
+                }
 
                 unicode = GlyphsUnicode[glyphName];
                 if (!unicode || reverseMap[unicode] === j) {
@@ -1994,7 +2011,10 @@ var Font = (function FontClosure() {
 
               glyphs[j].unicode = unicode;
               reverseMap[unicode] = j;
+              if (changeCode)
+                toFontChar[code] = unicode;
             }
+            this.useToFontChar = true;
           }
         }
 
index 81b63290de8bd6f2caf5a3bc71f6781ed987183c..f142368608cdaf879bdea3bfbbb7f9b18528aacb 100644 (file)
@@ -19,6 +19,7 @@
 !issue840.pdf
 !scan-bad.pdf
 !freeculture.pdf
+!pdfkit_compressed.pdf
 !issue918.pdf
 !issue1249.pdf
 !smaskdim.pdf
diff --git a/test/pdfs/pdfkit_compressed.pdf b/test/pdfs/pdfkit_compressed.pdf
new file mode 100644 (file)
index 0000000..f3e2521
Binary files /dev/null and b/test/pdfs/pdfkit_compressed.pdf differ
index c2cbaa415fd958c974f9545a434a995fa6d799fc..16d9241513e6fbe058bc01937a3961d7ece032c7 100644 (file)
       "link": true,
       "type": "eq"
     },
+    {  "id": "pdfkit_compressed",
+      "file": "pdfs/pdfkit_compressed.pdf",
+      "md5": "ffe9c571d0a1572e234253e6c7cdee6c",
+      "rounds": 1,
+      "type": "eq"
+    },
     {  "id": "issue925",
       "file": "pdfs/issue925.pdf",
       "md5": "f58fe943090aff89dcc8e771bc0db4c2",