Two or more operations can be combined together like qqBT
This commit is contained in:
parent
adbe74c7a6
commit
6acdf1791c
@ -112,14 +112,33 @@ var PartialEvaluator = (function PartialEvaluatorClosure() {
|
|||||||
};
|
};
|
||||||
|
|
||||||
function splitCombinedOperations(operations) {
|
function splitCombinedOperations(operations) {
|
||||||
// Two operations can be combined together, trying to find which two
|
// Two or more operations can be combined together, trying to find which
|
||||||
// operations were concatenated.
|
// operations were concatenated.
|
||||||
for (var i = operations.length - 1; i > 0; i--) {
|
var result = [];
|
||||||
var op1 = operations.substring(0, i), op2 = operations.substring(i);
|
var opIndex = 0;
|
||||||
if (op1 in OP_MAP && op2 in OP_MAP)
|
|
||||||
return [op1, op2]; // operations found
|
if (!operations) {
|
||||||
|
return null;
|
||||||
}
|
}
|
||||||
return null;
|
|
||||||
|
while (opIndex < operations.length) {
|
||||||
|
var currentOp = '';
|
||||||
|
for (var op in OP_MAP) {
|
||||||
|
if (op == operations.substr(opIndex, op.length) &&
|
||||||
|
op.length > currentOp.length) {
|
||||||
|
currentOp = op;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (currentOp.length > 0) {
|
||||||
|
result.push(operations.substr(opIndex, currentOp.length));
|
||||||
|
opIndex += currentOp.length;
|
||||||
|
} else {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
PartialEvaluator.prototype = {
|
PartialEvaluator.prototype = {
|
||||||
@ -267,14 +286,14 @@ var PartialEvaluator = (function PartialEvaluatorClosure() {
|
|||||||
var patterns = resources.get('Pattern') || new Dict();
|
var patterns = resources.get('Pattern') || new Dict();
|
||||||
var parser = new Parser(new Lexer(stream), false, xref);
|
var parser = new Parser(new Lexer(stream), false, xref);
|
||||||
var res = resources;
|
var res = resources;
|
||||||
var hasNextObj = false, nextObj;
|
var hasNextObj = false, nextObjs;
|
||||||
var args = [], obj;
|
var args = [], obj;
|
||||||
var TILING_PATTERN = 1, SHADING_PATTERN = 2;
|
var TILING_PATTERN = 1, SHADING_PATTERN = 2;
|
||||||
|
|
||||||
while (true) {
|
while (true) {
|
||||||
if (hasNextObj) {
|
if (hasNextObj) {
|
||||||
obj = nextObj;
|
obj = nextObjs.pop();
|
||||||
hasNextObj = false;
|
hasNextObj = (nextObjs.length > 0);
|
||||||
} else {
|
} else {
|
||||||
obj = parser.getObj();
|
obj = parser.getObj();
|
||||||
if (isEOF(obj))
|
if (isEOF(obj))
|
||||||
@ -290,9 +309,12 @@ var PartialEvaluator = (function PartialEvaluatorClosure() {
|
|||||||
if (cmds) {
|
if (cmds) {
|
||||||
cmd = cmds[0];
|
cmd = cmds[0];
|
||||||
fn = OP_MAP[cmd];
|
fn = OP_MAP[cmd];
|
||||||
// feeding other command on the next interation
|
// feeding other command on the next iteration
|
||||||
hasNextObj = true;
|
hasNextObj = true;
|
||||||
nextObj = Cmd.get(cmds[1]);
|
nextObjs = [];
|
||||||
|
for (var idx = 1; idx < cmds.length; idx++) {
|
||||||
|
nextObjs.push(Cmd.get(cmds[idx]));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
assertWellFormed(fn, 'Unknown command "' + cmd + '"');
|
assertWellFormed(fn, 'Unknown command "' + cmd + '"');
|
||||||
|
Loading…
x
Reference in New Issue
Block a user