Webclient: Fix rare garbage data when drawing system font text

What was happening was that the text drawing would rarely resize the system font drawing canvas to accomodate wider text. However, resizing the canvas also resets the properties of the associated CanvasRenderingContext2D, which hence caused the text to be drawn mostly offcanvas in a smaller font, which hence appeared as 'garbage' at the top of the drawn text in-game
This commit is contained in:
UnknownShadow200 2022-05-14 09:03:26 +10:00
parent 40183b6059
commit 0543f3d2a5

View File

@ -1023,8 +1023,14 @@ mergeInto(LibraryManager.library, {
// resize canvas if necessary so text fits
var data = ctx.measureText(text);
var text_width = Math.ceil(data.width)|0;
if (text_width > ctx.canvas.width)
if (text_width > ctx.canvas.width) {
var font = ctx.font;
ctx.canvas.width = text_width;
// resizing canvas also resets the properties of CanvasRenderingContext2D
ctx.font = font;
ctx.textAlign = 'left';
ctx.textBaseline = 'top';
}
var text_offset = 0.0;
ctx.fillStyle = hex;