diff --git a/src/core/pattern.js b/src/core/pattern.js index 6059fdfcf..62f67618a 100644 --- a/src/core/pattern.js +++ b/src/core/pattern.js @@ -968,20 +968,13 @@ class MeshShading extends BaseShading { } getIR() { - const { bounds } = this; - // Ensure that the shading has non-zero width and height, to prevent errors - // in `pattern_helper.js` (fixes issue17848.pdf). - if (bounds[2] - bounds[0] === 0 || bounds[3] - bounds[1] === 0) { - throw new FormatError(`Invalid MeshShading bounds: [${bounds}].`); - } - return [ "Mesh", this.shadingType, this.coords, this.colors, this.figures, - bounds, + this.bounds, this.bbox, this.background, ]; diff --git a/src/display/pattern_helper.js b/src/display/pattern_helper.js index 5a8da30a5..f66050d1b 100644 --- a/src/display/pattern_helper.js +++ b/src/display/pattern_helper.js @@ -462,16 +462,20 @@ class MeshShadingPattern extends BaseShadingPattern { const boundsWidth = Math.ceil(this._bounds[2]) - offsetX; const boundsHeight = Math.ceil(this._bounds[3]) - offsetY; - const width = Math.min( - Math.ceil(Math.abs(boundsWidth * combinedScale[0] * EXPECTED_SCALE)), - MAX_PATTERN_SIZE - ); - const height = Math.min( - Math.ceil(Math.abs(boundsHeight * combinedScale[1] * EXPECTED_SCALE)), - MAX_PATTERN_SIZE - ); - const scaleX = boundsWidth / width; - const scaleY = boundsHeight / height; + // Ensure that the shading has non-zero width and height, to prevent errors + // in `pattern_helper.js` (fixes issue17848.pdf). + const width = + Math.min( + Math.ceil(Math.abs(boundsWidth * combinedScale[0] * EXPECTED_SCALE)), + MAX_PATTERN_SIZE + ) || 1; + const height = + Math.min( + Math.ceil(Math.abs(boundsHeight * combinedScale[1] * EXPECTED_SCALE)), + MAX_PATTERN_SIZE + ) || 1; + const scaleX = boundsWidth ? boundsWidth / width : 1; + const scaleY = boundsHeight ? boundsHeight / height : 1; const context = { coords: this._coords, diff --git a/test/pdfs/.gitignore b/test/pdfs/.gitignore index 8e4b0a508..bcbcdd68a 100644 --- a/test/pdfs/.gitignore +++ b/test/pdfs/.gitignore @@ -884,3 +884,4 @@ !form_two_pages.pdf !outlines_se.pdf !radial_gradients.pdf +!mesh_shading_empty.pdf diff --git a/test/pdfs/mesh_shading_empty.pdf b/test/pdfs/mesh_shading_empty.pdf new file mode 100644 index 000000000..1bc16ce7e Binary files /dev/null and b/test/pdfs/mesh_shading_empty.pdf differ diff --git a/test/test_manifest.json b/test/test_manifest.json index 96245b451..7dac82e9b 100644 --- a/test/test_manifest.json +++ b/test/test_manifest.json @@ -13998,5 +13998,12 @@ "md5": "80e8bed66b83928698f008c33de47edd", "rounds": 1, "type": "eq" + }, + { + "id": "mesh_shading_empty", + "file": "pdfs/mesh_shading_empty.pdf", + "md5": "5a1bf9cb73010d84b47d91bb66bae27d", + "rounds": 1, + "type": "eq" } ]