From 0105a20afef0928fc0ec112c99836e503a7e14e5 Mon Sep 17 00:00:00 2001 From: Rex Date: Mon, 7 Oct 2024 13:29:15 +0800 Subject: [PATCH 1/3] 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 From 03ce4cecad1f4bf11f48959d4d1ed8acc91dac76 Mon Sep 17 00:00:00 2001 From: Rex Date: Mon, 7 Oct 2024 20:39:28 +0800 Subject: [PATCH 2/3] Twist logic --- src/gameobjects/text/GetTextSize.js | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/src/gameobjects/text/GetTextSize.js b/src/gameobjects/text/GetTextSize.js index 22ac351cde..f1199174fe 100644 --- a/src/gameobjects/text/GetTextSize.js +++ b/src/gameobjects/text/GetTextSize.js @@ -34,26 +34,26 @@ var GetTextSize = function (text, size, lines) style.syncFont(canvas, context); // Text Width + var letterSpacing = text.letterSpacing; for (var i = 0; i < drawnLines; i++) { var lineWidth = style.strokeThickness; - if (text.letterSpacing === 0) + if (letterSpacing === 0) { lineWidth += context.measureText(lines[i]).width; } else { var line = lines[i]; + for(var j=0; j< line.length; j++) { - lineWidth += context.measureText(line[j]).width + text.letterSpacing; + lineWidth += context.measureText(line[j]).width; } - if (line.length > 0) - { - lineWidth -= text.letterSpacing; - } + + lineWidth += letterSpacing * (line.length - 1); } // Adjust for wrapped text From cbca9ecf1f16000d550634836e2e596dd47d6d25 Mon Sep 17 00:00:00 2001 From: Rex Date: Tue, 8 Oct 2024 05:56:33 +0800 Subject: [PATCH 3/3] Fix bug --- src/gameobjects/text/GetTextSize.js | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/gameobjects/text/GetTextSize.js b/src/gameobjects/text/GetTextSize.js index f1199174fe..26d5b017df 100644 --- a/src/gameobjects/text/GetTextSize.js +++ b/src/gameobjects/text/GetTextSize.js @@ -53,7 +53,10 @@ var GetTextSize = function (text, size, lines) lineWidth += context.measureText(line[j]).width; } - lineWidth += letterSpacing * (line.length - 1); + if (line.length > 1) + { + lineWidth += letterSpacing * (line.length - 1); + } } // Adjust for wrapped text