Skip to content
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

Restore glyph hinting support #544

Merged
merged 1 commit into from
Apr 3, 2024
Merged

Restore glyph hinting support #544

merged 1 commit into from
Apr 3, 2024

Conversation

dfrg
Copy link
Collaborator

@dfrg dfrg commented Apr 3, 2024

Updates skrifa to 0.19.0 and restores hinting support. Our previous glyph scaler came with its own instance cache but skrifa does not, so this also adds a very simple LRU cache to manage instances.

There will likely be adjustments to this when we do "real" glyph caching and start retaining our caches across frames but this should be sufficient for now and will hopefully improve text quality in xilem on low-resolution displays.

Updates skrifa to 0.19.0 and restores hinting support. Our previous glyph scaler came with its own instance cache but skrifa does not, so this also adds a very simple LRU cache to manage instances.

There will likely be adjustments to this when we do "real" glyph caching and start retaining our caches across frames but this should be sufficient for now and will hopefully improve text quality in xilem on low-resolution displays.
Copy link
Member

@xorgy xorgy left a comment

Choose a reason for hiding this comment

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

I don't see anything wrong with this.

@dfrg dfrg added this pull request to the merge queue Apr 3, 2024
Merged via the queue into main with commit b520a35 Apr 3, 2024
15 checks passed
@dfrg dfrg deleted the hint branch April 3, 2024 19:32
}

impl GlyphCache {
pub fn clear(&mut self) {
self.encoding.reset();
self.glyphs.clear();
// No need to clear the hinting cache
Copy link
Member

Choose a reason for hiding this comment

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

Why? Is it because it's already bounded in size?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Exactly. In reality, none of this is retained right now so it’s mostly irrelevant. This module will need some substantial rework when we do rasterized glyph caching.

@@ -55,9 +58,18 @@ impl GlyphCache {
encoding_cache.encode_fill_style(fill);
let mut path = encoding_cache.encode_path(true);
let outline = outlines.get(GlyphId::new(key.glyph_id as u16))?;
// FIXME: Re-add hinting when skrifa supports it
Copy link
Member

Choose a reason for hiding this comment

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

🔥

}

const HINTING_MODE: HintingMode = HintingMode::Smooth {
lcd_subpixel: Some(LcdLayout::Horizontal),
Copy link
Member

Choose a reason for hiding this comment

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

I'm guessing this will need to be wired through at some point?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

That’s an open question. The skrifa hinter supports a lot of modes because we have a requirement of matching FreeType. There’s an argument to be made that vello should always just use a modern hinting mode but that’s open to discussion. Ultimately, most fonts these days have hints generated by ttfautohint which ignores these things. Only the MS ClearType fonts really take advantage of them and we can potentially choose a sane default for those.

@@ -92,6 +92,7 @@ impl SimpleText {
.glyph_transform(glyph_transform)
.normalized_coords(var_loc.coords())
.brush(brush)
.hint(false)
Copy link
Member

Choose a reason for hiding this comment

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

I would expect us to want to test this?
Is it because SimpleText is also used for the headless example?

I see in Zulip that you've mentioned that text should be on a pixel baseline, which we don't enforce in our current examples.

I still would imagine that hinting could be productively used in e.g. the stats displays?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

This is disabled for the test scenes because we have some animated text which doesn’t work well with hinting (it snaps to pixels as it animates causing annoying jitter) and everything currently uses the same code path. We can definitely change this but I wanted to get the functionality in for xilem where hinting is more important.

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.

3 participants