1
1
mirror of https://github.com/wez/wezterm.git synced 2024-12-23 13:21:38 +03:00

font: consider "random" glyphs when computing metrics for symbol fonts

If a font doesn't have any latin glyphs then we'd compute 0 as the
average width.  Later, during rendering, we'd compute an `inf` scaling
factor and then subsequently fail to allocate texture space.

This commit takes the average width from a "random" selection of glyphs
(whatever the first few glyphs in the font may be) to avoid that
situation.

refs: https://github.com/wez/wezterm/issues/404
This commit is contained in:
Wez Furlong 2020-12-28 09:02:30 -08:00
parent 7cbbb49ab4
commit 4d8cc1bb26
2 changed files with 20 additions and 0 deletions

View File

@ -34,6 +34,7 @@ brief notes about them may accumulate here.
* Tidied up logging. Previously ERROR level logging was used to make sure that informational things showed up in the stderr stream. Now we use INFO level logging for this to avoid alarming the user. You can set `WEZTERM_LOG=trace` in the environment to get more verbose logging for troubleshooting purposes.
* Windows: fix an issue where VNC-server-emulated AltGr was not treated as AltGr [#392](https://github.com/wez/wezterm/issues/392)
* X11: fix an issue where keys that produce unicode characters retained SHIFT as a modifier instead of normalizing it away. [#394](https://github.com/wez/wezterm/issues/394)
* Fixed an issue where a symbol-only font would be seen as 0-width and panic wezterm [#404](https://github.com/wez/wezterm/issues/404)
### 20201101-103216-403d002d

View File

@ -221,6 +221,25 @@ impl Face {
}
}
}
if width == 0.0 {
// Most likely we're looking at a symbol font with no latin
// glyphs at all. Let's just pick a selection of glyphs
for glyph_pos in 1..8 {
let res = FT_Load_Glyph(self.face, glyph_pos, FT_LOAD_COLOR as i32);
if succeeded(res) {
let glyph = &(*(*self.face).glyph);
if glyph.metrics.horiAdvance as f64 > width {
width = glyph.metrics.horiAdvance as f64;
}
}
}
if width == 0.0 {
log::error!(
"Couldn't find any glyphs for metrics, so guessing width == height"
);
width = height * 64.;
}
}
(width / 64.0, height)
}
}