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