From 0105a20afef0928fc0ec112c99836e503a7e14e5 Mon Sep 17 00:00:00 2001 From: Rex Date: Mon, 7 Oct 2024 13:29:15 +0800 Subject: [PATCH] Fix bug --- src/gameobjects/text/GetTextSize.js | 18 ++++++++++++++---- 1 file changed, 14 insertions(+), 4 deletions(-) diff --git a/src/gameobjects/text/GetTextSize.js b/src/gameobjects/text/GetTextSize.js index 9a05549663..22ac351cde 100644 --- a/src/gameobjects/text/GetTextSize.js +++ b/src/gameobjects/text/GetTextSize.js @@ -39,11 +39,21 @@ var GetTextSize = function (text, size, lines) { var lineWidth = style.strokeThickness; - lineWidth += context.measureText(lines[i]).width; - - if (lines[i].length > 1) + if (text.letterSpacing === 0) + { + lineWidth += context.measureText(lines[i]).width; + } + else { - lineWidth += text.letterSpacing * (lines[i].length - 1); + var line = lines[i]; + for(var j=0; j< line.length; j++) + { + lineWidth += context.measureText(line[j]).width + text.letterSpacing; + } + if (line.length > 0) + { + lineWidth -= text.letterSpacing; + } } // Adjust for wrapped text