Skip to content

Commit

Permalink
add emoji family for emoji clusters (#56)
Browse files Browse the repository at this point in the history
Quick and dirty fallback for emoji. This can be done more efficiently
(and should be handled in fontique directly) but this should get us
functioning emoji mapping for capable renderers.
  • Loading branch information
dfrg authored May 22, 2024
1 parent 0b62375 commit b2dd9d3
Showing 1 changed file with 13 additions and 2 deletions.
15 changes: 13 additions & 2 deletions src/shape.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ use super::style::{Brush, FontFeature, FontVariation};
use crate::util::nearly_eq;
#[cfg(feature = "std")]
use crate::Font;
#[cfg(feature = "std")]
use fontique::QueryFamily;
use fontique::{self, Attributes, Query, QueryFont};
use swash::shape::*;
#[cfg(feature = "std")]
Expand Down Expand Up @@ -212,7 +214,8 @@ impl<'a, 'b, B: Brush> partition::Selector for FontSelector<'a, 'b, B> {

fn select_font(&mut self, cluster: &mut CharCluster) -> Option<Self::SelectedFont> {
let style_index = cluster.user_data() as u16;
if style_index != self.style_index {
let is_emoji = cluster.info().is_emoji();
if style_index != self.style_index || is_emoji || self.fonts_id.is_none() {
self.style_index = style_index;
let style = &self.styles[style_index as usize].style;
let fonts_id = style.font_stack.id();
Expand All @@ -223,7 +226,15 @@ impl<'a, 'b, B: Brush> partition::Selector for FontSelector<'a, 'b, B> {
};
let variations = self.rcx.variations(style.font_variations).unwrap_or(&[]);
let features = self.rcx.features(style.font_features).unwrap_or(&[]);
if self.fonts_id != Some(fonts_id) {
if is_emoji {
let fonts = self.rcx.stack(style.font_stack).unwrap_or(&[]);
let fonts = fonts.iter().map(|id| QueryFamily::Id(*id));
self.query
.set_families(fonts.chain(core::iter::once(QueryFamily::Generic(
fontique::GenericFamily::Emoji,
))));
self.fonts_id = None;
} else if self.fonts_id != Some(fonts_id) {
let fonts = self.rcx.stack(style.font_stack).unwrap_or(&[]);
self.query.set_families(fonts.iter().copied());
self.fonts_id = Some(fonts_id);
Expand Down

0 comments on commit b2dd9d3

Please sign in to comment.