From 4fc8dfb37433e213a26fac5755a40dd0672e8617 Mon Sep 17 00:00:00 2001 From: Wez Furlong Date: Tue, 17 Aug 2021 22:00:27 -0700 Subject: [PATCH] fonts: retry fallback with no presentation if we hit last resort The introduction of the Emoji vs Text VS processing means that we might in some cases not find a glyph with the requested presentation. In that case, we'd rather show the emoji presentation glyph than none at all, so we'll retry fallback processing with unspecified presentation. refs: #997 --- wezterm-font/src/lib.rs | 1 + wezterm-font/src/shaper/harfbuzz.rs | 17 +++++++++++++++++ 2 files changed, 18 insertions(+) diff --git a/wezterm-font/src/lib.rs b/wezterm-font/src/lib.rs index ab15e51ed..35ec972ed 100644 --- a/wezterm-font/src/lib.rs +++ b/wezterm-font/src/lib.rs @@ -109,6 +109,7 @@ impl LoadedFont { presentation, ); + no_glyphs.retain(|&c| c != '\u{FE0F}' && c != '\u{FE0E}'); filter_out_synthetic(&mut no_glyphs); if !no_glyphs.is_empty() { diff --git a/wezterm-font/src/shaper/harfbuzz.rs b/wezterm-font/src/shaper/harfbuzz.rs index 836a18190..b16cefb43 100644 --- a/wezterm-font/src/shaper/harfbuzz.rs +++ b/wezterm-font/src/shaper/harfbuzz.rs @@ -186,6 +186,7 @@ impl HarfbuzzShaper { let cell_width; let shaped_any; + let initial_font_idx = font_idx; loop { match self.load_fallback(font_idx).context("load_fallback")? { @@ -225,6 +226,22 @@ impl HarfbuzzShaper { for c in s.chars() { no_glyphs.push(c); } + + if presentation.is_some() { + // We hit the last resort and we have an explicit presentation. + // This is a little awkward; we want to record the missing + // glyphs so that we can resolve them async, but we also + // want to try the current set of fonts without forcing + // the presentation match as we might find the results + // that way. + // Let's restart the shape but pretend that no specific + // presentation was used. + // We'll probably match the emoji presentation for something, + // but might potentially discover the text presentation for + // that glyph in a fallback font and swap it out a little + // later after a flash of showing the emoji one. + return self.do_shape(initial_font_idx, s, font_size, dpi, no_glyphs, None); + } } let hb_infos = buf.glyph_infos();