From af815a2e1b3dd7c68a3f3dda40272a7516cefa60 Mon Sep 17 00:00:00 2001 From: Wez Furlong Date: Thu, 9 Jun 2022 20:09:47 -0700 Subject: [PATCH] fonts: add freetype_pcf_long_family_names option Freetype has a compile-time feature that, when enabled, rewrites the font names of PCF fonts to include the foundry and wide status of the font in order to disambiguate the various versions of fonts all named "Fixed". That option is enabled by default in some linux distributions but not all; it's not enabled in Fedora, for example. When that feature is enabled it causes problems for the Terminus font as the PCF version of the fonts are no longer resolvable via the simple "Terminus" name but via "xos4 Terminus" instead. wezterm builds its own version of freetype (for consistency and cross platform support reasons), and is unaware of the choice used by the distro. The result of that is that fontconfig may see PCF fonts as having different font names than how wezterm sees them. A concrete problem is on such a system, when requesting "xos4 Terminus", fontconfig will present a match with that name, but when wezterm opens the font and sees that it has name "Terminus" (because of the difference in this feature in the freetype libraries in use), wezterm will reject that match. This commit enables that option in the freetype library and adds a wezterm config level option (freetype_pcf_long_family_names) that can be used to control the underlying pcf font driver configuration. The upshot of this is that this commit doesn't change any default behavior, but allows users of those systems to set `freetype_pcf_long_family_names = true` to turn that behavior on. My personal opinion on this is that users probably shouldn't use this if they can avoid it (and PCF fonts in general), and instead install the OTB version of the Terminus font, which doesn't have this legacy baggage associated with it! refs: https://github.com/wez/wezterm/issues/2100 --- config/src/config.rs | 3 +++ deps/freetype/build.rs | 4 ++++ wezterm-font/src/ftwrap.rs | 16 ++++++++++++++++ 3 files changed, 23 insertions(+) diff --git a/config/src/config.rs b/config/src/config.rs index 140a037ef..bd4a8c01f 100644 --- a/config/src/config.rs +++ b/config/src/config.rs @@ -191,6 +191,9 @@ pub struct Config { /// See https://freetype.org/freetype2/docs/subpixel-hinting.html pub freetype_interpreter_version: Option, + #[dynamic(default)] + pub freetype_pcf_long_family_names: bool, + /// Specify the features to enable when using harfbuzz for font shaping. /// There is some light documentation here: /// diff --git a/deps/freetype/build.rs b/deps/freetype/build.rs index 1fbbe42d8..d701272cc 100644 --- a/deps/freetype/build.rs +++ b/deps/freetype/build.rs @@ -147,6 +147,10 @@ fn freetype() { "#define TT_CONFIG_OPTION_SUBPIXEL_HINTING 2", "#define TT_CONFIG_OPTION_SUBPIXEL_HINTING 3", ) + .replace( + "/* #define PCF_CONFIG_OPTION_LONG_FAMILY_NAMES */", + "#define PCF_CONFIG_OPTION_LONG_FAMILY_NAMES", + ) .replace( "/* #define FT_CONFIG_OPTION_SUBPIXEL_RENDERING */", "#define FT_CONFIG_OPTION_SUBPIXEL_RENDERING", diff --git a/wezterm-font/src/ftwrap.rs b/wezterm-font/src/ftwrap.rs index b99e557e0..5590a1ef0 100644 --- a/wezterm-font/src/ftwrap.rs +++ b/wezterm-font/src/ftwrap.rs @@ -860,6 +860,22 @@ impl Library { } } + { + let no_long_names: FT_Bool = if config.freetype_pcf_long_family_names { + 0 + } else { + 1 + }; + unsafe { + FT_Property_Set( + lib.lib, + b"pcf\0" as *const u8 as *const FT_String, + b"no-long-family-names\0" as *const u8 as *const FT_String, + &no_long_names as *const FT_Bool as *const _, + ); + } + } + // Due to patent concerns, the freetype library disables the LCD // filtering feature by default, and since we always build our // own copy of freetype, it is likewise disabled by default for