Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Some fixes to textbox #2347

Merged
merged 1 commit into from
Jul 20, 2015
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/mixins/itext.svg_export.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
23 changes: 19 additions & 4 deletions src/shapes/textbox.class.js
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@asturur could you please rephrase this? it's difficult to understand it as it is

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Generate an object that translates the style object so that it is broken up by visual lines (new lines and automatic wrapping). The original text styles object is broken up by actual lines (new lines only), which is only sufficient for Text / IText.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks, changed

* @private
*/
_generateStyleMap: function() {
var realLineCount = 0,
realLineCharCount = 0,
Expand Down Expand Up @@ -329,6 +342,8 @@
var lines = this._wrapText(this.ctx, this.text);

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

Expand Down