Repository navigation
fix(text): measure text width from shaping, shared with the renderer - #270
Draft
silouanwright wants to merge 6 commits into
Draft
silouanwright wants to merge 6 commits into
silouanwright wants to merge 6 commits into
Conversation
…ded advances" (dmtrKovalenko#269) This reverts commit 633abaa.
Measuring no longer builds a usvgr tree. text_width, text_fit and line breaking call usvgr::text_advance, which only shapes the text, and the shaped glyphs go into a cache that every converter cache reads, so a string is shaped once for measuring and rendering. The measuring helper is private: a font source now only says which font database it uses. Captions measure through the frame shape cache too.
Drop before merging, once usvgr with text_advance is released.
The SVG parser turns tabs and line breaks into spaces before the renderer shapes the text. Shaping them directly gave a missing glyph for a tab and no advance for a line break.
Drop before merging, once usvgr with text_advance is released.
|
Important Draft PR not reviewedDraft PRs are not automatically reviewed by default.
To automatically review draft PRs, update your CodeRabbit configuration: reviews:
auto_review:
drafts: true
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. |
The outro centres the "fframes" wordmark with text_width. Measuring from shaping gives the exact advance, so the wordmark moves a few pixels. The frame was rendered by CI on Linux with skia-cpu.
Contributor
Author
|
Updated |
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.
Second attempt at #255, replacing #256 (merged by accident, reverted in #269). Draft: it needs dmtrKovalenko/svgr#26 and a usvgr release. Until then
Cargo.tomlpoints at that PR's branch, in a separate commit to drop.The first commit re-applies #256 as it was merged, so the commits after it are what is new.
What changed since #256, following your review:
usvgr::Treeis built to measure.text_width,text_fitand line breaking callusvgr::text_advance, which only shapes the text.TextCacheowns aUsvgrTextShapeCache, and every converter cache is created from it (TextCache::converter_cache), so a string is shaped once for measuring and rendering.FontSource::measure_textis gone; a font source now only says which font database it uses (FontSource::fontdb, defaultNone, which keeps per-character advances).Widths are the same as in #256: its tests pass as they were, and the
text-widthexample and its snapshots are untouched.Nothing cached on either side:
text_fiton a 113-character string (8 measurements)With the shared cache, converting a frame of 21 words that move on every frame goes from 519 µs to 135 µs. That is a best case: the outline cache is off, so shaping is the only work that can be reused.
Ryzen 7 9800X3D, release build, Inter ExtraBold 46 px. A timing loop in a test, not a Criterion benchmark; a full frame render was not measured.
Checked:
cargo test -p fframes(105 passed),cargo clippy -p fframes -p text-width-example -- -D warningsandcargo fmt --checkon Linux with Rust 1.100. Editor bridges forhello-worldandteej-podcastcheck for wasm32. The e2e snapshots and the other editor bridges were not run.