diff --git a/src/shapes/text.class.js b/src/shapes/text.class.js index a84b84c8..3a11db98 100644 --- a/src/shapes/text.class.js +++ b/src/shapes/text.class.js @@ -641,7 +641,7 @@ ctx.fillStyle = this.textBackgroundColor; for (var i = 0, len = this._textLines.length; i < len; i++) { if (this._textLines[i] !== '') { - lineWidth = this._getLineWidth(ctx, i); + lineWidth = this.textAlign === 'justify' ? this.width : this._getLineWidth(ctx, i); lineLeftOffset = this._getLineLeftOffset(lineWidth); ctx.fillRect( this._getLeftOffset() + lineLeftOffset, @@ -710,7 +710,7 @@ width = 0; } else if (this.textAlign === 'justify' && this._cacheLinesWidth) { - wordCount = line.split(' '); + wordCount = line.split(/\s+/); //consider not justify last line, not for now. if (wordCount.length > 1) { width = this.width; @@ -930,11 +930,11 @@ - textTopOffset + height - this.height / 2; if (this.textAlign === 'justify') { // i call from here to do not intefere with IText - this._setSVGTextLineJustifed(i, textSpans, height, textLeftOffset, textTopOffset); + this._setSVGTextLineJustifed(i, textSpans, yPos, textLeftOffset); return; } textSpans.push( - '\t\t elements since setting opacity + // on containing one doesn't work in Illustrator + attributes, '>', + fabric.util.string.escapeXml(word), + '\n' + ); + textLeftOffset += this._getWidthOfWords(ctx, word) + spaceWidth; + } + }, _setSVGTextLineBg: function(textBgRects, i, textLeftOffset, textTopOffset, height) {