From 72214b7db969634dcb2e19e99ef0c826ddca44bb Mon Sep 17 00:00:00 2001 From: Wez Furlong Date: Mon, 28 Mar 2022 19:32:00 -0700 Subject: [PATCH] Disable ligatures for Menlo and Monaco refs: https://github.com/wez/wezterm/issues/1736 refs: https://github.com/wez/wezterm/issues/1786 --- config/src/lua.rs | 92 +++++++++++++++++++++++++++++------------------ docs/changelog.md | 1 + 2 files changed, 59 insertions(+), 34 deletions(-) diff --git a/config/src/lua.rs b/config/src/lua.rs index 80096b18f..9c6ce5146 100644 --- a/config/src/lua.rs +++ b/config/src/lua.rs @@ -529,6 +529,24 @@ impl<'lua> FromLua<'lua> for LuaFontAttributes { } } +/// On macOS, both Menlo and Monaco fonts have ligatures for `fi` that +/// take effect for words like `find` and which are a source of +/// confusion/annoyance and issues filed on Github. +/// Let's default to disabling ligatures for these fonts unless +/// the user has explicitly specified harfbuzz_features. +/// +/// +fn disable_ligatures_for_menlo_or_monaco(mut attrs: FontAttributes) -> FontAttributes { + if attrs.harfbuzz_features.is_none() && (attrs.family == "Menlo" || attrs.family == "Monaco") { + attrs.harfbuzz_features = Some(vec![ + "kern".to_string(), + "clig".to_string(), + "liga=0".to_string(), + ]); + } + attrs +} + /// Given a simple font family name, returns a text style instance. /// The second optional argument is a list of the other TextStyle /// fields, which at the time of writing includes only the @@ -556,22 +574,26 @@ fn font<'lua>( text_style.foreground = map_defaults.foreground; } - text_style.font.push(FontAttributes { - family: attrs.family, - stretch: attrs.stretch, - weight: attrs.weight, - style: attrs.style, - is_fallback: false, - is_synthetic: false, - harfbuzz_features: attrs.harfbuzz_features, - freetype_load_target: attrs.freetype_load_target, - freetype_render_target: attrs.freetype_render_target, - freetype_load_flags: match attrs.freetype_load_flags { - Some(flags) => Some(TryFrom::try_from(flags).map_err(|e| mlua::Error::external(e))?), - None => None, - }, - scale: attrs.scale, - }); + text_style + .font + .push(disable_ligatures_for_menlo_or_monaco(FontAttributes { + family: attrs.family, + stretch: attrs.stretch, + weight: attrs.weight, + style: attrs.style, + is_fallback: false, + is_synthetic: false, + harfbuzz_features: attrs.harfbuzz_features, + freetype_load_target: attrs.freetype_load_target, + freetype_render_target: attrs.freetype_render_target, + freetype_load_flags: match attrs.freetype_load_flags { + Some(flags) => { + Some(TryFrom::try_from(flags).map_err(|e| mlua::Error::external(e))?) + } + None => None, + }, + scale: attrs.scale, + })); Ok(text_style) } @@ -602,24 +624,26 @@ fn font_with_fallback<'lua>( text_style.foreground = map_defaults.foreground; } - text_style.font.push(FontAttributes { - family: attrs.family, - stretch: attrs.stretch, - weight: attrs.weight, - style: attrs.style, - is_fallback: idx != 0, - is_synthetic: false, - harfbuzz_features: attrs.harfbuzz_features, - freetype_load_target: attrs.freetype_load_target, - freetype_render_target: attrs.freetype_render_target, - freetype_load_flags: match attrs.freetype_load_flags { - Some(flags) => { - Some(TryFrom::try_from(flags).map_err(|e| mlua::Error::external(e))?) - } - None => None, - }, - scale: attrs.scale, - }); + text_style + .font + .push(disable_ligatures_for_menlo_or_monaco(FontAttributes { + family: attrs.family, + stretch: attrs.stretch, + weight: attrs.weight, + style: attrs.style, + is_fallback: idx != 0, + is_synthetic: false, + harfbuzz_features: attrs.harfbuzz_features, + freetype_load_target: attrs.freetype_load_target, + freetype_render_target: attrs.freetype_render_target, + freetype_load_flags: match attrs.freetype_load_flags { + Some(flags) => { + Some(TryFrom::try_from(flags).map_err(|e| mlua::Error::external(e))?) + } + None => None, + }, + scale: attrs.scale, + })); } Ok(text_style) diff --git a/docs/changelog.md b/docs/changelog.md index 3aca7d8b5..a6fd44fc4 100644 --- a/docs/changelog.md +++ b/docs/changelog.md @@ -13,6 +13,7 @@ As features stabilize some brief notes about them will accumulate here. #### New #### Changed +* Disabled ligatures for `"Monaco"` and `"Menlo"` fonts, as those ligatures match even for words such as `find`. [#1786](https://github.com/wez/wezterm/issues/1786) [#1736](https://github.com/wez/wezterm/issues/1736) #### Updated and Improved * Bundled harfbuzz to 4.1.0 * On macOS, non-native fullscreen mode now attempts to avoid the notch on systems that have one. [#1737](https://github.com/wez/wezterm/issues/1737)