1
0
Fork 0
mirror of https://github.com/mozilla/pdf.js.git synced 2025-04-22 16:18:08 +02:00

Remove the limit used to decided if a group canvas must be upscaled or not

It fixes issues #14982 and #14724.
The main problem of upscaling a canvas is that it can induces some pixelation
(see issue #14724). So this patch is just removing the limit and as a side
effect it fixes issue #14982.
As far as I can tell, in looking different profiles (especially some memory profile)
in using the Firefox profiler, I don't see any noticeable difference in term of
memory use.
This commit is contained in:
Calixte Denizet 2024-05-01 18:01:50 +02:00
parent 96ce111e0c
commit 5c771628de
4 changed files with 22 additions and 17 deletions

View file

@ -45,7 +45,6 @@ import { convertBlackAndWhiteToRGBA } from "../shared/image_utils.js";
const MIN_FONT_SIZE = 16;
// Maximum font size that would be used during canvas fillText operations.
const MAX_FONT_SIZE = 100;
const MAX_GROUP_SIZE = 4096;
// Defines the time the `executeOperatorList`-method is going to be executing
// before it stops and schedules a continue of execution.
@ -2553,18 +2552,8 @@ class CanvasGraphics {
// too small and make the canvas at least 1x1 pixels.
const offsetX = Math.floor(bounds[0]);
const offsetY = Math.floor(bounds[1]);
let drawnWidth = Math.max(Math.ceil(bounds[2]) - offsetX, 1);
let drawnHeight = Math.max(Math.ceil(bounds[3]) - offsetY, 1);
let scaleX = 1,
scaleY = 1;
if (drawnWidth > MAX_GROUP_SIZE) {
scaleX = drawnWidth / MAX_GROUP_SIZE;
drawnWidth = MAX_GROUP_SIZE;
}
if (drawnHeight > MAX_GROUP_SIZE) {
scaleY = drawnHeight / MAX_GROUP_SIZE;
drawnHeight = MAX_GROUP_SIZE;
}
const drawnWidth = Math.max(Math.ceil(bounds[2]) - offsetX, 1);
const drawnHeight = Math.max(Math.ceil(bounds[3]) - offsetY, 1);
this.current.startNewPathAndClipBox([0, 0, drawnWidth, drawnHeight]);
@ -2582,7 +2571,6 @@ class CanvasGraphics {
// Since we created a new canvas that is just the size of the bounding box
// we have to translate the group ctx.
groupCtx.scale(1 / scaleX, 1 / scaleY);
groupCtx.translate(-offsetX, -offsetY);
groupCtx.transform(...currentTransform);
@ -2593,8 +2581,6 @@ class CanvasGraphics {
context: groupCtx,
offsetX,
offsetY,
scaleX,
scaleY,
subtype: group.smask.subtype,
backdrop: group.smask.backdrop,
transferMap: group.smask.transferMap || null,
@ -2605,7 +2591,6 @@ class CanvasGraphics {
// right location.
currentCtx.setTransform(1, 0, 0, 1, 0, 0);
currentCtx.translate(offsetX, offsetY);
currentCtx.scale(scaleX, scaleY);
currentCtx.save();
}
// The transparency group inherits all off the current graphics state