Rename all_font_families to all_font_names

Piotr Osiewicz created

Change summary

crates/gpui/src/platform.rs                 |  2 +-
crates/gpui/src/platform/mac/text_system.rs | 18 +++++++++++-------
crates/gpui/src/text_system.rs              |  5 ++---
crates/theme/src/settings.rs                |  2 +-
4 files changed, 15 insertions(+), 12 deletions(-)

Detailed changes

crates/gpui/src/platform.rs 🔗

@@ -192,7 +192,7 @@ pub trait PlatformDispatcher: Send + Sync {
 
 pub trait PlatformTextSystem: Send + Sync {
     fn add_fonts(&self, fonts: &[Arc<Vec<u8>>]) -> Result<()>;
-    fn all_font_families(&self) -> Vec<String>;
+    fn all_font_names(&self) -> Vec<String>;
     fn font_id(&self, descriptor: &Font) -> Result<FontId>;
     fn font_metrics(&self, font_id: FontId) -> FontMetrics;
     fn typographic_bounds(&self, font_id: FontId, glyph_id: GlyphId) -> Result<Bounds<f32>>;

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

@@ -5,7 +5,7 @@ use crate::{
 };
 use anyhow::anyhow;
 use cocoa::appkit::{CGFloat, CGPoint};
-use collections::HashMap;
+use collections::{BTreeSet, HashMap};
 use core_foundation::{
     array::CFIndex,
     attributed_string::{CFAttributedStringRef, CFMutableAttributedString},
@@ -78,12 +78,16 @@ impl PlatformTextSystem for MacTextSystem {
         self.0.write().add_fonts(fonts)
     }
 
-    fn all_font_families(&self) -> Vec<String> {
-        self.0
-            .read()
-            .system_source
-            .all_families()
-            .expect("core text should never return an error")
+    fn all_font_names(&self) -> Vec<String> {
+        let collection = core_text::font_collection::create_for_all_families();
+        let Some(descriptors) = collection.get_descriptors() else {
+            return vec![];
+        };
+        let mut names = BTreeSet::new();
+        for descriptor in descriptors.into_iter() {
+            names.insert(descriptor.display_name());
+        }
+        names.into_iter().collect()
     }
 
     fn font_id(&self, font: &Font) -> Result<FontId> {

crates/gpui/src/text_system.rs 🔗

@@ -65,8 +65,8 @@ impl TextSystem {
         }
     }
 
-    pub fn all_font_families(&self) -> Vec<String> {
-        let mut families = self.platform_text_system.all_font_families();
+    pub fn all_font_names(&self) -> Vec<String> {
+        let mut families = self.platform_text_system.all_font_names();
         families.append(
             &mut self
                 .fallback_font_stack
@@ -101,7 +101,6 @@ impl TextSystem {
         if let Ok(font_id) = self.font_id(font) {
             return font_id;
         }
-
         for fallback in &self.fallback_font_stack {
             if let Ok(font_id) = self.font_id(fallback) {
                 return font_id;

crates/theme/src/settings.rs 🔗

@@ -205,7 +205,7 @@ impl settings::Settings for ThemeSettings {
 
         let available_fonts = cx
             .text_system()
-            .all_font_families()
+            .all_font_names()
             .into_iter()
             .map(Value::String)
             .collect();