anyrender_svg: render text from usvg's layouted glyphs instead of flattened paths - #85
Open
nicoburns wants to merge 1 commit into
Open
anyrender_svg: render text from usvg's layouted glyphs instead of flattened paths#85nicoburns wants to merge 1 commit into
nicoburns wants to merge 1 commit into
Conversation
🤖 Devin AI EngineerI'll be helping with this pull request! Here's what you should know: ✅ I will automatically:
Note: I can only respond to comments from users who have write access to this repository. ⚙️ Control Options:
|
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.
Summary
anyrender_svgpreviously renderedusvg::Node::Textby recursing intotext.flattened(), i.e. drawing text as pre-converted vector paths. This PR switches it to consumetext.layouted()and submit real glyph runs viaPaintScene::draw_glyphs, so backends receive actual font/glyph data (enabling hinting, glyph caching, etc.).New
textmodule (crates/anyrender_svg/src/text.rs), feature-gated behind the existingtextfeature (theflattened()fallback remains when the feature is off):TextRendererloads faces from the tree'sfontdb::Database(Binary/File/SharedFilesources) intoanyrender::FontData, cached perfontdb::IDalong withunits_per_emand axis info (viaskrifa).usvg::layout::Span: draws overline/underline before glyphs and line-through after (matching resvg's paint order), honoringspan.visibleand fill/strokepaint_order.PositionedGlyph::transform()is a pure translate+uniform-scale (font_size/upem) are batched into runs ofanyrender::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_variationsplus automaticopsz(whenFontOpticalSizing::Autoand the font has an opsz axis) are normalized throughskrifa's axis mapping and passed asNormalizedCoords.draw_glyphstakes 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 thetextfeature withusvg/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:
Link to Devin session: https://dioxus.staging.devinenterprise.com/sessions/2dde303678964855b869f1254e8858e5
Requested by: @nicoburns