diff --git a/src/renderer/fonts/font_options.rs b/src/renderer/fonts/font_options.rs index 782d77792..3856a4f57 100644 --- a/src/renderer/fonts/font_options.rs +++ b/src/renderer/fonts/font_options.rs @@ -192,6 +192,10 @@ impl FontOptions { } pub fn font_list(&self, style: CoarseStyle) -> Vec { + if style == CoarseStyle::default() { + return self.normal.clone(); + } + let fonts = match (style.bold, style.italic) { (true, true) => &self.bold_italic, (true, false) => &self.bold, @@ -199,7 +203,13 @@ impl FontOptions { (false, false) => &None, }; - let fonts = fonts + let normal_fallback = self.normal.iter().map(|font| FontDescription { + // use current requested font style instead of normal + style: style.name().map(str::to_string), + family: font.family.clone(), + }); + + fonts .as_ref() .map(|fonts| { fonts @@ -207,20 +217,15 @@ impl FontOptions { .filter(|font| font.family.is_some()) .map(|font| FontDescription { family: font.family.clone().unwrap(), - style: None, + style: font + .style + .clone() + .or_else(|| style.name().map(str::to_string)), }) - .chain(self.normal.iter().cloned()) + .chain(normal_fallback.clone()) .collect() }) - .unwrap_or_else(|| self.normal.clone()); - - fonts - .into_iter() - .map(|font| FontDescription { - style: style.name().map(str::to_string), - ..font - }) - .collect() + .unwrap_or_else(|| normal_fallback.collect()) } pub fn possible_fonts(&self) -> Vec {