mirror of
https://github.com/wez/wezterm.git
synced 2024-12-25 14:22:37 +03:00
windows: properly fallback to JetBrains Mono
The default font locator on Windows is font-loader. That will always return *something* that matched, even if it didn't match what we asked for very well. This is problematic if for example we asked for "JetBrains Mono" and that isn't installed. font-loader will return the data for "Consolas". That's great if there is no other fallback mechanism, but it prevented us from searching our built-in fonts. This commit parsed the returned font and uses the same font family matching that we use for our own font directory searching to see if it matched well enough. This commit also tidies up that matching routine so that it more carefully matches sub-family characteristics such as bold, italic and bold-italic.
This commit is contained in:
parent
370c3fbd4d
commit
c32de40978
@ -45,10 +45,18 @@ impl FontLocator for FontLoaderFontLocator {
|
|||||||
index: index as u32,
|
index: index as u32,
|
||||||
name: font_attr.family.clone(),
|
name: font_attr.family.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);
|
fonts.push(handle);
|
||||||
loaded.insert(font_attr.clone());
|
loaded.insert(font_attr.clone());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
Ok(fonts)
|
Ok(fonts)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -465,7 +465,7 @@ fn collect_font_info(
|
|||||||
Ok(())
|
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 {
|
if attr.family == names.full_name {
|
||||||
true
|
true
|
||||||
} else if let Some(fam) = names.family.as_ref() {
|
} 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
|
// this is a pretty rough approximation
|
||||||
if attr.family == *fam {
|
if attr.family == *fam {
|
||||||
match names.sub_family.as_ref().map(String::as_str) {
|
match names.sub_family.as_ref().map(String::as_str) {
|
||||||
Some("Italic") if attr.italic => true,
|
Some("Italic") if attr.italic && !attr.bold => true,
|
||||||
Some("Bold") if attr.bold => true,
|
Some("Bold") if attr.bold && !attr.italic => true,
|
||||||
Some("Regular") | None => true,
|
Some("Bold Italic") if attr.bold && attr.italic => true,
|
||||||
|
Some("Regular") | None if !attr.italic && !attr.bold => true,
|
||||||
_ => false,
|
_ => false,
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
|
Loading…
Reference in New Issue
Block a user