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

getHeightOfLine not measuring empty lines #4802

Merged
merged 1 commit into from
Mar 11, 2018
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
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');
});
})();