diff --git a/src/config.rs b/src/config.rs index d017ad307..6dfeebc04 100644 --- a/src/config.rs +++ b/src/config.rs @@ -194,25 +194,27 @@ impl TextStyle { } } - fn add_fallback(&mut self) { + pub fn font_with_fallback(&self) -> Vec { + let mut font = self.font.clone(); #[cfg(target_os = "macos")] - self.font.push(FontAttributes { + font.push(FontAttributes { family: "Apple Color Emoji".into(), bold: None, italic: None, }); #[cfg(target_os = "macos")] - self.font.push(FontAttributes { + font.push(FontAttributes { family: "Apple Symbols".into(), bold: None, italic: None, }); #[cfg(windows)] - self.font.push(FontAttributes { + font.push(FontAttributes { family: "Segoe UI".into(), bold: None, italic: None, }); + font } } @@ -328,8 +330,6 @@ impl Config { }); } - cfg.font.add_fallback(); - cfg } } diff --git a/src/font/fontconfigandfreetype.rs b/src/font/fontconfigandfreetype.rs index 4e1af8711..8154ea6c0 100644 --- a/src/font/fontconfigandfreetype.rs +++ b/src/font/fontconfigandfreetype.rs @@ -19,16 +19,17 @@ impl FontConfigAndFreeType { impl FontSystem for FontConfigAndFreeType { fn load_font(&self, config: &Config, style: &TextStyle) -> Result, Error> { - let mut pattern = if style.font.len() >= 1 { + let fonts = style.font_with_fallback(); + let mut pattern = if fonts.len() >= 1 { let mut pattern = FontPattern::new()?; - if style.font.len() > 1 { + if fonts.len() > 1 { eprintln!( "FIXME: fontconfig loader currently only processes the first in your set of fonts for {:?}", style ); } - let attr = &style.font[0]; + let attr = &fonts[0]; pattern.family(&attr.family)?; if *attr.bold.as_ref().unwrap_or(&false) { pattern.add_integer("weight", 200)?; diff --git a/src/font/fontloader.rs b/src/font/fontloader.rs index 27298988c..c6091e6b8 100644 --- a/src/font/fontloader.rs +++ b/src/font/fontloader.rs @@ -7,7 +7,7 @@ pub fn load_system_fonts( style: &TextStyle, ) -> Result, i32)>, Error> { let mut fonts = Vec::new(); - for font_attr in &style.font { + for font_attr in style.font_with_fallback() { let mut font_props = system_fonts::FontPropertyBuilder::new() .family(&font_attr.family) .monospace();