Skip to content

Make text flattening lazy - #1124

Draft
nicoburns wants to merge 1 commit into
linebender:mainfrom
DioxusLabs:devin/1785834914-lazy-text-flattening
Draft

Make text flattening lazy#1124
nicoburns wants to merge 1 commit into
linebender:mainfrom
DioxusLabs:devin/1785834914-lazy-text-flattening

Conversation

@nicoburns

@nicoburns nicoburns commented Aug 13, 2026

Copy link
Copy Markdown
Collaborator

usvg's flattening of glyphs into sub-SVGs is inefficient (it writes out the glyphs paths as an SVG string and then re-parses them!), and is not required by users of usvg that are capable of rendering glyphs themselves. But currently on main, if you have the text feature (necessary to get layouted text) then glyphs will always be flattened.

This PR changes text flattening to be lazy (using a OnceLock), so you only pay that cost if you need the flattened glyphs:

  • Glyph outlines are computed on first access to Text::flattened, or upfront for the whole tree via the new Tree::compute_flattened_text (the latter approach is more efficient as it shares an ephemeral glyph cache between all text nodes)
  • Text::stroke_bounding_box is now approximated at layout time from the per-glyph ink bounding boxes stored in the font.

Generated with Fable. Has been through a couple of iterations, but has not yet be thoroughly self-reviewed.

Parsing now only performs text layout. Glyph outlines are computed on
first access to Text::flattened, or upfront for the whole tree via the
new Tree::compute_flattened_text, which shares an ephemeral glyph cache
between all text nodes.

Text::stroke_bounding_box is now approximated at layout time from the
per-glyph ink bounding boxes stored in the font.
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.

1 participant