Skip to content

Commit a72a8e9

Browse files
committed
Avoid extreme sizing / scaling in tiling pattern
The new test file (tiling-pattern-large-steps.pdf) was manually created, to have the following characteristics: - Large xstep and ystep (90000) - Page width is 4000 (which is larger than MAX_PATTERN_SIZE) - Visually, the page consists of a red rectangle with a black border, surrounded by a 50 unit white padding. - Before patch: blurry; After patch: sharp Fixes mozilla#6496 Fixes mozilla#5698 Fixes mozilla#1434 Fixes mozilla#2825
1 parent 60d4685 commit a72a8e9

File tree

4 files changed

+25
-5
lines changed

4 files changed

+25
-5
lines changed

src/display/pattern_helper.js

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -342,8 +342,10 @@ var TilingPattern = (function TilingPatternClosure() {
342342
// Use width and height values that are as close as possible to the end
343343
// result when the pattern is used. Too low value makes the pattern look
344344
// blurry. Too large value makes it look too crispy.
345-
var dimx = this.getSizeAndScale(xstep, combinedScale[0]);
346-
var dimy = this.getSizeAndScale(ystep, combinedScale[1]);
345+
var dimx = this.getSizeAndScale(xstep, this.ctx.canvas.width,
346+
combinedScale[0]);
347+
var dimy = this.getSizeAndScale(ystep, this.ctx.canvas.height,
348+
combinedScale[1]);
347349

348350
var tmpCanvas = owner.cachedCanvases.getCanvas('pattern',
349351
dimx.size, dimy.size, true);
@@ -368,12 +370,21 @@ var TilingPattern = (function TilingPatternClosure() {
368370
return tmpCanvas.canvas;
369371
},
370372

371-
getSizeAndScale: function TilingPattern_getSizeAndScale(step, scale) {
373+
getSizeAndScale:
374+
function TilingPattern_getSizeAndScale(step, realOutputSize, scale) {
372375
// xstep / ystep may be negative -- normalize.
373376
step = Math.abs(step);
374377
// MAX_PATTERN_SIZE is used to avoid OOM situation.
375-
var size = Math.min(Math.ceil(step * scale), MAX_PATTERN_SIZE);
376-
scale = size / step;
378+
// Use the destination canvas's size if it is bigger than the hard-coded
379+
// limit of MAX_PATTERN_SIZE to avoid clipping patterns that cover the
380+
// whole canvas.
381+
var maxSize = Math.max(MAX_PATTERN_SIZE, realOutputSize);
382+
var size = Math.ceil(step * scale);
383+
if (size >= maxSize) {
384+
size = maxSize;
385+
} else {
386+
scale = size / step;
387+
}
377388
return { scale, size, };
378389
},
379390

test/pdfs/.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -340,3 +340,4 @@
340340
!issue9972-1.pdf
341341
!issue9972-2.pdf
342342
!issue9972-3.pdf
343+
!tiling-pattern-large-steps.pdf
983 Bytes
Binary file not shown.

test/test_manifest.json

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2996,6 +2996,14 @@
29962996
"link": false,
29972997
"type": "eq"
29982998
},
2999+
{
3000+
"id": "tiling-pattern-large-steps",
3001+
"file": "pdfs/tiling-pattern-large-steps.pdf",
3002+
"md5": "569aac1303c97004aab6a720d9b259b4",
3003+
"rounds": 1,
3004+
"link": false,
3005+
"type": "eq"
3006+
},
29993007
{ "id": "issue6151",
30003008
"file": "pdfs/issue6151.pdf",
30013009
"md5": "926f8c6b25e6f0978759f7947d70e079",

0 commit comments

Comments
 (0)