Updated font system usage#14
Conversation
Bumps [fontique](https://github.com/linebender/parley) from 0.9.0 to 0.10.0. - [Release notes](https://github.com/linebender/parley/releases) - [Changelog](https://github.com/linebender/parley/blob/main/CHANGELOG.md) - [Commits](linebender/parley@v0.9.0...v0.10.0) --- updated-dependencies: - dependency-name: fontique dependency-version: 0.10.0 dependency-type: direct:production update-type: version-update:semver-minor ... Signed-off-by: dependabot[bot] <support@github.com>
Bumps [psl](https://github.com/addr-rs/psl) from 2.1.212 to 2.1.213. - [Release notes](https://github.com/addr-rs/psl/releases) - [Commits](addr-rs/psl@v2.1.212...v2.1.213) --- updated-dependencies: - dependency-name: psl dependency-version: 2.1.213 dependency-type: direct:production update-type: version-update:semver-patch ... Signed-off-by: dependabot[bot] <support@github.com>
Bumps [skia-safe](https://github.com/rust-skia/rust-skia) from 0.87.0 to 0.97.2. - [Release notes](https://github.com/rust-skia/rust-skia/releases) - [Commits](rust-skia/rust-skia@0.87.0...0.97.2) --- updated-dependencies: - dependency-name: skia-safe dependency-version: 0.97.2 dependency-type: direct:production update-type: version-update:semver-minor ... Signed-off-by: dependabot[bot] <support@github.com>
…safe-0.97.2 Bump skia-safe from 0.87.0 to 0.97.2
…que-0.10.0 Bump fontique from 0.9.0 to 0.10.0
….1.213 Bump psl from 2.1.212 to 2.1.213
| // render with even on systems that have no fonts installed. | ||
| font_cx | ||
| .collection | ||
| .register_fonts(gosub_shared::ROBOTO_FONT.to_vec().into(), None); |
There was a problem hiding this comment.
I think this here should not copy the font. It wants a dyn AsRef<[u8]> and we can just do that with a &'static [u8]
| self | ||
| } | ||
|
|
||
| fn register_font(&mut self, data: Vec<u8>, _family_override: Option<&str>) -> Result<(), FontError> { |
There was a problem hiding this comment.
Same here, I think we should have an additional method where you can register a &'static [u8] font and shared fonts with Arc<[u8]>
|
|
||
| if !glyphs.is_empty() { | ||
| runs.push(ShapedRun { | ||
| font: font.clone(), |
There was a problem hiding this comment.
I feel like we should not clone the font here. Every run is made by that one font anyways.
Also, I see problems here. We might have one inline context with more than one font aswell as other elements, and this seems to not account for that.
| /// Used for `@font-face` web fonts and for bundled fallback fonts (e.g. Roboto). | ||
| /// `family_override` lets callers assign a logical name that CSS can reference; | ||
| /// if `None` the name is taken from the font's own `name` table. | ||
| fn register_font(&mut self, data: Vec<u8>, family_override: Option<&str>) -> Result<(), FontError>; |
There was a problem hiding this comment.
Yeah, so again. API wise, this might also just be the `Arc<dyn AsRef<[u8]>> here as that is how we store it internally aswell
There was a problem hiding this comment.
Or alternatively, just add more register_font functions
| /// Returns fully positioned glyphs. The returned `ShapedText` is cheaply cloneable | ||
| /// (glyphs are usually stored in an `Arc<[ShapedGlyph]>` or `Vec`) so callers can | ||
| /// cache it at the layout node level. | ||
| fn shape(&mut self, text: &str, font: &ResolvedFont, size: f32, max_width: Option<f32>) -> ShapedText; |
There was a problem hiding this comment.
Shape should probably also not be here, or support more of our needs.
Laying out text is not the only problem here. We both need text-shaping but also supporting inline features (and considering that inline contexts can be merged). And we also need support inline boxes.
| /// ``` | ||
| pub trait HasFontSystem { | ||
| fn font_system(&self) -> Arc<Mutex<dyn FontSystem>>; | ||
| } |
There was a problem hiding this comment.
This needs the Better integration with the ModuleConfig, we should not return a dynamicly dispatched type here
| /// The database is built once the first time this is called and then reused, | ||
| /// so system font discovery only happens once per process. | ||
| fn svg_options() -> usvg::Options<'static> { | ||
| static FONTDB: OnceLock<Arc<usvg::fontdb::Database>> = OnceLock::new(); |
There was a problem hiding this comment.
I think we there now have multiple font databases? Like one from whatever font manager we are using and one from usvg?
|
|
||
| /// Return `usvg::Options` backed by a shared fontdb that has system fonts loaded. | ||
| fn svg_options() -> usvg::Options<'static> { | ||
| static FONTDB: OnceLock<Arc<usvg::fontdb::Database>> = OnceLock::new(); |
There was a problem hiding this comment.
Same here, another font db
| struct TextNodeData { | ||
| /// Start index of the text node in the complete string (`str_buf`) | ||
| to: usize, | ||
| /// Node identifier that holds the text | ||
| id: NodeId, | ||
| /// Actual font for rendering and layouting | ||
| font_info: <<C as HasFontManager>::FontManager as FontManager>::FontInfo, | ||
| /// CSS font properties for this run | ||
| font_info: FontDescriptor, |
There was a problem hiding this comment.
So, this currently fixes us to parley when using taffy
Wire Skia and Vello rasterizers into the render pipeline
Increased tile performance
9ab1674 to
11f583f
Compare
This PR introduces a backend-agnostic font system abstraction and wires it through the layout engine and all renderers.
Previously each renderer created its own ad-hoc font objects with no shared shaping or measurement. every renderer independently resolved font families, created typefaces, and laid out text with no coordination.