Skip to content

Commit c2365d4

Browse files
committed
Compute logical size from acutal physical sizes
1 parent d56017a commit c2365d4

File tree

1 file changed

+4
-4
lines changed

1 file changed

+4
-4
lines changed

frontend/src/utility-functions/viewports.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -32,17 +32,17 @@ export function setupViewportResizeObserver(editor: Editor) {
3232
physicalHeight = entry.contentBoxSize[0].blockSize * devicePixelRatio;
3333
}
3434

35-
// Get logical dimensions from contentBoxSize (these may be fractional pixels)
36-
const logicalWidth = entry.contentBoxSize[0].inlineSize;
37-
const logicalHeight = entry.contentBoxSize[0].blockSize;
35+
// Compute the logical size which corresponds to the physical size
36+
const logicalWidth = physicalWidth / devicePixelRatio;
37+
const logicalHeight = physicalHeight / devicePixelRatio;
3838

3939
// Get viewport position
4040
const bounds = entry.target.getBoundingClientRect();
4141

4242
const scale = physicalWidth / logicalWidth;
4343

44-
// Send both logical and physical dimensions to the backend
4544
// Logical dimensions are used for CSS/SVG sizing, physical for GPU textures
45+
// TODO: Consider passing physical sizes as well to eliminate pixel inaccuracies since width and height could be rounded differently
4646
editor.handle.updateViewport(bounds.x, bounds.y, logicalWidth, logicalHeight, scale);
4747
}
4848
});

0 commit comments

Comments
 (0)