From 0543f3d2a50f3a3d01fede08b46b84a5f4e54466 Mon Sep 17 00:00:00 2001 From: UnknownShadow200 Date: Sat, 14 May 2022 09:03:26 +1000 Subject: [PATCH] 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 --- src/interop_web.js | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/src/interop_web.js b/src/interop_web.js index e04a17374..c2eb91502 100644 --- a/src/interop_web.js +++ b/src/interop_web.js @@ -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;