fix textbox wrapping with charspacing (#4803)

* fix textbox and charspacing

* added test

* enabled all tests
This commit is contained in:
Andrea Bogazzi 2018-03-12 01:53:43 -04:00 committed by GitHub
parent c7f6154bb5
commit 808faa6d5f
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 22 additions and 4 deletions

View file

@ -736,11 +736,12 @@
prevStyle = prevGrapheme ? this.getCompleteStyleDeclaration(lineIndex, charIndex - 1) : { },
info = this._measureChar(grapheme, style, prevGrapheme, prevStyle),
kernedWidth = info.kernedWidth,
width = info.width;
width = info.width, charSpacing;
if (this.charSpacing !== 0) {
width += this._getWidthOfCharSpacing();
kernedWidth += this._getWidthOfCharSpacing();
charSpacing = this._getWidthOfCharSpacing();
width += charSpacing;
kernedWidth += charSpacing;
}
var box = {

View file

@ -326,6 +326,9 @@
lineWidth = wordWidth;
lineJustStarted = true;
}
else {
lineWidth += additionalSpace;
}
if (!lineJustStarted) {
line.push(infix);

View file

@ -113,5 +113,19 @@
assert.equal(textbox.isEmptyStyles(5), true, 'style is empty at line 5');
assert.equal(textbox.isEmptyStyles(6), false, 'style is empty at line 6');
});
QUnit.test('wrapping with charspacing', function(assert) {
var textbox = new fabric.Textbox('xa xb xc xd xe ya yb id', {
width: 190,
});
assert.equal(textbox.textLines[0], 'xa xb xc xd', 'first line match expectations');
textbox.charSpacing = 100;
textbox.initDimensions();
assert.equal(textbox.textLines[0], 'xa xb xc', 'first line match expectations spacing 100');
textbox.charSpacing = 300;
textbox.initDimensions();
assert.equal(textbox.textLines[0], 'xa xb', 'first line match expectations spacing 300');
textbox.charSpacing = 800;
textbox.initDimensions();
assert.equal(textbox.textLines[0], 'xa', 'first line match expectations spacing 800');
});
})();