Skip to content

Commit 6061094

Browse files
authored
Merge pull request #99 from WICG/progers-add-highdpi-scaling-snippet
Add high-dpi snippet to basic example
2 parents eb42993 + b93d4fd commit 6061094

1 file changed

Lines changed: 7 additions & 0 deletions

File tree

README.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,13 @@ The transform used to draw the element on the worker thread needs to be synced b
8989
let transform = ctx.drawElementImage(form_element, 0, 0);
9090
form_element.style.transform = transform.toString();
9191
};
92+
93+
// Size the canvas grid to match the device scale factor to prevent blurriness.
94+
const observer = new ResizeObserver(([entry]) => {
95+
canvas.width = entry.devicePixelContentBoxSize[0].inlineSize;
96+
canvas.height = entry.devicePixelContentBoxSize[0].blockSize;
97+
});
98+
observer.observe(canvas, {box: 'device-pixel-content-box'});
9299
</script>
93100
```
94101

0 commit comments

Comments
 (0)