Add Unicode-aware line wrapping with conservative number protection #53
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Summary
Implements intelligent multi-line text wrapping with proper width constraint enforcement and international language support. The implementation uses Core Text's Unicode Line Breaking Algorithm with a conservative validation layer to protect numbers from being split across lines.
Problem
Previously, when setting preferredMaxLayoutWidth on MTMathUILabel, long text would either:
constraint, causing truncation
- CJK languages (Chinese, Japanese) where words aren't space-separated
- Number formats across locales (French 3,14, English 1,000,000, French 1 000 000)
- Complex grapheme clusters (emoji, combining characters)
Example of the bug:
Constraint: 235pt
Actual width: 262.786pt
Rendered: "Rappelons la conversion : 1 km équi[TRUNCATED]"
expected: "Rappelons la conversion : 1 km équivaut à 1000 m."
Implementation Details
Number Protection Patterns
The implementation conservatively protects these number formats:
Wrapping Behavior
CJK Languages:
Chinese: Can break between most characters
Japanese: Follows kinsoku rules (禁則処理)
Korean: Breaks at spaces (like English)
Latin Languages:
English/French/Spanish/German: Break at word boundaries (spaces)
Respects accented characters: é, ñ, ü, etc.
Mixed Content:
"The equation is 方程式: x² + y² = r²"
→ Can break between scripts intelligently