Skip to content

Commit da841ed

Browse files
胡正Qiu-Jun
胡正
authored andcommitted
fix: 修复两端对齐的缺陷
1 parent 320b7ae commit da841ed

File tree

1 file changed

+10
-4
lines changed

1 file changed

+10
-4
lines changed

packages/core/objects/CustomTextbox.js

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -85,16 +85,22 @@ fabric.Textbox = fabric.util.createClass(fabric.Textbox, {
8585
accumulatedSpace = 0;
8686
line = this._textLines[i];
8787
currentLineWidth = this.getLineWidth(i);
88-
if (currentLineWidth < this.width && (spaces = this.textLines[i].split(''))) {
88+
if (
89+
currentLineWidth < this.width &&
90+
(spaces = this.textLines[i].split('')) &&
91+
spaces.length > 1
92+
) {
8993
numberOfSpaces = spaces.length;
9094
diffSpace = (this.width - currentLineWidth) / (numberOfSpaces - 1);
9195
for (var j = 0, jlen = line.length; j <= jlen; j++) {
9296
charBound = this.__charBounds[i][j];
9397
// if (this._reSpaceAndTab.test(line[j])) {
94-
charBound.width += diffSpace;
95-
charBound.kernedWidth += diffSpace;
9698
charBound.left += accumulatedSpace;
97-
accumulatedSpace += diffSpace;
99+
if (j < jlen - 1) {
100+
charBound.width += diffSpace;
101+
charBound.kernedWidth += diffSpace;
102+
accumulatedSpace += diffSpace;
103+
}
98104
// } else {
99105
// charBound.left += accumulatedSpace;
100106
// }

0 commit comments

Comments
 (0)