1
0
Fork 0
mirror of https://github.com/mozilla/pdf.js.git synced 2025-04-22 16:18:08 +02:00

Improving invalid operations syntax recovery (#1466) (see also #589)

This commit is contained in:
Yury Delendik 2012-04-04 11:50:20 -05:00
parent 921c1e82a3
commit 0ca4ca6077
3 changed files with 37 additions and 12 deletions

View 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 + '"');