Skip to content

Fix/rich text glyph spacing - #348

Merged
Insality merged 15 commits into
developfrom
fix/rich-text-glyph-spacing
Sep 26, 2026
Merged

Insality merged 15 commits into
developfrom
fix/rich-text-glyph-spacing

Conversation

@Insality

Copy link
Copy Markdown
Owner

No description provided.

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.
@Insality Insality self-assigned this Sep 25, 2026
Copilot AI lite review requested due to automatic review settings September 25, 2026 22:27
@codecov

codecov Bot commented Sep 25, 2026 •

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 86.71329% with 19 lines in your changes missing coverage. Please review.
✅ Project coverage is 72.85%. Comparing base (b6ea9f0) to head (69b1887).

Files with missing lines Patch % Lines
druid/custom/rich_text/module/rt.lua 89.39% 14 Missing ⚠️
druid/custom/rich_text/module/rt_parse.lua 50.00% 5 Missing ⚠️
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.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 Medium severity

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.

Comment thread druid/custom/rich_text/module/rt.lua Outdated
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.
@Insality
Insality merged commit a360575 into develop Sep 26, 2026
3 checks passed
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.

2 participants