diff --git a/src/display/pattern_helper.js b/src/display/pattern_helper.js index 0bfca2f5f..e73deb33c 100644 --- a/src/display/pattern_helper.js +++ b/src/display/pattern_helper.js @@ -596,15 +596,17 @@ class TilingPattern { // Converts clippedBBox from device space to pattern space and stores it // as [width, height, offsetX, offsetY] in dims. updatePatternDims(clippedBBox, dims) { - const inv = Util.inverseTransform(this.patternBaseMatrix); - const c1 = [clippedBBox[0], clippedBBox[1]]; - const c2 = [clippedBBox[2], clippedBBox[3]]; - Util.applyTransform(c1, inv); - Util.applyTransform(c2, inv); - dims[0] = Math.abs(c2[0] - c1[0]); - dims[1] = Math.abs(c2[1] - c1[1]); - dims[2] = Math.min(c1[0], c2[0]); - dims[3] = Math.min(c1[1], c2[1]); + // Two diagonal corners aren't enough when the pattern matrix is rotated. + const bbox = [Infinity, Infinity, -Infinity, -Infinity]; + Util.axialAlignedBoundingBox( + clippedBBox, + Util.inverseTransform(this.patternBaseMatrix), + bbox + ); + dims[0] = bbox[2] - bbox[0]; + dims[1] = bbox[3] - bbox[1]; + dims[2] = bbox[0]; + dims[3] = bbox[1]; } // Renders the tile operators onto a fresh canvas and returns it. diff --git a/test/pdfs/.gitignore b/test/pdfs/.gitignore index b2c15053a..a427e1a53 100644 --- a/test/pdfs/.gitignore +++ b/test/pdfs/.gitignore @@ -954,3 +954,4 @@ !bug1898053_minimal.pdf !bug2055455.pdf !issue20294_reduced.pdf +!issue21878.pdf diff --git a/test/pdfs/issue21878.pdf b/test/pdfs/issue21878.pdf new file mode 100644 index 000000000..79be9a4fb Binary files /dev/null and b/test/pdfs/issue21878.pdf differ diff --git a/test/test_manifest.json b/test/test_manifest.json index 9ad51e84d..b124f3f7d 100644 --- a/test/test_manifest.json +++ b/test/test_manifest.json @@ -14540,5 +14540,12 @@ "md5": "29bdb56f4249dc642556c36ecb8de22b", "rounds": 1, "type": "eq" + }, + { + "id": "issue21878", + "file": "pdfs/issue21878.pdf", + "md5": "0ab77bc45682d06b55499b95b42f907d", + "rounds": 1, + "type": "eq" } ]