1
1
mirror of https://github.com/wez/wezterm.git synced 2024-12-23 21:32:13 +03:00

Allow disabling re-sorting fallback fonts

The system locator may have a reasonable default ordering
in its list of fallbacks.

refs: #685
This commit is contained in:
Wez Furlong 2021-04-12 08:03:17 -07:00
parent 6f1664addd
commit 5ced58c37b
2 changed files with 24 additions and 8 deletions

View File

@ -1061,6 +1061,9 @@ pub struct Config {
#[serde(default = "default_true")]
pub warn_about_missing_glyphs: bool,
#[serde(default)]
pub sort_fallback_fonts_by_coverage: bool,
}
impl_lua_conversion!(Config);

View File

@ -251,15 +251,28 @@ impl FontConfigInner {
for c in no_glyphs {
wanted.add(c as u32);
}
log::trace!(
"Fallback fonts that match {} before sorting are: {:#?}",
fallback_str.escape_unicode(),
extra_handles
);
if wanted.len() > 1 && config.sort_fallback_fonts_by_coverage {
// Sort by ascending coverage
extra_handles.sort_by_cached_key(|p| {
p.coverage_intersection(&wanted)
.map(|r| r.len())
.unwrap_or(0)
});
// Re-arrange to descending coverage
extra_handles.reverse();
log::trace!(
"Fallback fonts that match {} after sorting are: {:#?}",
fallback_str.escape_unicode(),
extra_handles
);
}
// Sort by ascending coverage
extra_handles.sort_by_cached_key(|p| {
p.coverage_intersection(&wanted)
.map(|r| r.len())
.unwrap_or(0)
});
// Re-arrange to descending coverage
extra_handles.reverse();
// iteratively reduce to just the fonts that we need
extra_handles.retain(|p| match p.coverage_intersection(&wanted) {
Ok(cov) if cov.is_empty() => false,