From e1e9fb5215daa9dbd40998e16210a6ee3a61ff1f Mon Sep 17 00:00:00 2001 From: Lucas Timmins Date: Sat, 20 May 2023 02:05:52 +0800 Subject: [PATCH 1/2] Fallback to monospaced font if Monospace family is not found --- src/font/fallback/mod.rs | 14 ++++++++++++++ 1 file changed, 14 insertions(+) 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); + } } } From f0becfdb5403a68d4bacb045b7e057f8a9d28b37 Mon Sep 17 00:00:00 2001 From: Jeremy Soller Date: Thu, 8 Jun 2023 12:32:34 -0600 Subject: [PATCH 2/2] Fix comment typo --- src/font/fallback/mod.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/font/fallback/mod.rs b/src/font/fallback/mod.rs index bf4575d..2440e89 100644 --- a/src/font/fallback/mod.rs +++ b/src/font/fallback/mod.rs @@ -131,7 +131,7 @@ impl<'a> Iterator for FontFallbackIter<'a> { monospace_fallback = Some(id); } } - // If default family is Monospace allback to first monospaced font + // If default family is Monospace fallback to first monospaced font if let Some(id) = monospace_fallback { if let Some(font) = self.font_system.get_font(*id) { return Some(font);