Skip to content

anyrender_svg: render text from usvg's layouted glyphs instead of flattened paths - #85

Open
nicoburns wants to merge 1 commit into
mainfrom
devin/1786915533-usvg-layouted-text
Open

anyrender_svg: render text from usvg's layouted glyphs instead of flattened paths#85
nicoburns wants to merge 1 commit into
mainfrom
devin/1786915533-usvg-layouted-text

Conversation

@nicoburns

Copy link
Copy Markdown
Member

Summary

anyrender_svg previously rendered usvg::Node::Text by recursing into text.flattened(), i.e. drawing text as pre-converted vector paths. This PR switches it to consume text.layouted() and submit real glyph runs via PaintScene::draw_glyphs, so backends receive actual font/glyph data (enabling hinting, glyph caching, etc.).

New text module (crates/anyrender_svg/src/text.rs), feature-gated behind the existing text feature (the flattened() fallback remains when the feature is off):

  • TextRenderer loads faces from the tree's fontdb::Database (Binary/File/SharedFile sources) into anyrender::FontData, cached per fontdb::ID along with units_per_em and axis info (via skrifa).
  • For each usvg::layout::Span: draws overline/underline before glyphs and line-through after (matching resvg's paint order), honoring span.visible and fill/stroke paint_order.
  • Glyphs whose PositionedGlyph::transform() is a pure translate+uniform-scale (font_size/upem) are batched into runs of anyrender::Glyph { id, x, y }; runs flush on font or variation-coordinate changes. Rotated/skewed glyphs (e.g. textPath) are drawn as single-glyph runs with the glyph transform folded into the run transform.
  • Font variations: span font_variations plus automatic opsz (when FontOpticalSizing::Auto and the font has an opsz axis) are normalized through skrifa's axis mapping and passed as NormalizedCoords.
  • Since draw_glyphs takes no brush transform, gradient brush transforms are baked into the gradient geometry (apply_brush_transform), including a correction for single-glyph runs whose run transform differs from text space.

Also adds skrifa = "0.44" as an optional workspace dependency and extends the text feature with usvg/memmap-fonts + usvg/system-fonts.

Verified with a vello_cpu test harness rendering plain, underlined, gradient fill+stroke, rotated, and text-on-a-path SVGs:

layouted text rendering

Link to Devin session: https://dioxus.staging.devinenterprise.com/sessions/2dde303678964855b869f1254e8858e5
Requested by: @nicoburns

@staging-devin-ai-integration

Copy link
Copy Markdown

🤖 Devin AI Engineer

I'll be helping with this pull request! Here's what you should know:

✅ I will automatically:

  • Address comments on this PR that start with 'DevinAI' or '@devin'.
  • Look at CI failures and help fix them

Note: I can only respond to comments from users who have write access to this repository.

⚙️ Control Options:

  • Disable automatic comment, CI, and merge conflict monitoring

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