Skip to content

Commit

Permalink
fix: line break position does not take into account newline characters (
Browse files Browse the repository at this point in the history
  • Loading branch information
wang1212 authored Dec 27, 2024
1 parent c492468 commit 1424824
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 2 deletions.
5 changes: 5 additions & 0 deletions .changeset/sour-hornets-turn.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@antv/g-lite': patch
---

fix: line break position does not take into account newline characters
4 changes: 2 additions & 2 deletions __tests__/demos/bugfix/textWordWrap.ts
Original file line number Diff line number Diff line change
Expand Up @@ -83,14 +83,14 @@ export async function textWordWrap(context: { canvas: Canvas }) {
fontSize: 12,
fontWeight: 'normal',
linkTextFill: '#326EF4',
maxLines: 3,
maxLines: 1,
opacity: 1,
text: '哈哈哈哈\n哈哈哈哈\n哈哈哈哈\n',
// textAlign: 'right',
textBaseline: 'top',
textOverflow: 'ellipsis',
wordWrap: true,
wordWrapWidth: 84,
wordWrapWidth: 30,
},
});
const rect2 = new Rect({
Expand Down
4 changes: 4 additions & 0 deletions packages/g-lite/src/services/TextService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -338,6 +338,7 @@ export class TextService {
parsedStyle: ParsedTextStyleProps,
offscreenCanvas: CanvasLike,
): string {
const self = this;
const {
wordWrapWidth = 0,
letterSpacing = 0,
Expand Down Expand Up @@ -388,6 +389,9 @@ export class TextService {
calcWidth(txt) < widthThreshold &&
textCharIndex < chars.length - 1
) {
if (self.isNewline(chars[textCharIndex + 1])) {
break;
}
textCharIndex += 1;
txt += chars[textCharIndex];
}
Expand Down

0 comments on commit 1424824

Please sign in to comment.