Combine if/else block with switch for getOperatorList.

This commit is contained in:
Brendan Dahl 2013-11-18 16:50:58 -08:00
parent f88e0b51c2
commit a4f329aa38

View File

@ -540,7 +540,6 @@ var PartialEvaluator = (function PartialEvaluatorClosure() {
var promise = new Promise();
var args = [];
nextOp:
while (true) {
var obj = parser.getObj();
@ -584,8 +583,12 @@ var PartialEvaluator = (function PartialEvaluatorClosure() {
// TODO figure out how to type-check vararg functions
if ((cmd == 'SCN' || cmd == 'scn') &&
!args[args.length - 1].code) {
switch (fn) {
case OPS.setStrokeColorN:
case OPS.setFillColorN:
if (args[args.length - 1].code) {
break;
}
// compile tiling patterns
var patternName = args[args.length - 1];
// SCN/scn applies patterns along with normal colors
@ -611,7 +614,11 @@ var PartialEvaluator = (function PartialEvaluatorClosure() {
error('Unkown PatternType ' + typeNum);
}
}
} else if (cmd == 'Do' && !args[0].code) {
break;
case OPS.paintXObject:
if (args[0].code) {
break;
}
// eagerly compile XForm objects
var name = args[0].name;
var xobj = xobjs.get(name);
@ -638,28 +645,34 @@ var PartialEvaluator = (function PartialEvaluatorClosure() {
error('Unhandled XObject subtype ' + type.name);
}
}
} else if (cmd == 'Tf') { // eagerly collect all fonts
break;
case OPS.setFont:
// eagerly collect all fonts
var loadedName = self.handleSetFont(resources, args, null,
operatorList);
operatorList.addDependency(loadedName);
fn = OPS.setFont;
args[0] = loadedName;
} else if (cmd == 'EI') {
self.buildPaintImageXObject(resources, args[0], true, operatorList);
break;
case OPS.endInlineImage:
self.buildPaintImageXObject(resources, args[0], true,
operatorList);
args = [];
continue;
} else if (cmd === 'q') { // save
case OPS.save:
var old = this.state;
this.stateStack.push(this.state);
this.state = old.clone();
} else if (cmd === 'Q') { // restore
break;
case OPS.restore:
var prev = this.stateStack.pop();
if (prev) {
this.state = prev;
}
} else if (cmd === 'Tj') { // showText
break;
case OPS.showText:
args[0] = this.handleText(args[0]);
} else if (cmd === 'TJ') { // showSpacedText
break;
case OPS.showSpacedText:
var arr = args[0];
var arrLength = arr.length;
for (var i = 0; i < arrLength; ++i) {
@ -667,15 +680,16 @@ var PartialEvaluator = (function PartialEvaluatorClosure() {
arr[i] = this.handleText(arr[i]);
}
}
} else if (cmd === '\'') { // nextLineShowText
break;
case OPS.nextLineShowText:
args[0] = this.handleText(args[0]);
} else if (cmd === '"') { // nextLineSetSpacingShowText
break;
case OPS.nextLineSetSpacingShowText:
args[2] = this.handleText(args[2]);
} else if (cmd === 'Tr') { // setTextRenderingMode
break;
case OPS.setTextRenderingMode:
this.state.textRenderingMode = args[0];
}
switch (fn) {
break;
// Parse the ColorSpace data to a raw format.
case OPS.setFillColorSpace:
case OPS.setStrokeColorSpace:
@ -706,7 +720,7 @@ var PartialEvaluator = (function PartialEvaluatorClosure() {
var gState = extGState.get(dictName.name);
self.setGState(resources, gState, operatorList);
args = [];
continue nextOp;
continue;
} // switch
operatorList.addOp(fn, args);