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
This commit is contained in:
1 parent
61510b8393
commit
50ead11ccb
1 file changed
+15
-1
@@ -26,6 +26,7 @@ pub struct ParsedFont {
|
||||
pub synthesize_dim: bool,
|
||||
pub assume_emoji_presentation: bool,
|
||||
pub pixel_sizes: Vec<u16>,
|
||||
pub is_built_in_fallback: bool,
|
||||
|
||||
pub harfbuzz_features: Option<Vec<String>>,
|
||||
pub freetype_load_target: Option<FreeTypeLoadTarget>,
|
||||
@@ -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<ParsedFont>) -> 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);
|
||||
}
|
||||
|
||||
|
||||
Reference in new issue
Block a user