From 6cee020c892905083041907756ec998167a1dd3d Mon Sep 17 00:00:00 2001 From: Wez Furlong Date: Sun, 18 Oct 2020 10:08:04 -0700 Subject: [PATCH] linux/freebsd: avoid random fontconfig fallbacks This is the same class of problem as c32de40978099066e94c85b0d07fe926a52a8997 but on X11/Wayland systems. In this case, the 100 or so "random" fontconfig fallbacks were taking precedence over our locally configured emoji fallback. This commit filters the fontconfig results to more exact matches, with less surprising results. This may come at the cost of magically resolving fallback fonts for unusual scripts, however. --- wezterm/src/font/locator/font_config.rs | 19 +++++++++---------- 1 file changed, 9 insertions(+), 10 deletions(-) diff --git a/wezterm/src/font/locator/font_config.rs b/wezterm/src/font/locator/font_config.rs index 52ffb53b7..8d5bffa0d 100644 --- a/wezterm/src/font/locator/font_config.rs +++ b/wezterm/src/font/locator/font_config.rs @@ -34,7 +34,7 @@ impl FontLocator for FontConfigFontLocator { // at index 0. let font_list = pattern.sort(true)?; - for (idx, pat) in font_list.iter().enumerate() { + for pat in font_list.iter() { pattern.render_prepare(&pat)?; let file = pat.get_file()?; @@ -43,15 +43,14 @@ impl FontLocator for FontConfigFontLocator { index: pat.get_integer("index")?.try_into()?, }; - // When it comes to handling fallback, we prefer our - // user specified set of names so we take those first. - // The additional items in this loop are fallback fonts - // suggested by fontconfig and are lower precedence - if idx == 0 { - fonts.push(handle); - loaded.insert(attr.clone()); - } else { - fallback.push(handle); + // 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::font::parser::ParsedFont::from_locator(&handle) { + if crate::font::parser::font_info_matches(attr, parsed.names()) { + fonts.push(handle); + loaded.insert(attr.clone()); + } } } }