egui icon indicating copy to clipboard operation
egui copied to clipboard

Replace ab_glyph with Skrifa + vello_cpu; enable font hinting

Open valadaptive opened this issue 1 month ago • 4 comments

  • Closes N/A
  • [x] I have followed the instructions in the PR template

I'll probably come back to this and clean it up a bit. This PR reimplements ab_glyph's functionality on top of Skrifa, a somewhat lower-level font API that's being used in Chrome now.

Skrifa doesn't perform rasterization itself, so I'm using vello_cpu from the Linebender project for rasterization. It's still in its early days, but I believe it's already quite fast. It also supports color and gradient fills, so color emoji support will be easier.

Skrifa also supports font hinting, which should make text look a bit nicer / less blurry.

Here's the current ab_glyph rendering:

image

Here's Skrifa without hinting--it looks almost identical, but there are some subpixel differences, probably due to rasterizer behavior:

image

Here's Skrifa with hinting:

image

Hinting does make the horizontal strokes look a bit bolder, which makes me wonder once again about increasing the font weight from "light" to "regular".

valadaptive avatar Nov 10 '25 05:11 valadaptive

Preview available at https://egui-pr-preview.github.io/pr/7694-skrifa Note that it might take a couple seconds for the update to show up after the preview_build workflow has completed.

View snapshot changes at kitdiff

github-actions[bot] avatar Nov 10 '25 05:11 github-actions[bot]

I'm very excited for this! The readability improvements of the font hinting is pretty big imho. Also: colored emojis unlocked???

Before we merge I want to make sure we measure what impact this has on the .wasm blob size (./scripts/build_demo_web.sh --release before/after).

emilk avatar Nov 14 '25 15:11 emilk

Regarding the quality of the rendering, I have found that adding "font embolden" (aka stem darkening) to the skrifa-based renderers is (subjectively) a big additional improvement, at least on macOS (by tweaking the embolden parameter I can make the rendering very close if not identical to Skia/Chrome).

There's no implementation for vello_cpu yet, but there's a PR for Vello Classic, and in theory a CPU-side implementation ought to be easier.

nicoburns avatar Nov 14 '25 21:11 nicoburns

Hey I just wanted to throw a vote behind this. Is there something blocking we at @tritium-legal can help with? Hinting on normal DPI platforms just makes a massive difference.

drewmiller avatar Nov 30 '25 17:11 drewmiller

wasm size on main: 10,478,576 B wasm size with skrifa: 11,080,156 B

so +600kB. I think that's well acceptable.

emilk avatar Dec 06 '25 10:12 emilk

All snapshots look good

emilk avatar Dec 06 '25 14:12 emilk

I encourage everyone to follow this link to experience the improvements: https://rerun-io.github.io/kitdiff/?url=https://github.com/emilk/egui/pull/7694

emilk avatar Dec 06 '25 14:12 emilk