diff --git a/wezterm/src/font/locator/font_loader.rs b/wezterm/src/font/locator/font_loader.rs index e657af696..8af09b7ba 100644 --- a/wezterm/src/font/locator/font_loader.rs +++ b/wezterm/src/font/locator/font_loader.rs @@ -45,8 +45,16 @@ impl FontLocator for FontLoaderFontLocator { index: index as u32, name: font_attr.family.clone(), }; - fonts.push(handle); - loaded.insert(font_attr.clone()); + + // The system may just decide to give us its fallback, + // eg: Consolas, so we need to parse the returned font + // here to see if we got what we asked for. + if let Ok(parsed) = crate::font::parser::ParsedFont::from_locator(&handle) { + if crate::font::parser::font_info_matches(font_attr, parsed.names()) { + fonts.push(handle); + loaded.insert(font_attr.clone()); + } + } } } Ok(fonts) diff --git a/wezterm/src/font/parser.rs b/wezterm/src/font/parser.rs index 5e3c11749..aa1e7cc9e 100644 --- a/wezterm/src/font/parser.rs +++ b/wezterm/src/font/parser.rs @@ -465,7 +465,7 @@ fn collect_font_info( Ok(()) } -fn font_info_matches(attr: &FontAttributes, names: &Names) -> bool { +pub fn font_info_matches(attr: &FontAttributes, names: &Names) -> bool { if attr.family == names.full_name { true } else if let Some(fam) = names.family.as_ref() { @@ -473,9 +473,10 @@ fn font_info_matches(attr: &FontAttributes, names: &Names) -> bool { // this is a pretty rough approximation if attr.family == *fam { match names.sub_family.as_ref().map(String::as_str) { - Some("Italic") if attr.italic => true, - Some("Bold") if attr.bold => true, - Some("Regular") | None => true, + Some("Italic") if attr.italic && !attr.bold => true, + Some("Bold") if attr.bold && !attr.italic => true, + Some("Bold Italic") if attr.bold && attr.italic => true, + Some("Regular") | None if !attr.italic && !attr.bold => true, _ => false, } } else {