diff --git a/crates/gpui/src/platform/mac/text_system.rs b/crates/gpui/src/platform/mac/text_system.rs index 083e9cc1d89ced19c6b0e43e9d8adb13f429a8b7..d5bb7230127927c0cd16e489af07d3bce5f2901f 100644 --- a/crates/gpui/src/platform/mac/text_system.rs +++ b/crates/gpui/src/platform/mac/text_system.rs @@ -233,9 +233,34 @@ impl MacTextSystemState { let mut font = font.load()?; open_type::apply_features(&mut font, features); - let Some(_) = font.glyph_for_char('m') else { - continue; - }; + + // This block contains a precautionary fix to guard against loading fonts + // that might cause panics due to `.unwrap()`s up the chain. + { + // We use the 'm' character for text measurements in various spots + // (e.g., the editor). However, at time of writing some of those usages + // will panic if the font has no 'm' glyph. + // + // Therefore, we check up front that the font has the necessary glyph. + let has_m_glyph = font.glyph_for_char('m').is_some(); + + // HACK: The 'Segoe Fluent Icons' font does not have an 'm' glyph, + // but we need to be able to load it for rendering Windows icons in + // the Storybook (on macOS). + let is_segoe_fluent_icons = font.full_name() == "Segoe Fluent Icons"; + + if !has_m_glyph && !is_segoe_fluent_icons { + // I spent far too long trying to track down why a font missing the 'm' + // character wasn't loading. This log statement will hopefully save + // someone else from suffering the same fate. + log::warn!( + "font '{}' has no 'm' character and was not loaded", + font.full_name() + ); + continue; + } + } + // We've seen a number of panics in production caused by calling font.properties() // which unwraps a downcast to CFNumber. This is an attempt to avoid the panic, // and to try and identify the incalcitrant font. diff --git a/crates/ui/src/components/title_bar/windows_window_controls.rs b/crates/ui/src/components/title_bar/windows_window_controls.rs index 504a849d20e3168d8745340c559a17a4cc10a83e..4f478878500e91cb18ea955f6bbb2d0da1587188 100644 --- a/crates/ui/src/components/title_bar/windows_window_controls.rs +++ b/crates/ui/src/components/title_bar/windows_window_controls.rs @@ -45,8 +45,6 @@ impl RenderOnce for WindowsWindowControls { .content_stretch() .max_h(self.button_height) .min_h(self.button_height) - .font("Segoe Fluent Icons") - .text_size(px(10.0)) .child(WindowsCaptionButton::new( "minimize", WindowsCaptionButtonIcon::Minimize, @@ -110,6 +108,8 @@ impl RenderOnce for WindowsCaptionButton { .content_center() .w(width) .h_full() + .font("Segoe Fluent Icons") + .text_size(px(10.0)) .hover(|style| style.bg(self.hover_background_color)) .active(|style| { let mut active_color = self.hover_background_color;