Skip to content

Commit

Permalink
Merge pull request #2852 from asturur/textboxspaces
Browse files Browse the repository at this point in the history
adding lineStarted logic to _wrapLine function
  • Loading branch information
asturur committed Mar 26, 2016
2 parents c815f22 + 2a1842a commit c1e3ad5
Showing 1 changed file with 7 additions and 5 deletions.
12 changes: 7 additions & 5 deletions src/shapes/textbox.class.js
Original file line number Diff line number Diff line change
Expand Up @@ -262,29 +262,32 @@
infix = ' ',
wordWidth = 0,
infixWidth = 0,
largestWordWidth = 0;
largestWordWidth = 0,
lineJustStarted = true;

for (var i = 0; i < words.length; i++) {
word = words[i];
wordWidth = this._measureText(ctx, word, lineIndex, offset);

offset += word.length;

lineWidth += infixWidth + wordWidth;

if (lineWidth >= this.width && line !== '') {
if (lineWidth >= this.width && !lineJustStarted) {
lines.push(line);
line = '';
lineWidth = wordWidth;
lineJustStarted = true;
}

if (line !== '' || i === 1) {
if (!lineJustStarted) {
line += infix;
}
line += word;

infixWidth = this._measureText(ctx, infix, lineIndex, offset);
offset++;

lineJustStarted = false;
// keep track of largest word
if (wordWidth > largestWordWidth) {
largestWordWidth = wordWidth;
Expand All @@ -299,7 +302,6 @@

return lines;
},

/**
* Gets lines of text to render in the Textbox. This function calculates
* text wrapping on the fly everytime it is called.
Expand Down

0 comments on commit c1e3ad5

Please sign in to comment.