]> git.parisson.com Git - pdf.js.git/commitdiff
Fixing TrueType code-glyph assigmnent to pass sanitizer
authornotmasteryet <async.processingjs@yahoo.com>
Thu, 8 Dec 2011 02:59:44 +0000 (20:59 -0600)
committernotmasteryet <async.processingjs@yahoo.com>
Thu, 8 Dec 2011 02:59:44 +0000 (20:59 -0600)
src/fonts.js
test/pdfs/lista_preliminar.pdf.link [new file with mode: 0644]
test/test_manifest.json

index 1a4366c198dcb4dae6ac1f149f7ba0385d5d7a0e..fa2c0a7f13d285c8573ac96e6856c106f813407a 100644 (file)
@@ -1765,7 +1765,7 @@ var Font = (function Font() {
         var hasShortCmap = !!cmapTable.hasShortCmap;
         var toUnicode = this.toUnicode;
 
-        if (toUnicode) {
+        if (toUnicode && toUnicode.length > 0) {
           // checking if cmap is just identity map
           var isIdentity = true;
           for (var i = 0, ii = glyphs.length; i < ii; i++) {
@@ -1776,9 +1776,22 @@ var Font = (function Font() {
           }
           // if it is, replacing with meaningful toUnicode values
           if (isIdentity) {
+            var usedUnicodes = [], unassignedUnicodeItems = [];
             for (var i = 0, ii = glyphs.length; i < ii; i++) {
-              var unicode = toUnicode[i + 1] || i + 1;
+              var unicode = toUnicode[i + 1];
+              if (!unicode || usedUnicodes[unicode]) {
+                unassignedUnicodeItems.push(i);
+                continue;
+              }
               glyphs[i].unicode = unicode;
+              usedUnicodes[unicode] = true;
+            }
+            var unusedUnicode = kCmapGlyphOffset;
+            for (var j = 0, jj = unassignedUnicodeItems.length; j < jj; j++) {
+              var i = unassignedUnicodeItems[j];
+              while (usedUnicodes[unusedUnicode])
+                unusedUnicode++;
+              glyphs[i].unicode = unusedUnicode++;
             }
             this.useToUnicode = true;
           }
diff --git a/test/pdfs/lista_preliminar.pdf.link b/test/pdfs/lista_preliminar.pdf.link
new file mode 100644 (file)
index 0000000..54102b3
--- /dev/null
@@ -0,0 +1 @@
+http://www.lfg.com.br/concursodebolsas/lista_preliminar_classificao.pdf
index bd50068f7ba17c6e0acc98d575a7152b30b9a713..0e6e1913cf16b494264d4250e58c11829553552f 100644 (file)
        "pageLimit": 5,
        "skipPages": [1],
        "type": "eq"
+    },
+    {  "id": "lista_preliminar",
+       "file": "pdfs/lista_preliminar.pdf",
+       "md5": "4eff251319eeb660ba8a7a5cfac7787d",
+       "rounds": 1,
+       "link": true,
+       "pageLimit": 3,
+       "type": "eq"
     }
 ]