Skip to content

Conversation

@kskang
Copy link

@kskang kskang commented Jan 11, 2026

CJK characters have display width 2. But the code counted them as width 1 when calculating word wrap boundaries. This caused incorrect wrap positions.

Changes

  • Add col_offset field to WrapBreak struct. This field tracks display column position.
  • Use col_offset instead of char_offset in wrap boundary detection.
  • Use dynamic width calculation for non-ASCII characters in buffer drawing.

Test

  • Add native test for CJK word wrap with mixed scripts (Korean, English, Chinese, Japanese).

Fixes #255

@kommander
Copy link
Collaborator

Good find. I've got something similar on a branch, but I wasn't happy with the performance impact on measureForDimensions. Maybe that's now negligible with its caching. I'll bench some more and bring that in somehow the coming days.

Add col_offset field to WrapBreak struct for tracking display column.
CJK characters have display width 2, so char_offset (character count)
differs from col_offset (display column). This fix ensures word wrap
boundaries are calculated using display columns.
@kskang kskang force-pushed the fix/cjk-col-offset branch from a2870c5 to 02572b3 Compare January 11, 2026 23:54
@kommander
Copy link
Collaborator

I think I fixed that with a little bit different approach in #529, it is a little bit more performance aware. Thank you for looking into this!

@kommander kommander closed this Jan 17, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

bug: CJK char corruption in text rendering

2 participants