-
Notifications
You must be signed in to change notification settings - Fork 57
Add text_style + styled_text crates (CSS-like resolution + document blocks)
#495
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Add text_style + styled_text crates (CSS-like resolution + document blocks)
#495
Conversation
|
There's at least one big problem with this ... This is a great bike shedding opportunity for people (the name). |
|
This also doesn't yet lower to Parley and have an example ... coming soon. Other things too. |
|
I will also peel off the |
5eac6a3 to
ea54de2
Compare
|
I'm still reading through this but my general feeling is that we'll want a simpler vocabulary crate that only provides the fundamental resolved property types. Things like * A zero alloc language type the only captures language, script and region subtags would be nice. We don't really care about the rest. |
I agree with this. And would say that I think it would be useful to have the "computed" styles (and likely a few other complementary low-level types like |
|
I'll be pushing a proposal to address some of this shortly... and then I'll be passing out. :) |
05f976d to
d060b90
Compare
|
@dfrg I think the last set of changes adding If so, I could separate that out from this PR and submit a new PR that contains just that and the changes to have Parley / Fontique use it. (After I sleep...) |
|
(It would still need some of the code that we have for some of these types in the existing stuff ... like parse functions, display impls, and bytemuck stuff. But that's easy to bring over.) |
d060b90 to
45c2c0f
Compare
Yes, this looks much better to me and I think it makes sense to split it out into a separate PR so we can bikeshed a bit on name and get it merged. Thanks! |
|
Splitting a very small |
…nt blocks) - Keep `attributed_text` generic; add read APIs for iterating attributes/ranges - Introduce `text_style`: inline/paragraph declarations, specified→computed resolution, root-relative units (rem), and extensible `ResolveContext` (parent/initial/root) - Add OpenType settings (tag/setting model) with CSS-like source parsing at resolution time - Add `styled_text`: `StyledText` blocks, `StyledDocument` block list w/ root style propagation, and resolved inline runs (`Iterator<Item=Result<…>>`)
Replace the O(segments×spans) “scan all spans per run” resolver with a sweep-line that maintains an active span set across boundaries and computes each segment’s computed style from only active spans. This significantly reduces work for texts with many spans/runs, while preserving “last writer wins” semantics and dependent-property resolution (e.g. `em` spacing against final computed `font-size`). Includes a differential test against a reference (slow) resolver, and a forward-compat fallback for future `text_style::InlineDeclaration` variants.
Create new `text_style_resolve` crate providing computed style types, resolve contexts, specified→computed resolution, and OpenType settings parsing/errors. Slim `text_style` down to vocabulary-only (declarations/values/settings) and update `styled_text` + docs to use the new resolver layer.`
Replace the active-span `BTreeSet` with a sorted `Vec` (binary-search insert/remove) to eliminate per-span tree node allocations while preserving last-writer-wins ordering.
Change `ComputedInlineStyle` font variations/features to `Arc<[Setting<T>]>` and update resolution to inherit via `Arc` clone instead of allocating/copying `Vec`s. Keeps the public API returning `&[Setting<T>]` while reducing per-run allocations.
Replace per-boundary `Vec<Vec<usize>>` start/end event lists with CSR (Compressed Sparse Row) buffers (flat events + offsets) to avoid many small allocations while preserving run resolution semantics.
Add a new `no_std` + `alloc` `styled_text_parley` crate that lowers `styled_text::StyledText` resolved runs into Parley ranged builder calls, producing a `parley::Layout`.
Adding this to |
+1 for this. I think basically everything that's a computed style in Parley makes sense here (I'm assuming that where this is headed is that Parley will end up with less style resolution than it currently has (basically only things that can't be computed ahead of time becuase they depend on the font metrics or font fallback).
Some kind In my case my source will be https://docs.rs/stylo/latest/style/values/computed/font/struct.FontFamilyList.html which is itself an |
|
Another part of this has been pulled out and turned into #501. |
45c2c0f to
87ea50e
Compare
attributed_textgeneric; add read APIs for iterating attributes/rangestext_style: inline/paragraph declarations, specified→computed resolution, root-relative units (rem), and extensibleResolveContext(parent/initial/root)styled_text:StyledTextblocks,StyledDocumentblock list w/ root style propagation, and resolved inline runs (Iterator<Item=Result<…>>)