Slightly simplify the code in PartialEvaluator.hasBlendModes, e.g. by using for...of loops

- Replace the existing loops with `for...of` variants instead.

 - Make use of `continue`, to reduce indentation and to make the code (slightly) easier to follow, when checking `/Resources` entries.
This commit is contained in:
Jonas Jenwald 2020-07-15 11:51:45 +02:00
parent 15fa3f8518
commit f20aeb9343

View File

@ -249,10 +249,7 @@ class PartialEvaluator {
// First check the current resources for blend modes. // First check the current resources for blend modes.
var graphicStates = node.get("ExtGState"); var graphicStates = node.get("ExtGState");
if (graphicStates instanceof Dict) { if (graphicStates instanceof Dict) {
var graphicStatesKeys = graphicStates.getKeys(); for (const key of graphicStates.getKeys()) {
for (let i = 0, ii = graphicStatesKeys.length; i < ii; i++) {
const key = graphicStatesKeys[i];
let graphicState = graphicStates.getRaw(key); let graphicState = graphicStates.getRaw(key);
if (graphicState instanceof Ref) { if (graphicState instanceof Ref) {
if (processed[graphicState.toString()]) { if (processed[graphicState.toString()]) {
@ -286,8 +283,8 @@ class PartialEvaluator {
continue; continue;
} }
if (bm !== undefined && Array.isArray(bm)) { if (bm !== undefined && Array.isArray(bm)) {
for (let j = 0, jj = bm.length; j < jj; j++) { for (const element of bm) {
if (bm[j] instanceof Name && bm[j].name !== "Normal") { if (element instanceof Name && element.name !== "Normal") {
return true; return true;
} }
} }
@ -299,10 +296,7 @@ class PartialEvaluator {
if (!(xObjects instanceof Dict)) { if (!(xObjects instanceof Dict)) {
continue; continue;
} }
var xObjectsKeys = xObjects.getKeys(); for (const key of xObjects.getKeys()) {
for (let i = 0, ii = xObjectsKeys.length; i < ii; i++) {
const key = xObjectsKeys[i];
var xObject = xObjects.getRaw(key); var xObject = xObjects.getRaw(key);
if (xObject instanceof Ref) { if (xObject instanceof Ref) {
if (processed[xObject.toString()]) { if (processed[xObject.toString()]) {
@ -331,15 +325,17 @@ class PartialEvaluator {
processed[xObject.dict.objId] = true; processed[xObject.dict.objId] = true;
} }
var xResources = xObject.dict.get("Resources"); var xResources = xObject.dict.get("Resources");
if (!(xResources instanceof Dict)) {
continue;
}
// Checking objId to detect an infinite loop. // Checking objId to detect an infinite loop.
if ( if (xResources.objId && processed[xResources.objId]) {
xResources instanceof Dict && continue;
(!xResources.objId || !processed[xResources.objId]) }
) {
nodes.push(xResources); nodes.push(xResources);
if (xResources.objId) { if (xResources.objId) {
processed[xResources.objId] = true; processed[xResources.objId] = true;
}
} }
} }
} }