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.

Rename all_font_families to all_font_names

Piotr Osiewiczf011953484ae
diff --git a/crates/gpui/src/platform.rs b/crates/gpui/src/platform.rs
index 5a2335919eb..f165cd9c2b5 100644
--- a/crates/gpui/src/platform.rs
+++ b/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>>;
diff --git a/crates/gpui/src/platform/mac/text_system.rs b/crates/gpui/src/platform/mac/text_system.rs
index 68f4a633267..06179e126b6 100644
--- a/crates/gpui/src/platform/mac/text_system.rs
+++ b/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> {
diff --git a/crates/gpui/src/text_system.rs b/crates/gpui/src/text_system.rs
index 24438d8c819..34470aff021 100644
--- a/crates/gpui/src/text_system.rs
+++ b/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;
diff --git a/crates/theme/src/settings.rs b/crates/theme/src/settings.rs
index efc62ed59c4..90c61ce2690 100644
--- a/crates/theme/src/settings.rs
+++ b/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();