mirror of
https://github.com/photonstorm/phaser
synced 2024-11-26 22:52:14 +00:00
Don't add white space at last word of a line
This commit is contained in:
parent
467aac2308
commit
3c4cf8834e
1 changed files with 18 additions and 14 deletions
|
@ -508,16 +508,20 @@ var Text = new Class({
|
|||
{
|
||||
var result = '';
|
||||
var lines = text.split(this.splitRegExp);
|
||||
var lastLineIndex = lines.length - 1;
|
||||
var whiteSpaceWidth = context.measureText(' ').width;
|
||||
|
||||
for (var i = 0; i < lines.length; i++)
|
||||
for (var i = 0; i <= lastLineIndex; i++)
|
||||
{
|
||||
var spaceLeft = wordWrapWidth;
|
||||
var words = lines[i].split(' ');
|
||||
var lastWordIndex = words.length - 1;
|
||||
|
||||
for (var j = 0; j < words.length; j++)
|
||||
for (var j = 0; j <= lastWordIndex; j++)
|
||||
{
|
||||
var wordWidth = context.measureText(words[j]).width;
|
||||
var wordWidthWithSpace = wordWidth + context.measureText(' ').width;
|
||||
var word = words[j];
|
||||
var wordWidth = context.measureText(word).width;
|
||||
var wordWidthWithSpace = wordWidth + whiteSpaceWidth;
|
||||
|
||||
if (wordWidthWithSpace > spaceLeft)
|
||||
{
|
||||
|
@ -526,24 +530,24 @@ var Text = new Class({
|
|||
if (j > 0)
|
||||
{
|
||||
result += '\n';
|
||||
spaceLeft = wordWrapWidth;
|
||||
}
|
||||
}
|
||||
|
||||
result += words[j] + ' ';
|
||||
spaceLeft = wordWrapWidth - wordWidthWithSpace;
|
||||
result += word;
|
||||
|
||||
if (j < lastWordIndex)
|
||||
{
|
||||
result += ' ';
|
||||
spaceLeft -= wordWidthWithSpace;
|
||||
}
|
||||
else
|
||||
{
|
||||
spaceLeft -= wordWidthWithSpace;
|
||||
result += words[j];
|
||||
|
||||
if (j < (words.length - 1))
|
||||
{
|
||||
result += ' ';
|
||||
}
|
||||
spaceLeft -= wordWidth;
|
||||
}
|
||||
}
|
||||
|
||||
if (i < lines.length - 1)
|
||||
if (i < lastLineIndex)
|
||||
{
|
||||
result += '\n';
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue