Repository navigation
Fix/rich text glyph spacing - #348
Merged
Merged
Conversation
Measure each glyph against the line already laid out so UTF-8 letters and the character after a space keep a single advance instead of the padded quad width.
Use the last glyph run of the line as the measure prefix instead of the whole line, measure once with it before the overflow check, and trim only the first word of a line so spaces after images and indents after line breaks are kept.
Words split to characters are nobr, so they could never start a new line and overflowed the area. A nobr run now moves to the next line as a whole, and a word wider than the area no longer leaves an empty line before it.
Measuring after "|" shifted every word by the same amount, and line widths missed the side padding of the first glyph, so rich text sat a few pixels off a plain text node with any pivot.
With split to characters the space before a text was glued to its first letter. Letters are nobr, so the text after </nobr> joined the nobr run and could not wrap. Measure after "|" when the line tail has only spaces, so letters after an image get the same width as words.
Cache raw text metrics and font resources until the next create, read image sizes once, update nodes once instead of before and after the fit, and find the fit scale with a growing step and halving instead of a fixed 0.02 step. Split letters with a pattern instead of the pure Lua utf8.sub.
Words do not copy every settings field anymore, which matters most with split to characters. pairs(word) no longer lists the inherited settings.
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## develop #348 +/- ##
===========================================
+ Coverage 72.79% 72.85% +0.05%
===========================================
Files 31 31
Lines 4680 4704 +24
===========================================
+ Hits 3407 3427 +20
- Misses 1273 1277 +4 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
There was a problem hiding this comment.
Copilot review overview
🟡 Changes recommended
Unresolved rich-text scaling and vertical-alignment issues remain, and regression coverage is recommended.
Get a fresh assessment by requesting another Copilot review.
Review effort: Lite
Findings: 1
Open (1)
What changed in this PR
Fixes rich-text glyph spacing, measurement, scaling, and character-level wrapping, with new examples and localized strings.
Changes:
- Refactors rich-text layout and UTF-8 splitting.
- Adds glyph alignment and split-wrap examples.
- Adds translations across supported locales.
| File | Summary |
|---|---|
example/locales/zh.json |
Adds Chinese translations. |
example/locales/ru.json |
Adds Russian translations. |
example/locales/pt.json |
Adds Portuguese translations. |
example/locales/kr.json |
Adds Korean translations. |
example/locales/ja.json |
Adds Japanese translations. |
example/locales/it.json |
Adds Italian translations. |
example/locales/fr.json |
Adds French translations. |
example/locales/es.json |
Adds Spanish translations. |
example/locales/en.json |
Adds English translations. |
example/locales/de.json |
Adds German translations. |
example/examples/basic/rich_text/rich_text_split_wrap.lua |
Adds character-level wrapping example logic. |
example/examples/basic/rich_text/rich_text_split_wrap.gui |
Defines the split-wrap example layout. |
example/examples/basic/rich_text/rich_text_glyphs.lua |
Adds glyph alignment example logic. |
example/examples/basic/rich_text/rich_text_glyphs.gui |
Defines the glyph example layout. |
example/examples/basic/examples_list.lua |
Registers the new examples. |
example/druid.gui |
Adds example templates. |
druid/custom/rich_text/rich_text.lua |
Routes text creation through updated layout logic; regression coverage is recommended. |
druid/custom/rich_text/module/rt.lua |
Updates measurement, wrapping, caching, and scaling; scale-boundary spacing and empty-node vertical bearing issues remain. |
druid/custom/rich_text/module/rt_parse.lua |
Adds UTF-8 character splitting and parser updates. |
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
A word width is now its advance, measured with "|" after the text, so it does not depend on the previous word. Words keep the right spacing at size, font and image boundaries, and the line tail prefix and the "|" shift correction are gone. Lines wrap and align by the last visible glyph, so a line no longer overflows the area by the last glyph padding. Word nodes do not break lines inside themselves.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.

No description provided.