Skip to content

Commit

Permalink
fix: use pre-defined font weights only if user does not specify one (n…
Browse files Browse the repository at this point in the history
…eovide#2710)

* fix: Force fallback font style to predefined except normal style

* fix test fail
  • Loading branch information
xzbdmw authored Jul 16, 2024
1 parent f561452 commit 85ccb73
Showing 1 changed file with 17 additions and 12 deletions.
29 changes: 17 additions & 12 deletions src/renderer/fonts/font_options.rs
Original file line number Diff line number Diff line change
Expand Up @@ -192,35 +192,40 @@ impl FontOptions {
}

pub fn font_list(&self, style: CoarseStyle) -> Vec<FontDescription> {
if style == CoarseStyle::default() {
return self.normal.clone();
}

let fonts = match (style.bold, style.italic) {
(true, true) => &self.bold_italic,
(true, false) => &self.bold,
(false, true) => &self.italic,
(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
.iter()
.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<FontDescription> {
Expand Down

0 comments on commit 85ccb73

Please sign in to comment.