diff --git a/src/core/evaluator.js b/src/core/evaluator.js index 044cc7c1f..0a3a5df82 100644 --- a/src/core/evaluator.js +++ b/src/core/evaluator.js @@ -151,17 +151,19 @@ var PartialEvaluator = (function PartialEvaluatorClosure() { processed[resources.objId] = true; } - var nodes = [resources]; + var nodes = [resources], xref = this.xref; while (nodes.length) { - var key; + var key, i, ii; var node = nodes.shift(); // First check the current resources for blend modes. var graphicStates = node.get('ExtGState'); if (isDict(graphicStates)) { - graphicStates = graphicStates.getAll(); - for (key in graphicStates) { - var graphicState = graphicStates[key]; - var bm = graphicState['BM']; + var graphicStatesKeys = graphicStates.getKeys(); + for (i = 0, ii = graphicStatesKeys.length; i < ii; i++) { + key = graphicStatesKeys[i]; + + var graphicState = graphicStates.get(key); + var bm = graphicState.get('BM'); if (isName(bm) && bm.name !== 'Normal') { return true; } @@ -172,9 +174,20 @@ var PartialEvaluator = (function PartialEvaluatorClosure() { if (!isDict(xObjects)) { continue; } - xObjects = xObjects.getAll(); - for (key in xObjects) { - var xObject = xObjects[key]; + var xObjectsKeys = xObjects.getKeys(); + for (i = 0, ii = xObjectsKeys.length; i < ii; i++) { + key = xObjectsKeys[i]; + + var xObject = xObjects.getRaw(key); + if (isRef(xObject)) { + if (processed[xObject.toString()]) { + // The XObject has already been processed, and by avoiding a + // redundant `xref.fetch` we can *significantly* reduce the load + // time for badly generated PDF files (fixes issue6961.pdf). + continue; + } + xObject = xref.fetch(xObject); + } if (!isStream(xObject)) { continue; } diff --git a/test/pdfs/.gitignore b/test/pdfs/.gitignore index 5be1fc3f4..911781e82 100644 --- a/test/pdfs/.gitignore +++ b/test/pdfs/.gitignore @@ -18,6 +18,7 @@ !issue5972.pdf !issue5874.pdf !issue6782.pdf +!issue6961.pdf !filled-background.pdf !ArabicCIDTrueType.pdf !ThuluthFeatures.pdf diff --git a/test/pdfs/issue6961.pdf b/test/pdfs/issue6961.pdf new file mode 100644 index 000000000..b52d54805 Binary files /dev/null and b/test/pdfs/issue6961.pdf differ diff --git a/test/test_manifest.json b/test/test_manifest.json index 249b01805..e796620dc 100644 --- a/test/test_manifest.json +++ b/test/test_manifest.json @@ -2760,5 +2760,13 @@ "md5": "8961cb55149495989a80bf0487e0f076", "rounds": 1, "type": "load" + }, + { "id": "issue6961", + "file": "pdfs/issue6961.pdf", + "md5": "a80e4357a8fda758d96c2c76f2980b03", + "link": false, + "rounds": 1, + "lastPage": 1, + "type": "load" } ]