mirror of
https://github.com/photonstorm/phaser
synced 2024-11-24 21:53:59 +00:00
Merge pull request #6916 from rexrainbow/bug-text-measure-width
Fix rendering bug when using letterSpacing
This commit is contained in:
commit
2d01f5d3ae
1 changed files with 17 additions and 4 deletions
|
@ -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
|
||||
|
|
Loading…
Reference in a new issue