Skip to content

Commit

Permalink
fix: correct clearCanvas method to handle devicePixelRatio scaling
Browse files Browse the repository at this point in the history
  • Loading branch information
zhensherlock committed Sep 28, 2024
1 parent b99ba1e commit fdd176e
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 0 deletions.
5 changes: 5 additions & 0 deletions .changeset/eight-bobcats-reply.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@watermark-design/core': patch
---

fix correct clearCanvas method to handle devicePixelRatio scaling
3 changes: 3 additions & 0 deletions packages/core/src/watermark-canvas.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,10 @@ class WatermarkCanvas {
throw new Error('get context error');
}
ctx.restore();
ctx.resetTransform();
ctx.clearRect(0, 0, canvas.width, canvas.height);
const ratio = window.devicePixelRatio || 1;
ctx.setTransform(ratio, 0, 0, ratio, 0, 0);
}

getCanvas(): HTMLCanvasElement {
Expand Down

0 comments on commit fdd176e

Please sign in to comment.