From dab667ffc4fb5903feb058aff64ff8ba25a6de12 Mon Sep 17 00:00:00 2001 From: Wez Furlong Date: Sun, 15 Dec 2019 15:43:41 -0800 Subject: [PATCH] fonts: locator that only uses wezterm font_dirs config This is useful when checking to make sure that your config works independent of the system fonts. --- src/font/locator/mod.rs | 22 +++++++++++++++++++++- 1 file changed, 21 insertions(+), 1 deletion(-) diff --git a/src/font/locator/mod.rs b/src/font/locator/mod.rs index 8cc83c865..338d393f8 100644 --- a/src/font/locator/mod.rs +++ b/src/font/locator/mod.rs @@ -56,9 +56,16 @@ pub trait FontLocator { #[derive(Debug, Deserialize, Clone, Copy)] pub enum FontLocatorSelection { + /// Use fontconfig APIs to resolve fonts (!macos, posix systems) FontConfig, + /// Use the fontloader crate to use a system specific method of + /// resolving fonts FontLoader, + /// Use the fontkit crate to use a different system specific + /// method of resolving fonts FontKit, + /// Use only the font_dirs configuration to locate fonts + ConfigDirsOnly, } lazy_static::lazy_static! { @@ -87,7 +94,7 @@ impl FontLocatorSelection { } pub fn variants() -> Vec<&'static str> { - vec!["FontConfig", "FontLoader", "FontKit"] + vec!["FontConfig", "FontLoader", "FontKit", "ConfigDirsOnly"] } pub fn new_locator(self) -> Box { @@ -110,6 +117,7 @@ impl FontLocatorSelection { #[cfg(not(any(target_os = "macos", windows)))] panic!("fontkit not compiled in"); } + Self::ConfigDirsOnly => return Box::new(NopSystemSource {}), } } } @@ -121,6 +129,7 @@ impl std::str::FromStr for FontLocatorSelection { "fontconfig" => Ok(Self::FontConfig), "fontloader" => Ok(Self::FontLoader), "fontkit" => Ok(Self::FontKit), + "configdirsonly" => Ok(Self::ConfigDirsOnly), _ => Err(anyhow!( "{} is not a valid FontLocatorSelection variant, possible values are {:?}", s, @@ -129,3 +138,14 @@ impl std::str::FromStr for FontLocatorSelection { } } } + +struct NopSystemSource {} + +impl FontLocator for NopSystemSource { + fn load_fonts( + &self, + _fonts_selection: &[FontAttributes], + ) -> anyhow::Result> { + Ok(vec![]) + } +}