Skip to content

Commit

Permalink
Avoid to have a white line around the canvas
Browse files Browse the repository at this point in the history
  • Loading branch information
calixteman committed Sep 5, 2024
1 parent 4b906ad commit d48d0a2
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 7 deletions.
4 changes: 2 additions & 2 deletions src/display/display_utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -1103,8 +1103,8 @@ function setLayerDimensions(

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})`;
const widthStr = useRound ? `round(down, ${w}, 1px)` : `calc(${w})`,
heightStr = useRound ? `round(down, ${h}, 1px)` : `calc(${h})`;

if (!mustFlip || viewport.rotation % 180 === 0) {
style.width = widthStr;
Expand Down
15 changes: 10 additions & 5 deletions web/pdf_page_view.js
Original file line number Diff line number Diff line change
Expand Up @@ -1036,11 +1036,16 @@ class PDFPageView {
const sfx = approximateFraction(outputScale.sx);
const sfy = approximateFraction(outputScale.sy);

canvas.width = floorToDivide(width * outputScale.sx, sfx[0]);
canvas.height = floorToDivide(height * outputScale.sy, sfy[0]);
const { style } = canvas;
style.width = floorToDivide(width, sfx[1]) + "px";
style.height = floorToDivide(height, sfy[1]) + "px";
const newWidth = (canvas.width = floorToDivide(
width * outputScale.sx,
sfx[0]
));
const newHeight = (canvas.height = floorToDivide(
height * outputScale.sy,
sfy[0]
));
outputScale.sx = newWidth / width;
outputScale.sy = newHeight / height;

// Add the viewport so it's known what it was originally drawn with.
this.#viewportMap.set(canvas, viewport);
Expand Down
2 changes: 2 additions & 0 deletions web/pdf_viewer.css
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,8 @@
canvas {
margin: 0;
display: block;
width: 100%;
height: 100%;

&[hidden] {
display: none;
Expand Down

0 comments on commit d48d0a2

Please sign in to comment.