Skip to content

Updated font system usage#14

Closed
jaytaph wants to merge 17 commits into
wsf-2-tile-performancefrom
wsf-3-font-system
Closed

Updated font system usage#14
jaytaph wants to merge 17 commits into
wsf-2-tile-performancefrom
wsf-3-font-system

Conversation

@jaytaph

@jaytaph jaytaph commented Jun 10, 2026

Copy link
Copy Markdown
Owner

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.

dependabot Bot and others added 6 commits June 13, 2026 00:33
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
// render with even on systems that have no fonts installed.
font_cx
.collection
.register_fonts(gosub_shared::ROBOTO_FONT.to_vec().into(), None);

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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> {

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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(),

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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>;

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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;

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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>>;
}

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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();

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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();

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same here, another font db

Comment on lines +624 to +630
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,

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So, this currently fixes us to parley when using taffy

@jaytaph
jaytaph force-pushed the wsf-3-font-system branch from 9ab1674 to 11f583f Compare June 20, 2026 14:08
@jaytaph jaytaph closed this Jun 21, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants