From 21efdc57e73e455943e0f17eb94361350821779b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Attila=20B=C3=A1gyoni?= <10251730+bagyoni@users.noreply.github.com> Date: Sat, 12 Oct 2024 10:22:39 +0200 Subject: [PATCH 1/2] Remove dead code in GetBitmapTextSize --- .../bitmaptext/GetBitmapTextSize.js | 71 ------------------- 1 file changed, 71 deletions(-) diff --git a/src/gameobjects/bitmaptext/GetBitmapTextSize.js b/src/gameobjects/bitmaptext/GetBitmapTextSize.js index ba14d2968..839efeb8a 100644 --- a/src/gameobjects/bitmaptext/GetBitmapTextSize.js +++ b/src/gameobjects/bitmaptext/GetBitmapTextSize.js @@ -176,80 +176,9 @@ var GetBitmapTextSize = function (src, round, updateOrigin, out) text = wrappedLines.join('\n'); - // Loop through the words array and see if we've got any > maxWidth - var prev; - var offset = 0; - var crs = []; - - for (i = 0; i < words.length; i++) - { - var entry = words[i]; - var left = entry.x; - var right = entry.x + entry.w; - - if (left === 0) - { - offset = 0; - prev = null; - } - - if (prev) - { - var diff = left - (prev.x + prev.w); - - offset = left - (diff + prev.w); - - prev = null; - } - - var checkLeft = left - offset; - var checkRight = right - offset; - - if (checkLeft > maxWidth || checkRight > maxWidth) - { - crs.push(entry.i - 1); - - if (entry.cr) - { - crs.push(entry.i + entry.word.length); - - offset = 0; - prev = null; - } - else - { - prev = entry; - } - } - else if (entry.cr) - { - crs.push(entry.i + entry.word.length); - - offset = 0; - prev = null; - } - } - - var stringInsert = function (str, index, value) - { - return str.substr(0, index) + value + str.substr(index + 1); - }; - - for (i = crs.length - 1; i >= 0; i--) - { - if (crs[i] > -1) - { - text = stringInsert(text, crs[i], '\n'); - } - } - out.wrappedText = text; textLength = text.length; - - // Recalculated in the next loop - words = []; - current = null; } var charIndex = 0; From 95254316b39fde0006e79f8fff762a12ac9452c0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Attila=20B=C3=A1gyoni?= <10251730+bagyoni@users.noreply.github.com> Date: Sat, 12 Oct 2024 10:39:02 +0200 Subject: [PATCH 2/2] Fix calculation of idx in GetBitmapTextSize --- src/gameobjects/bitmaptext/GetBitmapTextSize.js | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/gameobjects/bitmaptext/GetBitmapTextSize.js b/src/gameobjects/bitmaptext/GetBitmapTextSize.js index 839efeb8a..6876a294c 100644 --- a/src/gameobjects/bitmaptext/GetBitmapTextSize.js +++ b/src/gameobjects/bitmaptext/GetBitmapTextSize.js @@ -162,6 +162,8 @@ var GetBitmapTextSize = function (src, round, updateOrigin, out) else { // If the current word is too long to fit on a line, wrap it + // Remove trailing word wrap char to keep text length the same + wrappedLine = wrappedLine.slice(0, -1); wrappedLine += (wrappedLine ? '\n' : '') + lineToCheck; lineToCheck = word; } @@ -170,6 +172,7 @@ var GetBitmapTextSize = function (src, round, updateOrigin, out) } } + wrappedLine = wrappedLine.slice(0, -1); wrappedLine += (wrappedLine ? '\n' : '') + lineToCheck; wrappedLines.push(wrappedLine); }