From 8d6274887f03b6621966465fd7a42c7c4b2a61a6 Mon Sep 17 00:00:00 2001 From: Wez Furlong Date: Mon, 19 Oct 2020 22:43:34 -0700 Subject: [PATCH] More fun with font fallback After 41b6c4a5ad45f1ecad7acf7cf4899e53309f51d0, I was able to experience a panic on a linux system. This commit gives us one last fallback to plain ? glyphs. --- wezterm/src/font/shaper/harfbuzz.rs | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/wezterm/src/font/shaper/harfbuzz.rs b/wezterm/src/font/shaper/harfbuzz.rs index 2f53964b4..927466a9f 100644 --- a/wezterm/src/font/shaper/harfbuzz.rs +++ b/wezterm/src/font/shaper/harfbuzz.rs @@ -58,12 +58,26 @@ fn make_question_string(s: &str) -> String { use unicode_segmentation::UnicodeSegmentation; let len = s.graphemes(true).count(); let mut result = String::new(); + let c = if !is_question_string(s) { + std::char::REPLACEMENT_CHARACTER + } else { + '?' + }; for _ in 0..len { - result.push(std::char::REPLACEMENT_CHARACTER); + result.push(c); } result } +fn is_question_string(s: &str) -> bool { + for c in s.chars() { + if c != std::char::REPLACEMENT_CHARACTER { + return false; + } + } + true +} + impl HarfbuzzShaper { pub fn new(handles: &[FontDataHandle]) -> anyhow::Result { let lib = ftwrap::Library::new()?;