From 48dd57ab9f2f381e66d590e002ce11620ee03fc3 Mon Sep 17 00:00:00 2001 From: Wez Furlong Date: Sun, 19 Dec 2021 11:07:53 -0700 Subject: [PATCH] fonts: speculative fix for Monaco.dfont bitmap/render error The error message in this issue sounds a lot like the freetype regression that caused bitmap fonts to fail to render in a recent freetype release. Our workaround for that is to used our understanding of whether a font is a bitmap font or not to avoid calling render. What we normally see for bitmap TTFs is that setting the scale fails and we then fall back to using a bitmap. For Monaco.dfont it appears as though setting the scale succeeds. This commit introduces some skepticism and prefers to use bitmaps when available. This might potentially cause problems in the future if there are fonts that legitimately have both scaled and bitmap fonts, but lets see if this helps for now. refs: https://github.com/wez/wezterm/issues/1419 --- wezterm-font/src/ftwrap.rs | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/wezterm-font/src/ftwrap.rs b/wezterm-font/src/ftwrap.rs index fe47c3a45..00b10014b 100644 --- a/wezterm-font/src/ftwrap.rs +++ b/wezterm-font/src/ftwrap.rs @@ -555,6 +555,12 @@ impl Face { if (*self.face).height == 0 { anyhow::bail!("font has 0 height, fallback to bitmaps"); } + if (*self.face).num_fixed_sizes > 0 { + anyhow::bail!( + "font has bitmaps but also allowed FT_Set_Char_Size to succeed... \ + not trusting it and falling back to bitmaps" + ); + } } Ok(()) @@ -612,8 +618,12 @@ impl Face { } } - ft_result(FT_Render_Glyph(slot, render_mode), ()) - .context("load_and_render_glyph: FT_Render_Glyph")?; + ft_result(FT_Render_Glyph(slot, render_mode), ()).with_context(|| { + format!( + "load_and_render_glyph: FT_Render_Glyph render_mode={:?}", + render_mode + ) + })?; Ok(slot) } }