pathfinder icon indicating copy to clipboard operation
pathfinder copied to clipboard

add reset method for CanvasRenderingContext2D

Open colorhook opened this issue 4 years ago • 0 comments

In Web Browsers, If width or height of a Canvas reassigned, even the value not changed, the canvas would reset it's state, includes state stack and current properties.

var canvas = new OffscreenCanvas(100, 100);
var ctx = canvas.getContext('2d')
ctx.font = 'menu'
console.log(ctx.font) // "16px Arial"
ctx.fillStyle = "red"
console.log(ctx.fillStyle) // "#ff0000"

// reassign width or height, the context state should reset to initial value
canvas.width = canvas.width
console.log(ctx.font) // "10px sans-serif"
console.log(ctx.fillStyle) // "#000000"

colorhook avatar Nov 05 '20 02:11 colorhook