Add calculation for letter spacing to better align with css letter-spacing properties

This commit is contained in:
Adam Greenan 2024-12-11 13:35:24 +00:00
parent 09445e0880
commit a24b30b110

View File

@ -263,7 +263,7 @@ export class Text extends Shape<TextConfig> {
var lineTranslateY = 0; var lineTranslateY = 0;
var obj = textArr[n], var obj = textArr[n],
text = obj.text, text = obj.text,
width = obj.width, width = obj.width + letterSpacing,
lastLine = obj.lastInParagraph, lastLine = obj.lastInParagraph,
spacesNumber, spacesNumber,
oneWord, oneWord,
@ -383,7 +383,8 @@ export class Text extends Shape<TextConfig> {
return isAuto ? this.getTextWidth() + this.padding() * 2 : this.attrs.width; return isAuto ? this.getTextWidth() + this.padding() * 2 : this.attrs.width;
} }
getHeight() { getHeight() {
const isAuto = this.attrs.height === AUTO || this.attrs.height === undefined; const isAuto =
this.attrs.height === AUTO || this.attrs.height === undefined;
return isAuto return isAuto
? this.fontSize() * this.textArr.length * this.lineHeight() + ? this.fontSize() * this.textArr.length * this.lineHeight() +
this.padding() * 2 this.padding() * 2
@ -501,7 +502,9 @@ export class Text extends Shape<TextConfig> {
this.textArr = []; this.textArr = [];
getDummyContext().font = this._getContextFont(); getDummyContext().font = this._getContextFont();
const additionalWidth = shouldAddEllipsis ? this._getTextWidth(ELLIPSIS) : 0; const additionalWidth = shouldAddEllipsis
? this._getTextWidth(ELLIPSIS)
: 0;
for (let i = 0, max = lines.length; i < max; ++i) { for (let i = 0, max = lines.length; i < max; ++i) {
let line = lines[i]; let line = lines[i];