Skip to content

Commit 83f06b4

Browse files
Merge pull request #20897 from calixteman/empty_shading
Don't throw when a mesh shading is degenerated
2 parents feea0e2 + 085ab36 commit 83f06b4

5 files changed

Lines changed: 23 additions & 18 deletions

File tree

src/core/pattern.js

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -968,20 +968,13 @@ class MeshShading extends BaseShading {
968968
}
969969

970970
getIR() {
971-
const { bounds } = this;
972-
// Ensure that the shading has non-zero width and height, to prevent errors
973-
// in `pattern_helper.js` (fixes issue17848.pdf).
974-
if (bounds[2] - bounds[0] === 0 || bounds[3] - bounds[1] === 0) {
975-
throw new FormatError(`Invalid MeshShading bounds: [${bounds}].`);
976-
}
977-
978971
return [
979972
"Mesh",
980973
this.shadingType,
981974
this.coords,
982975
this.colors,
983976
this.figures,
984-
bounds,
977+
this.bounds,
985978
this.bbox,
986979
this.background,
987980
];

src/display/pattern_helper.js

Lines changed: 14 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -462,16 +462,20 @@ class MeshShadingPattern extends BaseShadingPattern {
462462
const boundsWidth = Math.ceil(this._bounds[2]) - offsetX;
463463
const boundsHeight = Math.ceil(this._bounds[3]) - offsetY;
464464

465-
const width = Math.min(
466-
Math.ceil(Math.abs(boundsWidth * combinedScale[0] * EXPECTED_SCALE)),
467-
MAX_PATTERN_SIZE
468-
);
469-
const height = Math.min(
470-
Math.ceil(Math.abs(boundsHeight * combinedScale[1] * EXPECTED_SCALE)),
471-
MAX_PATTERN_SIZE
472-
);
473-
const scaleX = boundsWidth / width;
474-
const scaleY = boundsHeight / height;
465+
// Ensure that the shading has non-zero width and height, to prevent errors
466+
// in `pattern_helper.js` (fixes issue17848.pdf).
467+
const width =
468+
Math.min(
469+
Math.ceil(Math.abs(boundsWidth * combinedScale[0] * EXPECTED_SCALE)),
470+
MAX_PATTERN_SIZE
471+
) || 1;
472+
const height =
473+
Math.min(
474+
Math.ceil(Math.abs(boundsHeight * combinedScale[1] * EXPECTED_SCALE)),
475+
MAX_PATTERN_SIZE
476+
) || 1;
477+
const scaleX = boundsWidth ? boundsWidth / width : 1;
478+
const scaleY = boundsHeight ? boundsHeight / height : 1;
475479

476480
const context = {
477481
coords: this._coords,

test/pdfs/.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -884,3 +884,4 @@
884884
!form_two_pages.pdf
885885
!outlines_se.pdf
886886
!radial_gradients.pdf
887+
!mesh_shading_empty.pdf

test/pdfs/mesh_shading_empty.pdf

1.37 KB
Binary file not shown.

test/test_manifest.json

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13998,5 +13998,12 @@
1399813998
"md5": "80e8bed66b83928698f008c33de47edd",
1399913999
"rounds": 1,
1400014000
"type": "eq"
14001+
},
14002+
{
14003+
"id": "mesh_shading_empty",
14004+
"file": "pdfs/mesh_shading_empty.pdf",
14005+
"md5": "5a1bf9cb73010d84b47d91bb66bae27d",
14006+
"rounds": 1,
14007+
"type": "eq"
1400114008
}
1400214009
]

0 commit comments

Comments
 (0)