From 0a0921f88b4540f2e5cef0686667942bf20a5fa7 Mon Sep 17 00:00:00 2001 From: Piotr Osiewicz <24362066+osiewicz@users.noreply.github.com> Date: Thu, 18 Jan 2024 12:01:10 +0100 Subject: [PATCH] gpui: Bring back family and style names in font name suggestions --- crates/gpui/src/platform.rs | 1 + crates/gpui/src/platform/mac/text_system.rs | 12 +++++++++++- crates/gpui/src/text_system.rs | 19 +++++++++++-------- 3 files changed, 23 insertions(+), 9 deletions(-) diff --git a/crates/gpui/src/platform.rs b/crates/gpui/src/platform.rs index f43e96280f..e08d7a8552 100644 --- a/crates/gpui/src/platform.rs +++ b/crates/gpui/src/platform.rs @@ -201,6 +201,7 @@ pub trait PlatformDispatcher: Send + Sync { pub(crate) trait PlatformTextSystem: Send + Sync { fn add_fonts(&self, fonts: &[Arc>]) -> Result<()>; fn all_font_names(&self) -> Vec; + fn all_font_families(&self) -> Vec; fn font_id(&self, descriptor: &Font) -> Result; fn font_metrics(&self, font_id: FontId) -> FontMetrics; fn typographic_bounds(&self, font_id: FontId, glyph_id: GlyphId) -> Result>; diff --git a/crates/gpui/src/platform/mac/text_system.rs b/crates/gpui/src/platform/mac/text_system.rs index a77741074f..d11efa902a 100644 --- a/crates/gpui/src/platform/mac/text_system.rs +++ b/crates/gpui/src/platform/mac/text_system.rs @@ -85,7 +85,9 @@ impl PlatformTextSystem for MacTextSystem { }; let mut names = BTreeSet::new(); for descriptor in descriptors.into_iter() { - names.insert(descriptor.display_name()); + names.insert(descriptor.font_name()); + names.insert(descriptor.family_name()); + names.insert(descriptor.style_name()); } if let Ok(fonts_in_memory) = self.0.read().memory_source.all_families() { names.extend(fonts_in_memory); @@ -93,6 +95,14 @@ impl PlatformTextSystem for MacTextSystem { names.into_iter().collect() } + fn all_font_families(&self) -> Vec { + self.0 + .read() + .system_source + .all_families() + .expect("core text should never return an error") + } + fn font_id(&self, font: &Font) -> Result { let lock = self.0.upgradable_read(); if let Some(font_id) = lock.font_selections.get(font) { diff --git a/crates/gpui/src/text_system.rs b/crates/gpui/src/text_system.rs index 27d216dd50..1c9de5ea04 100644 --- a/crates/gpui/src/text_system.rs +++ b/crates/gpui/src/text_system.rs @@ -13,7 +13,7 @@ use crate::{ SharedString, Size, UnderlineStyle, }; use anyhow::anyhow; -use collections::{FxHashMap, FxHashSet}; +use collections::{BTreeSet, FxHashMap, FxHashSet}; use core::fmt; use itertools::Itertools; use parking_lot::{Mutex, RwLock, RwLockUpgradableReadGuard}; @@ -66,15 +66,18 @@ impl TextSystem { } pub fn all_font_names(&self) -> Vec { - let mut families = self.platform_text_system.all_font_names(); - families.append( - &mut self - .fallback_font_stack + let mut names: BTreeSet<_> = self + .platform_text_system + .all_font_names() + .into_iter() + .collect(); + names.extend(self.platform_text_system.all_font_families().into_iter()); + names.extend( + self.fallback_font_stack .iter() - .map(|font| font.family.to_string()) - .collect(), + .map(|font| font.family.to_string()), ); - families + names.into_iter().collect() } pub fn add_fonts(&self, fonts: &[Arc>]) -> Result<()> { self.platform_text_system.add_fonts(fonts)