Skip to content

Commit

Permalink
Merge pull request #6916 from rexrainbow/bug-text-measure-width
Browse files Browse the repository at this point in the history
Fix rendering bug when using letterSpacing
  • Loading branch information
photonstorm authored Oct 10, 2024
2 parents 7988f4d + cbca9ec commit 2d01f5d
Showing 1 changed file with 17 additions and 4 deletions.
21 changes: 17 additions & 4 deletions src/gameobjects/text/GetTextSize.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,16 +34,29 @@ 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;

lineWidth += context.measureText(lines[i]).width;

if (lines[i].length > 1)
if (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;
}

if (line.length > 1)
{
lineWidth += letterSpacing * (line.length - 1);
}
}

// Adjust for wrapped text
Expand Down

0 comments on commit 2d01f5d

Please sign in to comment.