diff --git a/src/font/fallback/mod.rs b/src/font/fallback/mod.rs index 410dfac..bf4575d 100644 --- a/src/font/fallback/mod.rs +++ b/src/font/fallback/mod.rs @@ -112,6 +112,7 @@ impl<'a> Iterator for FontFallbackIter<'a> { fn next(&mut self) -> Option { while self.default_i < self.default_families.len() { self.default_i += 1; + let mut monospace_fallback = None; for id in self.font_ids.iter() { let default_family = self .font_system @@ -122,6 +123,19 @@ impl<'a> Iterator for FontFallbackIter<'a> { return Some(font); } } + // Set a monospace fallback if Monospace family is not found + if self.default_families[self.default_i - 1] == &Family::Monospace + && self.font_system.db().face(*id).map(|f| f.monospaced) == Some(true) + && monospace_fallback.is_none() + { + monospace_fallback = Some(id); + } + } + // If default family is Monospace allback to first monospaced font + if let Some(id) = monospace_fallback { + if let Some(font) = self.font_system.get_font(*id) { + return Some(font); + } } }