Skip to content

Commit

Permalink
Merge pull request #2347 from asturur/fixes-textbox
Browse files Browse the repository at this point in the history
Some fixes to textbox
kangax committed Jul 20, 2015
2 parents 2171dd1 + 8f14daa commit aba1b0e
Showing 2 changed files with 20 additions and 5 deletions.
2 changes: 1 addition & 1 deletion src/mixins/itext.svg_export.js
Original file line number Diff line number Diff line change
@@ -10,7 +10,7 @@
*/
_setSVGTextLineText: function(lineIndex, textSpans, height, textLeftOffset, textTopOffset, textBgRects) {
if (!this.styles[lineIndex]) {
this.callSuper('_setSVGTextLineText',
fabric.Text.prototype._setSVGTextLineText.call(this,
lineIndex, textSpans, height, textLeftOffset, textTopOffset);
}
else {
23 changes: 19 additions & 4 deletions src/shapes/textbox.class.js
Original file line number Diff line number Diff line change
@@ -92,15 +92,28 @@
this._set('width', this.dynamicMinWidth);
}

// calculate a styleMap that lets us know where styles as, as _textLines is separated by \n and wraps,
// but the style object line indices is by \n.
this._styleMap = this._generateStyleMap();

// clear cache and re-calculate height
this._clearCache();
this.height = this._getTextHeight(ctx);
this._setLineWidths();
},

/**
* set the __lineWidths cache array to support
* functions that expect it to be filled
* @private
*/
_setLineWidths: function() {
for (var i = 0, len = this._textLines.length; i < len; i++) {
this.__lineWidths[i] = this.width;
}
},

/**
* Calculate a styleMap that lets us know where styles as, as _textLines is separated by \n and wraps,
* but the style object line indices is by \n.
* @private
*/
_generateStyleMap: function() {
var realLineCount = 0,
realLineCharCount = 0,
@@ -329,6 +342,8 @@
var lines = this._wrapText(this.ctx, this.text);

this.ctx.restore();
this._textLines = lines;
this._styleMap = this._generateStyleMap();
return lines;
},

0 comments on commit aba1b0e

Please sign in to comment.