mirror of
https://github.com/Hopiu/fabric.js.git
synced 2026-03-16 22:10:32 +00:00
fix textbox wrapping with charspacing (#4803)
* fix textbox and charspacing * added test * enabled all tests
This commit is contained in:
parent
c7f6154bb5
commit
808faa6d5f
3 changed files with 22 additions and 4 deletions
|
|
@ -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 = {
|
||||
|
|
|
|||
|
|
@ -326,6 +326,9 @@
|
|||
lineWidth = wordWidth;
|
||||
lineJustStarted = true;
|
||||
}
|
||||
else {
|
||||
lineWidth += additionalSpace;
|
||||
}
|
||||
|
||||
if (!lineJustStarted) {
|
||||
line.push(infix);
|
||||
|
|
|
|||
|
|
@ -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');
|
||||
});
|
||||
})();
|
||||
|
|
|
|||
Loading…
Reference in a new issue