1
1
mirror of https://github.com/wez/wezterm.git synced 2024-11-10 15:04:32 +03:00

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.
This commit is contained in:
Wez Furlong 2022-07-08 21:14:16 -07:00
parent b98fb8410b
commit c97e8e564e
9 changed files with 32 additions and 10 deletions

View File

@ -353,6 +353,8 @@ pub struct FontAttributes {
pub freetype_load_flags: Option<FreeTypeLoadFlags>,
#[dynamic(default)]
pub scale: Option<NotNan<f64>>,
#[dynamic(default)]
pub assume_emoji_presentation: Option<bool>,
}
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,
}
}
}

View File

@ -327,6 +327,8 @@ struct LuaFontAttributes {
pub freetype_load_flags: Option<String>,
#[dynamic(default)]
pub scale: Option<NotNan<f64>>,
#[dynamic(default)]
pub assume_emoji_presentation: Option<bool>,
}
impl<'lua> FromLua<'lua> for LuaFontAttributes {
fn from_lua(value: Value<'lua>, _lua: &'lua Lua) -> Result<Self, mlua::Error> {
@ -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,
}));
}

View File

@ -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)

View File

@ -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*

View File

@ -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

View File

@ -198,6 +198,7 @@ fn build_fallback_list_impl() -> anyhow::Result<Vec<ParsedFont>> {
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() {

View File

@ -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) {

View File

@ -666,6 +666,11 @@ impl ParsedFont {
&& attr.weight < self.weight
&& self.weight >= FontWeight::REGULAR;
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
@ -677,6 +682,8 @@ impl ParsedFont {
{
self.assume_emoji_presentation = true;
}
}
}
self
}

View File

@ -702,6 +702,7 @@ mod test {
freetype_render_target: None,
harfbuzz_features: None,
scale: None,
assume_emoji_presentation: None,
},
14,
)