Try to load fallback fonts instead of panicking when a font is not found (#3891)

This PR adjusts our font resolution code to attempt to use a fallback
font if the specified font cannot be found.

Right now our fallback font stack is `Zed Mono`, followed by `Helvetica`
(in practice we should always be able to resolve `Zed Mono` since we
bundle it with the app).

In the future we'll want to surface the ability to set the fallback font
stack from GPUI consumers, and potentially even support specifying font
stacks in the user settings (as opposed to a single font family).

Release Notes:

- Fixed a panic when trying to load a font that could not be found.
This commit is contained in:
Marshall Bowers 2024-01-04 14:10:46 -05:00 committed by GitHub
parent 3d1023ef52
commit e4aa7ba4f2
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 41 additions and 6 deletions

View file

@ -421,7 +421,7 @@ impl TerminalElement {
let rem_size = cx.rem_size();
let font_pixels = text_style.font_size.to_pixels(rem_size);
let line_height = font_pixels * line_height.to_pixels(rem_size);
let font_id = cx.text_system().font_id(&text_style.font()).unwrap();
let font_id = cx.text_system().resolve_font(&text_style.font());
// todo!(do we need to keep this unwrap?)
let cell_width = text_system