From da841ed68dcd35e80c41feac2c779891128e5e9e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E8=83=A1=E6=AD=A3?= Date: Mon, 30 Sep 2024 14:08:47 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E4=BF=AE=E5=A4=8D=E4=B8=A4=E7=AB=AF?= =?UTF-8?q?=E5=AF=B9=E9=BD=90=E7=9A=84=E7=BC=BA=E9=99=B7?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- packages/core/objects/CustomTextbox.js | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/packages/core/objects/CustomTextbox.js b/packages/core/objects/CustomTextbox.js index e4b2347e..4b765f37 100644 --- a/packages/core/objects/CustomTextbox.js +++ b/packages/core/objects/CustomTextbox.js @@ -85,16 +85,22 @@ fabric.Textbox = fabric.util.createClass(fabric.Textbox, { accumulatedSpace = 0; line = this._textLines[i]; currentLineWidth = this.getLineWidth(i); - if (currentLineWidth < this.width && (spaces = this.textLines[i].split(''))) { + if ( + currentLineWidth < this.width && + (spaces = this.textLines[i].split('')) && + spaces.length > 1 + ) { numberOfSpaces = spaces.length; diffSpace = (this.width - currentLineWidth) / (numberOfSpaces - 1); for (var j = 0, jlen = line.length; j <= jlen; j++) { charBound = this.__charBounds[i][j]; // if (this._reSpaceAndTab.test(line[j])) { - charBound.width += diffSpace; - charBound.kernedWidth += diffSpace; charBound.left += accumulatedSpace; - accumulatedSpace += diffSpace; + if (j < jlen - 1) { + charBound.width += diffSpace; + charBound.kernedWidth += diffSpace; + accumulatedSpace += diffSpace; + } // } else { // charBound.left += accumulatedSpace; // }