From 823529f839e29bf445e1541a68d649b13d4b04bc Mon Sep 17 00:00:00 2001 From: Louis Jolibois Date: Wed, 27 Mar 2013 17:12:20 +0100 Subject: [PATCH] Fixed word wrapping behavior: last words of a multiline text should not be arbitrarily wrapped anymore. Fixed width padding not being used. Removed unused _expandTextData method --- src/shapes/Text.js | 34 +++++++++++++++------------------- 1 file changed, 15 insertions(+), 19 deletions(-) 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;