]> git.parisson.com Git - pdf.js.git/commitdiff
Fixing PDF bad structure and 'fi' ligature
authornotmasteryet <async.processingjs@yahoo.com>
Sat, 8 Oct 2011 03:24:26 +0000 (22:24 -0500)
committernotmasteryet <async.processingjs@yahoo.com>
Sat, 8 Oct 2011 03:24:26 +0000 (22:24 -0500)
fonts.js
pdf.js
test/pdfs/usmanm-bad.pdf.link [new file with mode: 0644]
test/test_manifest.json

index 7d9b484650085ab32b3c9623007cacba31c96025..2ab3a90b76eee461e938d5b55ffb41994d6fa752 100644 (file)
--- a/fonts.js
+++ b/fonts.js
@@ -2550,7 +2550,7 @@ var Type2CFF = (function type2CFF() {
       var defaultWidth = privateDict['defaultWidthX'];
       var charstrings = [];
       var differences = properties.differences;
-      var index = 0;
+      var index = properties.firstChar || 0;
       for (var i = 1; i < charsets.length; i++) {
         var code = -1;
         var glyph = charsets[i];
@@ -2562,7 +2562,8 @@ var Type2CFF = (function type2CFF() {
           }
         }
 
-        var mapping = properties.glyphs[glyph] || {};
+        var mapping =
+          properties.glyphs[glyph] || properties.glyphs[index] || {};
         if (code == -1)
           index = code = mapping.unicode || index;
 
diff --git a/pdf.js b/pdf.js
index 943986e0d057d7df0907b83ec8f82bd50d9c6af2..e804126fe3617b108188f35ea794c249ce419423 100644 (file)
--- a/pdf.js
+++ b/pdf.js
@@ -3260,7 +3260,7 @@ var XRef = (function xRefXRef() {
       var stream = this.stream;
       stream.pos = 0;
       var buffer = stream.getBytes();
-      var position = 0, length = buffer.length;
+      var position = stream.start, length = buffer.length;
       var trailers = [], xrefStms = [];
       var state = 0;
       var currentToken;
@@ -3311,6 +3311,7 @@ var XRef = (function xRefXRef() {
           this.readXRef(xrefStms[i]);
       }
       // finding main trailer
+      var dict;
       for (var i = 0; i < trailers.length; ++i) {
         stream.pos = trailers[i];
         var parser = new Parser(new Lexer(stream), true);
@@ -3318,13 +3319,15 @@ var XRef = (function xRefXRef() {
         if (!isCmd(obj, 'trailer'))
           continue;
         // read the trailer dictionary
-        var dict;
         if (!isDict(dict = parser.getObj()))
           continue;
         // taking the first one with 'ID'
         if (dict.has('ID'))
           return dict;
       }
+      // no tailer with 'ID', taking last one (if exists)
+      if (dict)
+        return dict;
       // nothing helps
       error('Invalid PDF structure');
       return null;
@@ -4595,7 +4598,7 @@ var PartialEvaluator = (function partialEvaluator() {
         var glyph = differences[i];
         var replaceGlyph = true;
         if (!glyph) {
-          glyph = baseEncoding[i];
+          glyph = baseEncoding[i] || i;
           replaceGlyph = false;
         }
         var index = GlyphsUnicode[glyph] || i;
@@ -4605,7 +4608,7 @@ var PartialEvaluator = (function partialEvaluator() {
           width: isNum(width) ? width : properties.defaultWidth
         };
 
-        if (glyph && (replaceGlyph || !glyphs[glyph]))
+        if (replaceGlyph || !glyphs[glyph])
             glyphs[glyph] = map[i];
 
         // If there is no file, the character mapping can't be modified
diff --git a/test/pdfs/usmanm-bad.pdf.link b/test/pdfs/usmanm-bad.pdf.link
new file mode 100644 (file)
index 0000000..f7ebc36
--- /dev/null
@@ -0,0 +1 @@
+http://www.mit.edu/~6.033/writing-samples/usmanm_dp1.pdf
index f074c06c375e50085322c68b35fa8090f7be461a..15771438cd41493b3d27160618de782d77c06486 100644 (file)
        "rounds": 1,
        "type": "load"
     },
+    {  "id": "usmanm-bad",
+       "file": "pdfs/usmanm-bad.pdf",
+       "link": true,
+       "rounds": 1,
+       "type": "eq"
+    },
     {  "id": "vesta-bad",
        "file": "pdfs/vesta.pdf",
        "link": true,