From c97e8e564eb31fba057f0becde424814502c5bea Mon Sep 17 00:00:00 2001 From: Wez Furlong Date: Fri, 8 Jul 2022 21:14:16 -0700 Subject: [PATCH] fonts: allow setting assume_emoji_presentation per font This allows the user to specify what happens if they have an emoji font that doesn't match our built-in heuristics. --- config/src/font.rs | 5 ++++ config/src/lua.rs | 4 +++ docs/changelog.md | 1 + docs/config/lua/wezterm/font.md | 1 + docs/config/lua/wezterm/font_with_fallback.md | 1 + wezterm-font/src/locator/core_text.rs | 1 + wezterm-font/src/locator/gdi.rs | 1 + wezterm-font/src/parser.rs | 27 ++++++++++++------- wezterm-font/src/shaper/harfbuzz.rs | 1 + 9 files changed, 32 insertions(+), 10 deletions(-) diff --git a/config/src/font.rs b/config/src/font.rs index f7134c721..ca3132786 100644 --- a/config/src/font.rs +++ b/config/src/font.rs @@ -353,6 +353,8 @@ pub struct FontAttributes { pub freetype_load_flags: Option, #[dynamic(default)] pub scale: Option>, + #[dynamic(default)] + pub assume_emoji_presentation: Option, } impl_lua_conversion_dynamic!(FontAttributes); @@ -380,6 +382,7 @@ impl FontAttributes { freetype_render_target: None, freetype_load_flags: None, scale: None, + assume_emoji_presentation: None, } } @@ -396,6 +399,7 @@ impl FontAttributes { freetype_render_target: None, freetype_load_flags: None, scale: None, + assume_emoji_presentation: None, } } } @@ -414,6 +418,7 @@ impl Default for FontAttributes { freetype_render_target: None, freetype_load_flags: None, scale: None, + assume_emoji_presentation: None, } } } diff --git a/config/src/lua.rs b/config/src/lua.rs index 7f7bfd2be..7884d2b33 100644 --- a/config/src/lua.rs +++ b/config/src/lua.rs @@ -327,6 +327,8 @@ struct LuaFontAttributes { pub freetype_load_flags: Option, #[dynamic(default)] pub scale: Option>, + #[dynamic(default)] + pub assume_emoji_presentation: Option, } impl<'lua> FromLua<'lua> for LuaFontAttributes { fn from_lua(value: Value<'lua>, _lua: &'lua Lua) -> Result { @@ -415,6 +417,7 @@ fn font<'lua>( None => None, }, scale: attrs.scale, + assume_emoji_presentation: attrs.assume_emoji_presentation, })); Ok(text_style) @@ -465,6 +468,7 @@ fn font_with_fallback<'lua>( None => None, }, scale: attrs.scale, + assume_emoji_presentation: attrs.assume_emoji_presentation, })); } diff --git a/docs/changelog.md b/docs/changelog.md index fbb2f3482..b4ab8ca37 100644 --- a/docs/changelog.md +++ b/docs/changelog.md @@ -20,6 +20,7 @@ As features stabilize some brief notes about them will accumulate here. * [window:get_selection_escapes_for_pane](config/lua/window/get_selection_escapes_for_pane.md) method for getting the current selection including escape sequences. [#2223](https://github.com/wez/wezterm/issues/2223) * New [wezterm.gui](config/lua/wezterm.gui/index.md) module and [mux_window:gui_window](config/lua/mux-window/gui_window.md) method. * You may now use [wezterm.format](config/lua/wezterm/format.md) (or otherwise use strings with escape sequences) in the labels of the [Launcher Menu](config/launch.md#the-launcher-menu). +* You may now specify `assume_emoji_presentation = true` (or `false`) in [wezterm.font()](config/lua/wezterm/font.md) and [wezterm.font_with_fallback()](config/lua/wezterm/font_with_fallback.md) #### Fixed * [ActivateKeyTable](config/lua/keyassignment/ActivateKeyTable.md)'s `replace_current` field was not actually optional. Made it optional. [#2179](https://github.com/wez/wezterm/issues/2179) diff --git a/docs/config/lua/wezterm/font.md b/docs/config/lua/wezterm/font.md index e42556c86..626b0da5b 100644 --- a/docs/config/lua/wezterm/font.md +++ b/docs/config/lua/wezterm/font.md @@ -93,6 +93,7 @@ The following options can be specified in the same way: * [freetype_load_target](../config/freetype_load_target.md) * [freetype_render_target](../config/freetype_render_target.md) * [freetype_load_flags](../config/freetype_load_flags.md) +* `assume_emoji_presentation = true` or `assume_emoji_presentation = false` to control whether a font is considered to have emoji (rather than text) presentation glyphs for emoji. (*Since: nightly builds only) *Since: 20220319-142410-0fcdea07* diff --git a/docs/config/lua/wezterm/font_with_fallback.md b/docs/config/lua/wezterm/font_with_fallback.md index 18a6ef051..3c870bcdb 100644 --- a/docs/config/lua/wezterm/font_with_fallback.md +++ b/docs/config/lua/wezterm/font_with_fallback.md @@ -65,6 +65,7 @@ The following options can be specified in the same way: * [freetype_load_target](../config/freetype_load_target.md) * [freetype_render_target](../config/freetype_render_target.md) * [freetype_load_flags](../config/freetype_load_flags.md) +* `assume_emoji_presentation = true` or `assume_emoji_presentation = false` to control whether a font is considered to have emoji (rather than text) presentation glyphs for emoji. (*Since: nightly builds only) ## Dealing with different fallback font heights diff --git a/wezterm-font/src/locator/core_text.rs b/wezterm-font/src/locator/core_text.rs index 24b3a3a04..f879f974b 100644 --- a/wezterm-font/src/locator/core_text.rs +++ b/wezterm-font/src/locator/core_text.rs @@ -198,6 +198,7 @@ fn build_fallback_list_impl() -> anyhow::Result> { freetype_render_target: None, freetype_load_flags: None, scale: None, + assume_emoji_presentation: None, }; if let Ok(descriptors) = descriptor_from_attr(&symbols) { for descriptor in descriptors.iter() { diff --git a/wezterm-font/src/locator/gdi.rs b/wezterm-font/src/locator/gdi.rs index 51c186a65..949a29350 100644 --- a/wezterm-font/src/locator/gdi.rs +++ b/wezterm-font/src/locator/gdi.rs @@ -328,6 +328,7 @@ impl FontLocator for GdiFontLocator { freetype_render_target: None, freetype_load_flags: None, scale: None, + assume_emoji_presentation: None, }; if !resolved.contains(&attr) { diff --git a/wezterm-font/src/parser.rs b/wezterm-font/src/parser.rs index 86e1cb29a..59d321837 100644 --- a/wezterm-font/src/parser.rs +++ b/wezterm-font/src/parser.rs @@ -666,16 +666,23 @@ impl ParsedFont { && 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. - // We match on "moji" rather than "emoji" as there are - // emoji fonts that are moji rather than emoji :-/ - // This heuristic is awful, TBH. - if !self.is_built_in_fallback - && !attr.is_synthetic - && self.names.full_name.to_lowercase().contains("moji") - { - self.assume_emoji_presentation = true; + match attr.assume_emoji_presentation { + Some(assume) => { + self.assume_emoji_presentation = assume; + } + None => { + // If they explicitly list an emoji font, assume that they + // want it to be used for emoji presentation. + // We match on "moji" rather than "emoji" as there are + // emoji fonts that are moji rather than emoji :-/ + // This heuristic is awful, TBH. + if !self.is_built_in_fallback + && !attr.is_synthetic + && self.names.full_name.to_lowercase().contains("moji") + { + self.assume_emoji_presentation = true; + } + } } self diff --git a/wezterm-font/src/shaper/harfbuzz.rs b/wezterm-font/src/shaper/harfbuzz.rs index bb131b506..2cd142ecc 100644 --- a/wezterm-font/src/shaper/harfbuzz.rs +++ b/wezterm-font/src/shaper/harfbuzz.rs @@ -702,6 +702,7 @@ mod test { freetype_render_target: None, harfbuzz_features: None, scale: None, + assume_emoji_presentation: None, }, 14, )