Skip to content

Conversation

colorhook
Copy link

@colorhook colorhook commented Nov 5, 2020

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"

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant