You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
What currently happens is in epaint, glyphs are rasterized here. This sets an opacity value for each glyph pixel. Then eventually the wgpu renderer takes the FontImage and converts it to sRGBA pixels here.
The COLR and CPAL tables are used in OpenType fonts to enable coloring of emojis. ttf-parser has a method for checking whether a glyph has coloring data called Face::is_color_glyph(GlyphId). It also has a method called Face::paint_color_glyph (here)
This tells the colr::Painter trait how to paint the current glyph.
I propose the following:
We need to make an implementation of Painter called ColorRasterizer. Calling paint_color_glyph using ColorRasterizer will store each method as a command, similar to VecPainter and will also compute the glyph's bounding box. It will support an additional function draw(FnMut(u32, u32, u8, u8, u8, u8)) which will play back the commands to rasterize the glyph within it's bounding box, using the closure to write the RGBa value to the pixel coordinate.
pub struct FontImage {
/// width, height
pub size: [usize; 2],
/// The coverage value.
///
/// Often you want to use [`Self::srgba_pixels`] instead.
pub pixels: Vec<f32>,
+
+ pub colors: Option<Vec<[u8; 3]>>,
}
This adds an optional colors Vec which holds the rgb values for each pixel in the FontImage. We exclude alpha because that is already captured in pixels.
Then FontImage::srgba_pixels would be modified to check if colors.is_some(), and if so, use them for Color32::from_rgba_premultiplied. Otherwise, use the previous implementation.
The text was updated successfully, but these errors were encountered:
kernelkind
changed the title
support color emoji ttf fonts
egui support color emoji ttf fonts
Dec 20, 2024
The following is a proposal for getting color emoji font support directly in egui. It's purpose would be to complete
what we have now
What currently happens is in
epaint
, glyphs are rasterized here. This sets an opacity value for each glyph pixel. Then eventually thewgpu
renderer takes theFontImage
and converts it to sRGBA pixels here.The COLR and CPAL tables are used in OpenType fonts to enable coloring of emojis.
ttf-parser
has a method for checking whether a glyph has coloring data calledFace::is_color_glyph(GlyphId)
. It also has a method calledFace::paint_color_glyph
(here)This tells the
colr::Painter
trait how to paint the current glyph.I propose the following:
We need to make an implementation of
Painter
calledColorRasterizer
. Callingpaint_color_glyph
usingColorRasterizer
will store each method as a command, similar toVecPainter
and will also compute the glyph's bounding box. It will support an additional functiondraw(FnMut(u32, u32, u8, u8, u8, u8))
which will play back the commands to rasterize the glyph within it's bounding box, using the closure to write the RGBa value to the pixel coordinate.In
egui
add the following here:Then in
FontImage
we can add the following:This adds an optional
colors
Vec which holds the rgb values for each pixel in theFontImage
. We exclude alpha because that is already captured inpixels
.Then
FontImage::srgba_pixels
would be modified to check ifcolors.is_some()
, and if so, use them forColor32::from_rgba_premultiplied
. Otherwise, use the previous implementation.The text was updated successfully, but these errors were encountered: