-
Notifications
You must be signed in to change notification settings - Fork 1.9k
add color emoji #7677
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
add color emoji #7677
Conversation
|
Preview is being built... Preview will be available at https://egui-pr-preview.github.io/pr/7677-my-color-emoji View snapshot changes at kitdiff |
|
@jb55 did you run this prior to cargo
|
|
that one works, I tried the one from https://fonts.google.com/noto/specimen/Noto+Color+Emoji and it didn't work |
|
this implementation looks pretty clean at first glance, but I'm not expert on this part of the code. what do you think @emilk ? prays to the egui gods he is not too busy to review |
|
A few more font options: Font requirements: |
|
Oof. This PR adds a second, entirely separate font rendering stack. There's ab_glyph, which uses ttf-parser and its own rasterizer; and now there's swash, which depends on skrifa, read-fonts, and zeno for rasterization. Two completely different sets of crates to do the exact same thing. I haven't looked too much at the added code, but it really does seem like the second font rendering stack is entirely bolted on. I don't think Swash is under active development anymore. |
|
Thanks for the feedback. -Swash only works with emoji_color enabled. The value is off by default. Single ab_glyph is still compiled. Second set of emoji crates are explicitly opt-in. If the only acceptable approach is to add color emoji support to ab_glyph, there is a complex way forward or two that can be explored. Uncertain if these will work. I was not able to make progress. |
|
This looks really cool, but I agree with @valadaptive that adding an entirely separate font rendering stack is definitely not the way to go. Note that I also previously experimented with color emoji support: #7333 If you wanted, you could then use that api to do the emoji rendering via swash in your application (or release it as a 3rd party egui plugin crate). Although the more reasonable approach would likely be to just include the emojis as png files and load those via that api. For egui-built-in emoji font support we should wait for #7694, which should allow us to implement this eventually |

Warning
Please note this PR may contain hallucinations, and has not been reviewed by a professional developer. Proceed at your own risk!
Overview
Feature Integration
workspace (Cargo.toml:129, crates/epaint/Cargo.toml:42, crates/egui/Cargo.toml:51). By
default nothing changes—Monochrome glyphs remain the fallback.
Color Glyph Rasterization Path
and an optional ColorFont that wraps a swash::scale::ScaleContext plus the raw font
bytes (crates/epaint/src/text/font.rs:188-299).
font.rs:459-477). On a cache miss, the code now:
preferring COLR outlines and color bitmaps (crates/epaint/src/text/font.rs:217-
247).
Color32::from_rgba_unmultiplied and build a UvRect based on the placement offsets
swash gives (crates/epaint/src/text/font.rs:559-591).
glyphs.
monochrome outline path untouched.
Layout and Rendering Adjustments
their vertex color to Color32::WHITE so the texture colors pass through (crates/epaint/
src/text/text_layout.rs:768-915).
skip recoloring those vertex ranges, so text overrides or dark/light theme adjustments
don’t wash out emoji (crates/epaint/src/shape_transform.rs:90-105, crates/epaint/src/
tessellator.rs:2056-2077).
Validation Demo
font (e.g. NotoColorEmoji.ttf), enables the feature at runtime, and renders a label
showing tinted text plus multi-colored emoji, demonstrating that color quads render
correctly while surrounding text keeps its tint.
Net effect: with --features egui/emoji_color, any font that carries COLR/CBDT data (like
Noto Color Emoji) now renders in full color through the standard atlas/mesh pipeline
Running the demo app
wget -O NotoColorEmoji.ttf https://github.com/googlefonts/noto-emoji/raw/main/fonts/NotoColorEmoji.ttf