]> git.parisson.com Git - pdf.js.git/commitdiff
Improving invalid operations syntax recovery (#1466) (see also #589)
authorYury Delendik <ydelendik@mozilla.com>
Wed, 4 Apr 2012 16:50:20 +0000 (11:50 -0500)
committerYury Delendik <ydelendik@mozilla.com>
Wed, 4 Apr 2012 16:50:20 +0000 (11:50 -0500)
src/evaluator.js
test/pdfs/issue1466.pdf.link [new file with mode: 0644]
test/test_manifest.json

index 05be3511cbde530983a21aa740347341dd9ffecc..bb542b7d2e03328813f919533ae78fd0fa9699f5 100644 (file)
@@ -111,6 +111,17 @@ var PartialEvaluator = (function PartialEvaluatorClosure() {
     EX: 'endCompat'
   };
 
+  function splitCombinedOperations(operations) {
+    // Two operations can be combined together, trying to find which two
+    // operations were concatenated.
+    for (var i = operations.length - 1; i > 0; i--) {
+      var op1 = operations.substring(0, i), op2 = operations.substring(i);
+      if (op1 in OP_MAP && op2 in OP_MAP)
+        return [op1, op2]; // operations found
+    }
+    return null;
+  }
+
   PartialEvaluator.prototype = {
     getOperatorList: function partialEvaluatorGetOperatorList(stream, resources,
                                                       dependency, queue) {
@@ -255,26 +266,32 @@ var PartialEvaluator = (function PartialEvaluatorClosure() {
       var patterns = xref.fetchIfRef(resources.get('Pattern')) || new Dict();
       var parser = new Parser(new Lexer(stream), false);
       var res = resources;
+      var hasNextObj = false, nextObj;
       var args = [], obj;
-      var getObjBt = function getObjBt() {
-        parser = this.oldParser;
-        return { name: 'BT' };
-      };
       var TILING_PATTERN = 1, SHADING_PATTERN = 2;
 
-      while (!isEOF(obj = parser.getObj())) {
+      while (true) {
+        if (hasNextObj) {
+          obj = nextObj;
+          hasNextObj = false;
+        } else {
+          obj = parser.getObj();
+          if (isEOF(obj))
+            break;
+        }
+
         if (isCmd(obj)) {
           var cmd = obj.cmd;
           var fn = OP_MAP[cmd];
           if (!fn) {
             // invalid content command, trying to recover
-            if (cmd.substr(-2) == 'BT') {
-              fn = OP_MAP[cmd.substr(0, cmd.length - 2)];
-              // feeding 'BT' on next interation
-              parser = {
-                getObj: getObjBt,
-                oldParser: parser
-              };
+            var cmds = splitCombinedOperations(cmd);
+            if (cmds) {
+              cmd = cmds[0];
+              fn = OP_MAP[cmd];
+              // feeding other command on the next interation
+              hasNextObj = true;
+              nextObj = Cmd.get(cmds[1]);
             }
           }
           assertWellFormed(fn, 'Unknown command "' + cmd + '"');
diff --git a/test/pdfs/issue1466.pdf.link b/test/pdfs/issue1466.pdf.link
new file mode 100644 (file)
index 0000000..22ebf7e
--- /dev/null
@@ -0,0 +1 @@
+http://web.missouri.edu/~fanxud/publications/On%20the%20performance%20quantification%20of%20resonant%20refractive%20index%20sensors.pdf
index a4c6defccd9325f2d364d2541384a5c91dfd6950..7d290d6184165289669c1a888f4033e6f5dc8c1e 100644 (file)
       "link": true,
       "type": "eq"
     },
+    {  "id": "issue1466",
+      "file": "pdfs/issue1466.pdf",
+      "md5": "8a8877432e5bb10cfd50d60488d947bb",
+      "rounds": 1,
+      "link": true,
+      "type": "eq"
+    },
     {  "id": "issue1133",
       "file": "pdfs/issue1133.pdf",
       "md5": "d1b61580cb100e3df93d33703af1773a",