mirror of
https://github.com/wez/wezterm.git
synced 2024-12-23 21:32:13 +03:00
font-config: fall back to searching by postscript name
Our first pass is to match based on the overall constraints supplied by the user, but if that fails, we fall back to looking up by postscript name.
This commit is contained in:
parent
16e7457049
commit
0694e905e8
@ -310,7 +310,6 @@ impl Pattern {
|
||||
}
|
||||
|
||||
pub fn list(&self) -> anyhow::Result<FontSet> {
|
||||
log::trace!("listing: {:?}", self);
|
||||
unsafe {
|
||||
// This defines the fields that are retrieved
|
||||
let oset = FcObjectSetCreate();
|
||||
|
@ -23,8 +23,7 @@ impl FontLocator for FontConfigFontLocator {
|
||||
) -> anyhow::Result<Vec<ParsedFont>> {
|
||||
let mut fonts = vec![];
|
||||
|
||||
for attr in fonts_selection {
|
||||
for &spacing in &SPACING {
|
||||
fn by_family(attr: &FontAttributes, spacing: i32) -> anyhow::Result<FontPattern> {
|
||||
let mut pattern = FontPattern::new()?;
|
||||
let start = std::time::Instant::now();
|
||||
pattern.family(&attr.family)?;
|
||||
@ -50,7 +49,41 @@ impl FontLocator for FontConfigFontLocator {
|
||||
start.elapsed(),
|
||||
best
|
||||
);
|
||||
Ok(best)
|
||||
}
|
||||
|
||||
fn by_postscript(attr: &FontAttributes, _spacing: i32) -> anyhow::Result<FontPattern> {
|
||||
let mut pattern = FontPattern::new()?;
|
||||
let start = std::time::Instant::now();
|
||||
pattern.add_string("postscriptname", &attr.family)?;
|
||||
let matches = pattern.list()?;
|
||||
for best in matches.iter() {
|
||||
log::trace!(
|
||||
"listing by postscriptname took {:?} to compute and is {:?}",
|
||||
start.elapsed(),
|
||||
best
|
||||
);
|
||||
return Ok(best);
|
||||
}
|
||||
|
||||
log::trace!(
|
||||
"listing by postscriptname took {:?} to compute and produced no results",
|
||||
start.elapsed(),
|
||||
);
|
||||
anyhow::bail!("no match for postscript name");
|
||||
}
|
||||
|
||||
for attr in fonts_selection {
|
||||
for &spacing in &SPACING {
|
||||
if loaded.contains(&attr) {
|
||||
continue;
|
||||
}
|
||||
|
||||
// First, we assume that attr.family is the family name.
|
||||
// If that doesn't work, we try by postscript name.
|
||||
for resolver in &[by_family, by_postscript] {
|
||||
match resolver(attr, spacing) {
|
||||
Ok(best) => {
|
||||
let file = best.get_file()?;
|
||||
let index = best.get_integer("index")? as u32;
|
||||
let variation = index >> 16;
|
||||
@ -72,6 +105,10 @@ impl FontLocator for FontConfigFontLocator {
|
||||
}
|
||||
}
|
||||
}
|
||||
Err(err) => log::trace!("while searching for {:?}: {:#}", attr, err),
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Ok(fonts)
|
||||
|
Loading…
Reference in New Issue
Block a user