Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Always enable smoothing when rendering downscaled image #17868

Merged
merged 1 commit into from
Apr 24, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 9 additions & 9 deletions src/display/canvas.js
Original file line number Diff line number Diff line change
Expand Up @@ -913,6 +913,14 @@ function composeSMask(ctx, smask, layerCtx, layerBox) {
}

function getImageSmoothingEnabled(transform, interpolate) {
// In section 8.9.5.3 of the PDF spec, it's mentioned that the interpolate
// flag should be used when the image is upscaled.
// In Firefox, smoothing is always used when downscaling images (bug 1360415).
timvandermeij marked this conversation as resolved.
Show resolved Hide resolved

if (interpolate) {
return true;
}

const scale = Util.singularValueDecompose2dScale(transform);
// Round to a 32bit float so that `<=` check below will pass for numbers that
// are very close, but not exactly the same 64bit floats.
Expand All @@ -921,15 +929,7 @@ function getImageSmoothingEnabled(transform, interpolate) {
const actualScale = Math.fround(
(globalThis.devicePixelRatio || 1) * PixelsPerInch.PDF_TO_CSS_UNITS
);
if (interpolate !== undefined) {
// If the value is explicitly set use it.
return interpolate;
} else if (scale[0] <= actualScale || scale[1] <= actualScale) {
// Smooth when downscaling.
return true;
}
// Don't smooth when upscaling.
return false;
return scale[0] <= actualScale && scale[1] <= actualScale;
calixteman marked this conversation as resolved.
Show resolved Hide resolved
}

const LINE_CAP_STYLES = ["butt", "round", "square"];
Expand Down