From 332b0faeaa94de63d29646585ab5c7b3ee83c92b Mon Sep 17 00:00:00 2001 From: Wez Furlong Date: Fri, 22 Feb 2019 15:51:36 -0800 Subject: [PATCH] CoreText renderer is now the default on macOS I've added dingbats to the fallback list on macos as that is needed for some symbols we use in tools at work. With that, and some tweaks for allowing for missing letter glyphs when loading a symbol font as a fallback, we can make that the default for macOS Closes https://github.com/wez/wezterm/issues/5 --- src/config.rs | 6 ++++++ src/font/coretext.rs | 7 ++++--- src/font/mod.rs | 10 ++++++---- 3 files changed, 16 insertions(+), 7 deletions(-) diff --git a/src/config.rs b/src/config.rs index 6dfeebc04..c872c9d5c 100644 --- a/src/config.rs +++ b/src/config.rs @@ -208,6 +208,12 @@ impl TextStyle { bold: None, italic: None, }); + #[cfg(target_os = "macos")] + font.push(FontAttributes { + family: "Zapf Dingbats".into(), + bold: None, + italic: None, + }); #[cfg(windows)] font.push(FontAttributes { family: "Segoe UI".into(), diff --git a/src/font/coretext.rs b/src/font/coretext.rs index 7a3214ac1..e655e1ba7 100644 --- a/src/font/coretext.rs +++ b/src/font/coretext.rs @@ -108,7 +108,7 @@ fn glyph_index(ct_font: &CTFont, codepoint: char) -> Option { } } -#[derive(Debug)] +#[derive(Debug, Default)] struct Metrics { font_metrics: FontMetrics, ascent: f64, @@ -150,8 +150,9 @@ impl CoreTextFontImpl { let w_metrics = metrics('W', &ct_font); let m_metrics = metrics('M', &ct_font); let zero_metrics = metrics('0', &ct_font); - let metrics = - w_metrics.unwrap_or_else(|| m_metrics.unwrap_or_else(|| zero_metrics.unwrap())); + let metrics = w_metrics.unwrap_or_else(|| { + m_metrics.unwrap_or_else(|| zero_metrics.unwrap_or_else(|| Default::default())) + }); Self { ct_font, hb_font, diff --git a/src/font/mod.rs b/src/font/mod.rs index 902c58722..793903c2d 100644 --- a/src/font/mod.rs +++ b/src/font/mod.rs @@ -58,10 +58,12 @@ impl Default for FontSystemSelection { not(feature = "force-rusttype") )) { FontSystemSelection::FontConfigAndFreeType - } else if cfg!(not(feature = "force-rusttype")) { - FontSystemSelection::FontLoaderAndFreeType - } else { + } else if cfg!(feature = "force-rusttype") { FontSystemSelection::FontLoaderAndRustType + } else if cfg!(target_os = "macos") { + FontSystemSelection::CoreText + } else { + FontSystemSelection::FontLoaderAndFreeType } } } @@ -104,7 +106,7 @@ impl std::str::FromStr for FontSystemSelection { fn from_str(s: &str) -> Result { match s.to_lowercase().as_ref() { "fontconfigandfreetype" => Ok(FontSystemSelection::FontConfigAndFreeType), - "fontloadandfreetype" => Ok(FontSystemSelection::FontLoaderAndFreeType), + "fontloaderandfreetype" => Ok(FontSystemSelection::FontLoaderAndFreeType), "fontloaderandrusttype" => Ok(FontSystemSelection::FontLoaderAndRustType), "coretext" => Ok(FontSystemSelection::CoreText), _ => Err(format_err!(