From d5e7a9f231c3a682e75e229e85612dbd728e578b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E4=B8=8D=E5=A6=82=E6=80=80=E5=BF=B5=EF=BC=88=E4=BA=91?= =?UTF-8?q?=E8=B0=8C=EF=BC=89?= Date: Thu, 26 Dec 2024 20:52:52 +0800 Subject: [PATCH] fix: text wrapping boundary cases (#1879) * fix: text wrapping boundary cases * chore: remove log --- .changeset/ten-impalas-type.md | 5 +++++ packages/g-lite/src/services/TextService.ts | 12 ++++++------ 2 files changed, 11 insertions(+), 6 deletions(-) create mode 100644 .changeset/ten-impalas-type.md diff --git a/.changeset/ten-impalas-type.md b/.changeset/ten-impalas-type.md new file mode 100644 index 000000000..75f7a1d86 --- /dev/null +++ b/.changeset/ten-impalas-type.md @@ -0,0 +1,5 @@ +--- +'@antv/g-lite': patch +--- + +fix: text wrapping boundary cases diff --git a/packages/g-lite/src/services/TextService.ts b/packages/g-lite/src/services/TextService.ts index 8a0ccc056..412b5b7fa 100644 --- a/packages/g-lite/src/services/TextService.ts +++ b/packages/g-lite/src/services/TextService.ts @@ -391,7 +391,7 @@ export class TextService { textCharIndex += 1; txt += chars[textCharIndex]; } - while (calcWidth(txt) > widthThreshold) { + while (calcWidth(txt) > widthThreshold && textCharIndex > 0) { textCharIndex -= 1; txt = txt.slice(0, -1); } @@ -436,7 +436,7 @@ export class TextService { parsedStyle.isOverflowing = true; if (i < chars.length - 1) { - appendEllipsis(currentLineIndex, i); + appendEllipsis(currentLineIndex, i - 1); } break; @@ -452,17 +452,17 @@ export class TextService { if (currentLineWidth > 0 && currentLineWidth + charWidth > maxWidth) { const result = findCharIndexClosestWidthThreshold( lines[currentLineIndex], - i, + i - 1, maxWidth, ); - if (result.textCharIndex !== i) { + if (result.textCharIndex !== i - 1) { lines[currentLineIndex] = result.txt; if (result.textCharIndex === chars.length - 1) { break; } - i = result.textCharIndex; + i = result.textCharIndex + 1; char = chars[i]; prevChar = chars[i - 1]; nextChar = chars[i + 1]; @@ -472,7 +472,7 @@ export class TextService { if (currentLineIndex + 1 >= maxLines) { parsedStyle.isOverflowing = true; - appendEllipsis(currentLineIndex, i); + appendEllipsis(currentLineIndex, i - 1); break; }