Draw colored glyphs in iced_tiny_skia

This commit is contained in:
Héctor Ramón Jiménez 2023-09-19 22:28:28 +02:00
parent a9ee8f62fd
commit 9af0a27e67
No known key found for this signature in database
GPG key ID: 7CC46565708259A7

View file

@ -188,7 +188,7 @@ fn draw(
if let Some((buffer, placement)) = glyph_cache.allocate( if let Some((buffer, placement)) = glyph_cache.allocate(
physical_glyph.cache_key, physical_glyph.cache_key,
color, glyph.color_opt.map(from_color).unwrap_or(color),
font_system, font_system,
&mut swash, &mut swash,
) { ) {
@ -213,6 +213,12 @@ fn draw(
} }
} }
fn from_color(color: cosmic_text::Color) -> Color {
let [r, g, b, a] = color.as_rgba();
Color::from_rgba8(r, g, b, a as f32 / 255.0)
}
#[derive(Debug, Clone, Default)] #[derive(Debug, Clone, Default)]
struct GlyphCache { struct GlyphCache {
entries: FxHashMap< entries: FxHashMap<