diff --git a/wezterm-font/src/db.rs b/wezterm-font/src/db.rs index 82a01994b..047dc6716 100644 --- a/wezterm-font/src/db.rs +++ b/wezterm-font/src/db.rs @@ -20,6 +20,12 @@ impl FontDatabase { fn load_font_info(&mut self, font_info: Vec) { for parsed in font_info { + if let Some(path) = parsed.handle.path_str() { + self.by_full_name + .entry(path.to_string()) + .or_insert_with(Vec::new) + .push(parsed.clone()); + } self.by_full_name .entry(parsed.names().full_name.clone()) .or_insert_with(Vec::new) diff --git a/wezterm-font/src/locator/mod.rs b/wezterm-font/src/locator/mod.rs index d2503ac78..e08221c1e 100644 --- a/wezterm-font/src/locator/mod.rs +++ b/wezterm-font/src/locator/mod.rs @@ -53,6 +53,14 @@ impl FontDataSource { } } + pub fn path_str(&self) -> Option> { + match self { + Self::OnDisk(path) => Some(path.to_string_lossy()), + Self::BuiltIn { .. } => None, + Self::Memory { .. } => None, + } + } + pub fn load_data<'a>(&'a self) -> anyhow::Result> { match self { Self::OnDisk(path) => { @@ -161,6 +169,10 @@ impl FontDataHandle { self.source.name_or_path_str() } + pub fn path_str(&self) -> Option> { + self.source.path_str() + } + pub fn index(&self) -> u32 { self.index } diff --git a/wezterm-font/src/parser.rs b/wezterm-font/src/parser.rs index 18a667187..841d33423 100644 --- a/wezterm-font/src/parser.rs +++ b/wezterm-font/src/parser.rs @@ -453,6 +453,63 @@ impl ParsedFont { FontStyle::Oblique => FontStyle::Oblique, }; + let weight = match weight { + FontWeight::REGULAR => { + let lower = names.full_name.to_lowercase(); + let mut weight = weight; + for (label, candidate) in &[ + ("extrablack", FontWeight::EXTRABLACK), + // must match after other black variants + ("black", FontWeight::BLACK), + ("extrabold", FontWeight::EXTRABOLD), + ("demibold", FontWeight::DEMIBOLD), + // must match after other bold variants + ("bold", FontWeight::BOLD), + ("medium", FontWeight::MEDIUM), + ("book", FontWeight::BOOK), + ("demilight", FontWeight::DEMILIGHT), + ("extralight", FontWeight::EXTRALIGHT), + // must match after other light variants + ("light", FontWeight::LIGHT), + ("thin", FontWeight::THIN), + ] { + if lower.contains(label) { + weight = *candidate; + break; + } + } + weight + } + weight => weight, + }; + + let stretch = match stretch { + FontStretch::Normal => { + let lower = names.full_name.to_lowercase(); + let mut stretch = stretch; + for (label, value) in &[ + ("ultracondensed", FontStretch::UltraCondensed), + ("extracondensed", FontStretch::ExtraCondensed), + ("semicondensed", FontStretch::SemiCondensed), + // must match after other condensed variants + ("condensed", FontStretch::Condensed), + ("semiexpanded", FontStretch::SemiExpanded), + ("extraexpanded", FontStretch::ExtraExpanded), + ("ultraexpanded", FontStretch::UltraExpanded), + // must match after other expanded variants + ("expanded", FontStretch::Expanded), + ] { + if lower.contains(label) { + stretch = *value; + break; + } + } + + stretch + } + stretch => stretch, + }; + Ok(Self { names, weight, @@ -518,6 +575,11 @@ impl ParsedFont { if attr.family == self.names.family { return true; } + if let Some(path) = self.handle.path_str() { + if attr.family == path { + return true; + } + } self.matches_full_or_ps_name(attr) || self.matches_alias(attr) }