From 78d0d269dc6cd55494834bfe79649f2c93a33b8f Mon Sep 17 00:00:00 2001 From: Jonas Jenwald Date: Sun, 30 Nov 2014 21:15:18 +0100 Subject: [PATCH] Fallback to the |Dummy| Pattern when we fail to parse a Shading Pattern (issue 5509) --- src/core/pattern.js | 37 ++++++++++++++++++++++-------------- test/pdfs/issue5509.pdf.link | 1 + test/test_manifest.json | 9 +++++++++ 3 files changed, 33 insertions(+), 14 deletions(-) create mode 100644 test/pdfs/issue5509.pdf.link diff --git a/src/core/pattern.js b/src/core/pattern.js index 2bb9c72b8..b769f2263 100644 --- a/src/core/pattern.js +++ b/src/core/pattern.js @@ -15,7 +15,8 @@ * limitations under the License. */ /* globals ColorSpace, PDFFunction, Util, error, warn, info, isArray, isStream, - assert, isPDFFunction, UnsupportedManager, UNSUPPORTED_FEATURES */ + assert, isPDFFunction, UnsupportedManager, UNSUPPORTED_FEATURES, + MissingDataException */ 'use strict'; @@ -49,19 +50,27 @@ var Pattern = (function PatternClosure() { var dict = isStream(shading) ? shading.dict : shading; var type = dict.get('ShadingType'); - switch (type) { - case PatternType.AXIAL: - case PatternType.RADIAL: - // Both radial and axial shadings are handled by RadialAxial shading. - return new Shadings.RadialAxial(dict, matrix, xref, res); - case PatternType.FREE_FORM_MESH: - case PatternType.LATTICE_FORM_MESH: - case PatternType.COONS_PATCH_MESH: - case PatternType.TENSOR_PATCH_MESH: - return new Shadings.Mesh(shading, matrix, xref, res); - default: - UnsupportedManager.notify(UNSUPPORTED_FEATURES.shadingPattern); - return new Shadings.Dummy(); + try { + switch (type) { + case PatternType.AXIAL: + case PatternType.RADIAL: + // Both radial and axial shadings are handled by RadialAxial shading. + return new Shadings.RadialAxial(dict, matrix, xref, res); + case PatternType.FREE_FORM_MESH: + case PatternType.LATTICE_FORM_MESH: + case PatternType.COONS_PATCH_MESH: + case PatternType.TENSOR_PATCH_MESH: + return new Shadings.Mesh(shading, matrix, xref, res); + default: + throw new Error('Unknown PatternType: ' + type); + } + } catch (ex) { + if (ex instanceof MissingDataException) { + throw ex; + } + UnsupportedManager.notify(UNSUPPORTED_FEATURES.shadingPattern); + warn(ex); + return new Shadings.Dummy(); } }; return Pattern; diff --git a/test/pdfs/issue5509.pdf.link b/test/pdfs/issue5509.pdf.link new file mode 100644 index 000000000..45aa81036 --- /dev/null +++ b/test/pdfs/issue5509.pdf.link @@ -0,0 +1 @@ +http://web.archive.org/web/20140908142029/http://kieranhealy.org/files/papers/data-visualization.pdf diff --git a/test/test_manifest.json b/test/test_manifest.json index c93a911c9..007187463 100644 --- a/test/test_manifest.json +++ b/test/test_manifest.json @@ -499,6 +499,15 @@ "link": false, "type": "eq" }, + { "id": "issue5509", + "file": "pdfs/issue5509.pdf", + "md5": "1975ef8db7355b1d691bc79d0749574b", + "rounds": 1, + "link": true, + "firstPage": 1, + "lastPage": 1, + "type": "load" + }, { "id": "txt2pdf", "file": "pdfs/txt2pdf.pdf", "md5": "02cefa0f5e8d96313bb05163b2f88c8c",