From 50ead11ccb67daadfa112fbd321a0120c16cae0a Mon Sep 17 00:00:00 2001 From: Wez Furlong Date: Sun, 19 Jun 2022 06:54:22 -0700 Subject: [PATCH] fonts: assume emoji presentation based on name wezterm makes two passes over fonts when resolving emoji, based on the presentation of the text. If the text has a defined presentation via a variation selector, then the first pass will only consider fonts that match that presentation. If no fonts match, a second pass is made to locate any font with the appropriate glyphs. Previously, the font was assumed to have emoji presentation if it had color glyphs. That meant that if you chose a monochrome emoji font then it would be skipped for regular emoji presentation and we'd end up matching against the default fallback for the Noto Color Emoji font. This commit changes the behavior to consider any explicitly listed font with "Emoji" in the name as having emoji presentation. This is also an imperfect heuristic, but perhaps it is good enough? refs: #1959 --- wezterm-font/src/parser.rs | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/wezterm-font/src/parser.rs b/wezterm-font/src/parser.rs index 00ede3782..65a858f15 100644 --- a/wezterm-font/src/parser.rs +++ b/wezterm-font/src/parser.rs @@ -26,6 +26,7 @@ pub struct ParsedFont { pub synthesize_dim: bool, pub assume_emoji_presentation: bool, pub pixel_sizes: Vec, + pub is_built_in_fallback: bool, pub harfbuzz_features: Option>, pub freetype_load_target: Option, @@ -76,6 +77,7 @@ impl Clone for ParsedFont { freetype_load_target: self.freetype_load_target, freetype_render_target: self.freetype_render_target, freetype_load_flags: self.freetype_load_flags, + is_built_in_fallback: self.is_built_in_fallback, scale: self.scale, } } @@ -403,6 +405,7 @@ impl ParsedFont { synthesize_italic: false, synthesize_bold: false, synthesize_dim: false, + is_built_in_fallback: false, assume_emoji_presentation, handle, coverage: Mutex::new(RangeSet::new()), @@ -662,6 +665,16 @@ impl ParsedFont { self.synthesize_dim = attr.weight < FontWeight::REGULAR && attr.weight < self.weight && self.weight >= FontWeight::REGULAR; + + // If they explicitly list an emoji font, assume that they + // want it to be used for emoji presentation + if !self.is_built_in_fallback + && !attr.is_synthetic + && self.names.full_name.to_lowercase().contains("emoji") + { + self.assume_emoji_presentation = true; + } + self } } @@ -716,7 +729,8 @@ pub(crate) fn load_built_in_fonts(font_info: &mut Vec) -> anyhow::Re coverage: None, }; let face = lib.face_from_locator(&locator)?; - let parsed = ParsedFont::from_face(&face, locator)?; + let mut parsed = ParsedFont::from_face(&face, locator)?; + parsed.is_built_in_fallback = true; font_info.push(parsed); }