diff --git a/src/shapes/Text.js b/src/shapes/Text.js index 7b410899..e8bfafde 100644 --- a/src/shapes/Text.js +++ b/src/shapes/Text.js @@ -192,22 +192,6 @@ _getContextFont: function() { return this.getFontStyle() + SPACE + this.getFontSize() + PX_SPACE + this.getFontFamily(); }, - _expandTextData: function(arr) { - var len = arr.length; - n = 0, - text = EMPTY_STRING, - newArr = []; - - for (n=0; n width) { + if (fixedWidth && lineWidth > maxWidth) { /* * if width is fixed and line does not fit entirely * break the line into multiple fitting lines @@ -255,7 +241,7 @@ var mid = (low + high) >>> 1, substr = line.slice(0, mid + 1), substrWidth = this._getTextWidth(substr); - if (substrWidth <= width) { + if (substrWidth <= maxWidth) { low = mid + 1; match = substr; matchWidth = substrWidth; @@ -292,6 +278,16 @@ break; } line = line.slice(low); + if (line.length > 0) { + // Check if the remaining text would fit on one line + lineWidth = this._getTextWidth(line); + if (lineWidth <= maxWidth) { + // if it does, add the line and break out of the loop + this._addTextLine(line, lineWidth); + currentHeightPx += lineHeightPx; + break; + } + } } else { // not even one character could fit in the element, abort break;