]> git.parisson.com Git - pdf.js.git/commitdiff
Fix bad chars in Type2CFF font names.
authorBrendan Dahl <brendan.dahl@gmail.com>
Mon, 20 Feb 2012 06:12:22 +0000 (22:12 -0800)
committerBrendan Dahl <brendan.dahl@gmail.com>
Mon, 20 Feb 2012 06:12:22 +0000 (22:12 -0800)
src/fonts.js
test/pdfs/.gitignore
test/pdfs/issue925.pdf [new file with mode: 0755]
test/test_manifest.json

index 0f9b6f9d09f4343f836882be50b7e5986817780d..7b09aa8ca4e35a18ed7f5ee87cb8efe275340a18 100644 (file)
@@ -3321,7 +3321,9 @@ var Type2CFF = (function Type2CFFClosure() {
     parse: function cff_parse() {
       var header = this.parseHeader();
       var properties = this.properties;
+
       var nameIndex = this.parseIndex(header.endPos);
+      this.sanitizeName(nameIndex);
 
       var dictIndex = this.parseIndex(nameIndex.endPos);
       if (dictIndex.length != 1)
@@ -3690,6 +3692,19 @@ var Type2CFF = (function Type2CFFClosure() {
       }
       return dict;
     },
+    sanitizeName: function cff_sanitizeName(nameIndex) {
+      // There should really only be one font, but loop to make sure.
+      for (var i = 0, ii = nameIndex.length; i < ii; ++i) {
+        var data = nameIndex.get(i).data;
+        var length = data.length;
+        if (length > 127)
+          warn('Font had name longer than 127 chars, will be rejected.');
+        // Only certain chars are permitted in the font name.  Set them all to
+        // 'A' to avoid being rejected.
+        for (var j = 0; j < length; ++j)
+          data[j] = 65;
+      }
+    },
     getStrings: function cff_getStrings(stringIndex) {
       function bytesToString(bytesArray) {
         var str = '';
index e0926492b647a846d7b7f277972054004c7b16ab..9460cfbecdb26c50b1802156ee4421fbcb3095f7 100644 (file)
@@ -24,3 +24,4 @@
 !type4psfunc.pdf
 !S2.pdf
 !zerowidthline.pdf
+!issue925.pdf
diff --git a/test/pdfs/issue925.pdf b/test/pdfs/issue925.pdf
new file mode 100755 (executable)
index 0000000..16329cb
Binary files /dev/null and b/test/pdfs/issue925.pdf differ
index e09f16da92ad11cd39f457d0ac9d01926144ec53..e9aebdc90a223dcc7bf6d22f3aa4e11483e531d1 100644 (file)
       "link": true,
       "type": "eq"
     },
+    {  "id": "issue925",
+      "file": "pdfs/issue925.pdf",
+      "md5": "f58fe943090aff89dcc8e771bc0db4c2",
+      "rounds": 1,
+      "link": true,
+      "type": "eq"
+    },
     {  "id": "issue1133",
       "file": "pdfs/issue1133.pdf",
       "md5": "d1b61580cb100e3df93d33703af1773a",