Skip to content

Commit

Permalink
feat: change canvas render viewBox
Browse files Browse the repository at this point in the history
  • Loading branch information
qq15725 committed Nov 9, 2024
1 parent 074faba commit 8a099c8
Showing 1 changed file with 6 additions and 7 deletions.
13 changes: 6 additions & 7 deletions src/canvas/setupView.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,12 @@ export function setupView(ctx: CanvasRenderingContext2D, pixelRatio: number, bou
const view = ctx.canvas
view.dataset.viewbox = String(`${left} ${top} ${width} ${height}`)
view.dataset.pixelRatio = String(pixelRatio)
view.width = Math.max(1, Math.ceil(width * pixelRatio))
view.height = Math.max(1, Math.ceil(height * pixelRatio))
view.style.marginTop = `${top}px`
view.style.marginLeft = `${left}px`
view.style.width = `${width}px`
view.style.height = `${height}px`
const canvasWidth = width + left
const canvasHeight = height + top
view.width = Math.max(1, Math.ceil(canvasWidth * pixelRatio))
view.height = Math.max(1, Math.ceil(canvasHeight * pixelRatio))
view.style.width = `${canvasWidth}px`
view.style.height = `${canvasHeight}px`
ctx.clearRect(0, 0, ctx.canvas.width, ctx.canvas.height)
ctx.scale(pixelRatio, pixelRatio)
ctx.translate(-left, -top)
}

0 comments on commit 8a099c8

Please sign in to comment.