Skip to content

Commit

Permalink
fixed empty line (#4802)
Browse files Browse the repository at this point in the history
  • Loading branch information
asturur authored Mar 11, 2018
1 parent e27296c commit c7f6154
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 2 deletions.
7 changes: 5 additions & 2 deletions src/shapes/text.class.js
Original file line number Diff line number Diff line change
Expand Up @@ -767,8 +767,11 @@
return this.__lineHeights[lineIndex];
}

var line = this._textLines[lineIndex], maxHeight = 0;
for (var i = 0, len = line.length; i < len; i++) {
var line = this._textLines[lineIndex],
// char 0 is measured before the line cycle because it nneds to char
// emptylines
maxHeight = this.getHeightOfChar(lineIndex, 0);
for (var i = 1, len = line.length; i < len; i++) {
maxHeight = Math.max(this.getHeightOfChar(lineIndex, i), maxHeight);
}

Expand Down
9 changes: 9 additions & 0 deletions test/unit/text.js
Original file line number Diff line number Diff line change
Expand Up @@ -717,4 +717,13 @@
assert.equal(text.styles[0][2].fontSize, styleFontSize * schema.size, 'character 2: fontSize has been decreased');
assert.equal(text.styles[0][2].deltaY, styleDeltaY + styleFontSize * schema.baseline, 'character 2: deltaY has been increased');
});

QUnit.test('getHeightOfLine measures height of aline', function(assert) {
var text = new fabric.Text('xxx\n');
var height1 = text.getHeightOfLine(0);
var height2 = text.getHeightOfLine(1);
assert.equal(Math.round(height1), 52, 'height of line with text is ok');
assert.equal(Math.round(height2), 52, 'height of empty line is ok');
assert.equal(height1, height2, 'should have same height');
});
})();

0 comments on commit c7f6154

Please sign in to comment.