From 8c77ea1d9eb9e2d059e1d7ba915b79dc2e958fb2 Mon Sep 17 00:00:00 2001 From: Wez Furlong Date: Mon, 14 Aug 2023 20:23:17 -0700 Subject: [PATCH] fonts: allow svg fonts to take precedence over bitmap versions But note that we don't currently render svg refs: https://github.com/wez/wezterm/issues/4148 --- wezterm-font/src/parser.rs | 32 +++++++++++++++++++------------- 1 file changed, 19 insertions(+), 13 deletions(-) diff --git a/wezterm-font/src/parser.rs b/wezterm-font/src/parser.rs index 80ee7ab59..7efba2fd8 100644 --- a/wezterm-font/src/parser.rs +++ b/wezterm-font/src/parser.rs @@ -617,21 +617,27 @@ impl ParsedFont { // Reduce to matching weight candidates.retain(|&idx| fonts[idx].weight == weight); - // Check for best matching pixel strike - if let Some((_distance, idx)) = candidates + // Check for best matching pixel strike, but only if all + // candidates have pixel strikes + if candidates .iter() - .map(|&idx| { - let distance = fonts[idx] - .pixel_sizes - .iter() - .map(|&size| ((pixel_size as i32) - (size as i32)).abs()) - .min() - .unwrap_or(i32::MAX); - (distance, idx) - }) - .min() + .all(|&idx| !fonts[idx].pixel_sizes.is_empty()) { - return Some(idx); + if let Some((_distance, idx)) = candidates + .iter() + .map(|&idx| { + let distance = fonts[idx] + .pixel_sizes + .iter() + .map(|&size| ((pixel_size as i32) - (size as i32)).abs()) + .min() + .unwrap_or(i32::MAX); + (distance, idx) + }) + .min() + { + return Some(idx); + } } // The first one in this set is our best match