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

Use the round CSS function in the setLayerDimensions helper function #16794

Merged
merged 1 commit into from
Aug 6, 2023
Merged
Show file tree
Hide file tree
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
14 changes: 6 additions & 8 deletions src/display/display_utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -967,6 +967,8 @@ function getCurrentTransformInverse(ctx) {
return [a, b, c, d, e, f];
}

const useRound = globalThis.CSS?.supports?.("width: round(1.5px, 1px)");

/**
* @param {HTMLDivElement} div
* @param {PageViewport} viewport
Expand All @@ -983,14 +985,10 @@ function setLayerDimensions(
const { pageWidth, pageHeight } = viewport.rawDims;
const { style } = div;

// TODO: Investigate if it could be interesting to use the css round
// function (https://developer.mozilla.org/en-US/docs/Web/CSS/round):
// const widthStr =
// `round(down, var(--scale-factor) * ${pageWidth}px, 1px)`;
// const heightStr =
// `round(down, var(--scale-factor) * ${pageHeight}px, 1px)`;
const widthStr = `calc(var(--scale-factor) * ${pageWidth}px)`;
const heightStr = `calc(var(--scale-factor) * ${pageHeight}px)`;
const w = `var(--scale-factor) * ${pageWidth}px`,
h = `var(--scale-factor) * ${pageHeight}px`;
const widthStr = useRound ? `round(${w}, 1px)` : `calc(${w})`,
heightStr = useRound ? `round(${h}, 1px)` : `calc(${h})`;

if (!mustFlip || viewport.rotation % 180 === 0) {
style.width = widthStr;
Expand Down
2 changes: 2 additions & 0 deletions test/test.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -945,6 +945,8 @@ async function startBrowser(browserName, startUrl = "") {
"gfx.offscreencanvas.enabled": true,
// Disable gpu acceleration
"gfx.canvas.accelerated": false,
// Enable the `round` CSS function.
"layout.css.round.enabled": true,
};
}

Expand Down