Skip to content

armgit / zed

Public Imported from GitHub
0

Code at the speed of thought – Zed is a high-performance, multiplayer code editor from the creators of Atom and Tree-sitter.

Allow loading "Segoe Fluent Icons" font on macOS (#9421)

Marshall Bowers0329b4a5cb1d
diff --git a/crates/gpui/src/platform/mac/text_system.rs b/crates/gpui/src/platform/mac/text_system.rs
index 083e9cc1d89..d5bb7230127 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 504a849d20e..4f478878500 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;