Changing the canvas dimensions also resets the context. You'll need to set the font again (and any other non-default settings) after the resize.
tCtx.font = 'bold 24px serif';
tCtx.canvas.width = tCtx.measureText(this.value).width;
tCtx.font = 'bold 24px serif';
tCtx.fillText(this.value, 0, 10);
Saved states (via .save()
/.restore()
) are also lost on a resize. If you expect to have a number of changes to the canvas state, you may want to break these out into your own .save()
/.restore()
functions.
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…