gpui: Validate font contents at load time.

Piotr Osiewicz created

During layout of EditorElement we use 'm' character from current font to calculate sizes, panicking with fonts that do not have that character (e.g. Arabic fonts). It's not really EditorElement's fault, as it assumes that the font it's dealing with is gonna have that character available.
To prevent a crash, I added validation while loading a family that a given font contains the glyphs we're gonna use down the line.

Change summary

crates/gpui/src/platform/mac/text_system.rs | 3 +++
1 file changed, 3 insertions(+)

Detailed changes

crates/gpui/src/platform/mac/text_system.rs 🔗

@@ -190,6 +190,9 @@ impl MacTextSystemState {
         for font in family.fonts() {
             let mut font = font.load()?;
             open_type::apply_features(&mut font, features);
+            let Some(_) = font.glyph_for_char('m') else {
+                continue;
+            };
             let font_id = FontId(self.fonts.len());
             font_ids.push(font_id);
             let postscript_name = font.postscript_name().unwrap();