Don't throw when a mesh shading is degenerated

The problem of throwing an error is that it removes an operation
from drawing list which can cause a rendering issue.
This commit is contained in:
calixteman 2026-03-16 23:19:21 +01:00
parent 394727a28c
commit 085ab36680
No known key found for this signature in database
GPG Key ID: 0C5442631EE0691F
5 changed files with 23 additions and 18 deletions

View File

@ -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,
];

View File

@ -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,

View File

@ -884,3 +884,4 @@
!form_two_pages.pdf
!outlines_se.pdf
!radial_gradients.pdf
!mesh_shading_empty.pdf

Binary file not shown.

View File

@ -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"
}
]