mirror of
https://github.com/photonstorm/phaser
synced 2024-11-21 20:23:19 +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);
|
style.syncFont(canvas, context);
|
||||||
|
|
||||||
// Text Width
|
// Text Width
|
||||||
|
var letterSpacing = text.letterSpacing;
|
||||||
|
|
||||||
for (var i = 0; i < drawnLines; i++)
|
for (var i = 0; i < drawnLines; i++)
|
||||||
{
|
{
|
||||||
var lineWidth = style.strokeThickness;
|
var lineWidth = style.strokeThickness;
|
||||||
|
|
||||||
lineWidth += context.measureText(lines[i]).width;
|
if (letterSpacing === 0)
|
||||||
|
|
||||||
if (lines[i].length > 1)
|
|
||||||
{
|
{
|
||||||
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
|
// Adjust for wrapped text
|
||||||
|
|
Loading…
Reference in a new issue