Merge pull request #6916 from rexrainbow/bug-text-measure-width

Fix rendering bug when using letterSpacing
This commit is contained in:
Richard Davey 2024-10-10 16:24:13 +01:00 committed by GitHub
commit 2d01f5d3ae
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -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 += text.letterSpacing * (lines[i].length - 1);
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;
}
if (line.length > 1)
{
lineWidth += letterSpacing * (line.length - 1);
}
}
// Adjust for wrapped text