Skip to content

Commit

Permalink
cosmic_text: Handle variation selectors; fix emoji colors (#12587)
Browse files Browse the repository at this point in the history
Basically, we detect if a glyph is a variation selector if its `id` is 3
(i.e. a whitespace character) and if it comes from an emoji font (since
variation selectors are only used for emoji glyphs).

- Fixes #11703 and
#12022

Release Notes:

- N/A
  • Loading branch information
apricotbucket28 committed Jun 3, 2024
1 parent 726f23e commit ed86b86
Showing 1 changed file with 16 additions and 2 deletions.
18 changes: 16 additions & 2 deletions crates/gpui/src/platform/cosmic_text/text_system.rs
Original file line number Diff line number Diff line change
Expand Up @@ -314,7 +314,7 @@ impl CosmicTextSystemState {
let bitmap_size = glyph_bounds.size;
let font = &self.loaded_fonts_store[params.font_id.0];
let font_system = &mut self.font_system;
let image = self
let mut image = self
.swash_cache
.get_image(
font_system,
Expand All @@ -330,6 +330,13 @@ impl CosmicTextSystemState {
.clone()
.unwrap();

if params.is_emoji {
// Convert from RGBA to BGRA.
for pixel in image.data.chunks_exact_mut(4) {
pixel.swap(0, 2);
}
}

Ok((bitmap_size, image.data))
}
}
Expand Down Expand Up @@ -394,13 +401,20 @@ impl CosmicTextSystemState {
for glyph in &layout.glyphs {
let font_id = glyph.font_id;
let font_id = self.font_id_for_cosmic_id(font_id);
let is_emoji = self.is_emoji(font_id);
let mut glyphs = SmallVec::new();

// HACK: Prevent crash caused by variation selectors.
if glyph.glyph_id == 3 && is_emoji {
continue;
}

// todo(linux) this is definitely wrong, each glyph in glyphs from cosmic-text is a cluster with one glyph, ShapedRun takes a run of glyphs with the same font and direction
glyphs.push(ShapedGlyph {
id: GlyphId(glyph.glyph_id as u32),
position: point((glyph.x).into(), glyph.y.into()),
index: glyph.start,
is_emoji: self.is_emoji(font_id),
is_emoji,
});

runs.push(crate::ShapedRun { font_id, glyphs });
Expand Down

0 comments on commit ed86b86

Please sign in to comment.