fix locating Hasklig
The root cause of this was that I'd added a fontformat=TrueType
constraint to the fontconfig pattern and since fontconfig has
fontformat=CFF for Hasklig, it wasn't the primary font candidate.
When I cut out redundant fontconfig checks in
ee1d84829a it meant that we'd never
"see" the hasklig result that turns up ~20 or so fonts into the
fallback list.
This commit removes the TrueType constraint so that the results
are ranked correctly again.
I've also switched the main font lookup path to using an alternative
font config API that returns only the best match as that more closely
aligns our intent in this function; originally, fallback was intended
to be handled in this code path, but these days it has its own separate
method.
closes: https://github.com/wez/wezterm/issues/383
refs: https://github.com/wez/wezterm/issues/379
This commit is contained in:
1 parent
c6a55cd3b2
commit
dc83c6de2a
2 files changed
+32
-35
No files matched your search
@@ -321,6 +321,18 @@ impl Pattern {
|
||||
}
|
||||
}
|
||||
|
||||
pub fn get_best_match(&self) -> Result<Self, Error> {
|
||||
unsafe {
|
||||
let mut res = FcResultWrap(0);
|
||||
let best = FcFontMatch(ptr::null_mut(), self.pat, &mut res.0 as *mut _);
|
||||
|
||||
if !best.is_null() {
|
||||
add_object();
|
||||
}
|
||||
Ok(Pattern { pat: best })
|
||||
}
|
||||
}
|
||||
|
||||
pub fn sort(&self, trim: bool) -> Result<FontSet, Error> {
|
||||
unsafe {
|
||||
let mut res = FcResultWrap(0);
|
||||
|
||||
@@ -20,51 +20,37 @@ impl FontLocator for FontConfigFontLocator {
|
||||
|
||||
for attr in fonts_selection {
|
||||
let mut pattern = FontPattern::new()?;
|
||||
let start = std::time::Instant::now();
|
||||
pattern.family(&attr.family)?;
|
||||
pattern.add_integer("weight", if attr.bold { 200 } else { 80 })?;
|
||||
pattern.add_integer("slant", if attr.italic { 100 } else { 0 })?;
|
||||
pattern.add_string("fontformat", "TrueType")?;
|
||||
/*
|
||||
pattern.add_double("size", config.font_size * font_scale)?;
|
||||
pattern.add_double("dpi", config.dpi)?;
|
||||
*/
|
||||
pattern.monospace()?;
|
||||
log::trace!("fc pattern before config subst: {:?}", pattern);
|
||||
pattern.config_substitute(fcwrap::MatchKind::Pattern)?;
|
||||
pattern.default_substitute();
|
||||
// and obtain the selection with the best preference
|
||||
// at index 0.
|
||||
let start = std::time::Instant::now();
|
||||
let font_list = pattern.sort(true)?;
|
||||
|
||||
let best = pattern.get_best_match()?;
|
||||
log::trace!(
|
||||
"query font-config for {:?} took {:?}",
|
||||
pattern,
|
||||
start.elapsed()
|
||||
"best match took {:?} to compute and is {:?}",
|
||||
start.elapsed(),
|
||||
best
|
||||
);
|
||||
|
||||
for pat in font_list.iter() {
|
||||
pattern.render_prepare(&pat)?;
|
||||
let file = pat.get_file()?;
|
||||
let file = best.get_file()?;
|
||||
let handle = FontDataHandle::OnDisk {
|
||||
path: file.into(),
|
||||
index: best.get_integer("index")?.try_into()?,
|
||||
};
|
||||
|
||||
let handle = FontDataHandle::OnDisk {
|
||||
path: file.into(),
|
||||
index: pat.get_integer("index")?.try_into()?,
|
||||
};
|
||||
|
||||
// fontconfig will give us a boatload of random fallbacks.
|
||||
// so we need to parse the returned font
|
||||
// here to see if we got what we asked for.
|
||||
if let Ok(parsed) = crate::parser::ParsedFont::from_locator(&handle) {
|
||||
if crate::parser::font_info_matches(attr, parsed.names()) {
|
||||
fonts.push(handle);
|
||||
loaded.insert(attr.clone());
|
||||
log::trace!("found font-config match for {:?}", parsed.names());
|
||||
}
|
||||
// fontconfig will give us a boatload of random fallbacks.
|
||||
// so we need to parse the returned font
|
||||
// here to see if we got what we asked for.
|
||||
if let Ok(parsed) = crate::parser::ParsedFont::from_locator(&handle) {
|
||||
if crate::parser::font_info_matches(attr, parsed.names()) {
|
||||
fonts.push(handle);
|
||||
loaded.insert(attr.clone());
|
||||
log::trace!("found font-config match for {:?}", parsed.names());
|
||||
}
|
||||
|
||||
// If the first result from font-config isn't a match, then stop looking.
|
||||
// font-config can return many fallback fonts. We don't want any of those
|
||||
// at this stage.
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -82,7 +68,6 @@ impl FontLocator for FontConfigFontLocator {
|
||||
|
||||
let mut pattern = FontPattern::new()?;
|
||||
pattern.add_charset(&charset)?;
|
||||
pattern.add_string("fontformat", "TrueType")?;
|
||||
pattern.add_integer("weight", 80)?;
|
||||
pattern.add_integer("slant", 0)?;
|
||||
|
||||
|
||||
Reference in new issue
Block a user