-
Notifications
You must be signed in to change notification settings - Fork 57
parley: add style-run builder; accept precomputed runs from styled_text
#516
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?
parley: add style-run builder; accept precomputed runs from styled_text
#516
Conversation
|
This builds on top of PR #495 so only look at the right commit here ... but this shows a way to build a |
|
This is still doing some style resolution via |
…n, Parley lowering) - Add `styled_text`: attributed text + span styles with a CSS-inspired vocabulary (`styled_text::style`), specified→computed resolution (`styled_text::resolve`), and a `StyledText`/`StyledDocument` model for block + span styling. - Provide deterministic inline-run resolution (including overlap handling and run coalescing) plus unit tests and doctests for the core semantics. - Add `styled_text_parley`: lowers `styled_text` computed runs into Parley `StyleProperty` spans to build a `parley::Layout`. - Add `vello_cpu_render_styled_text` example exercising the end-to-end pipeline and update workspace/CI wiring for the new crates.
…ext` - Add `LayoutContext::style_run_builder` and a `StyleRunBuilder` API for constructing a Layout from contiguous, non-overlapping style runs, skipping Parley’s internal range-splitting step. - Redesign `TextStyle` as `TextStyle<'family, 'settings, B>` so font-family and OpenType settings can borrow independently, enabling per-run borrowed variations/features without extra allocations. - Update `styled_text_parley` to lower StyledText’s computed runs directly into `StyleRunBuilder` using `TextStyle<'static, '_, B>`. - Add a parity test ensuring `StyleRunBuilder` output matches `RangedBuilder` for equivalent styles.
4e0a8ae to
7f92f04
Compare
|
Makes a lot of sense. #387 does something very similar. |
|
I will note that I think the "flat list of non-overlapping styles" model may be insufficient to represent some tree-shaped data. For example, it's going to be hard to represent |
|
Why is that span example hard to represent? It's not clear to me, especially as there is no BiDi in that example. |
|
@nicoburns This is probably just the first phase ... I think those sorts of things might change with time. There's a lot of stuff downstream from this. |
@xStrom The key thing is that the two spans start/end at exactly the same offset in the text. So in the model where the styles apply to glyphs in the text, how do you determine that you have "pushed" or "popped" two spans? For most styles (e.g. styles the modify the text itself) this doesn't matter: two nested spans isn't really any different to one span that applies both sets of styles. But for (horizontal) padding, the two nested spans here imply that the I think that to implement this you would need some kind of modelling of the tree structure within Parley (perhaps each style struct having |
|
@waywardmonkeys Unrelated to my previous comment: Is there a way to reuse styles with this API? For example, in Basically, it might nice to have a layer of indirection between the style structs and the text ranges, so that more than one text range can point to the same style struct. |
|
Regarding I haven't checked the PR but in genral style reuse via references seems like an important memory optimization. Just imagine a text where there's a bold word every now and then. You only need two actual style structs for this, not a multiple of how many bold words you have. |
We're in the first steps of a long journey. |
Handling it as part of flattening is interesting possibility that for some reason I had not considered. I'd need to think it through, but I think this would probably work.
Luckily margin collapsing only applies to block-level elements, not inline-level elements, so we don't need to deal with this in Parley. |
LayoutContext::style_run_builderand aStyleRunBuilderAPI for constructing a Layout from contiguous, non-overlapping style runs, skipping Parley’s internal range-splitting step.TextStyleasTextStyle<'family, 'settings, B>so font-family and OpenType settings can borrow independently, enabling per-run borrowed variations/features without extra allocations.styled_text_parleyto lower StyledText’s computed runs directly intoStyleRunBuilderusingTextStyle<'static, '_, B>.StyleRunBuilderoutput matchesRangedBuilderfor equivalent styles.