servo / pathfinder

A fast, practical GPU rasterizer for fonts and vector graphics
Apache License 2.0
3.56k stars 198 forks source link

add reset method for CanvasRenderingContext2D #446

Open colorhook opened 3 years ago

colorhook commented 3 years ago

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"