gpui: Bring back family and style names in font name suggestions
This commit is contained in:
parent
5d6af532d9
commit
0a0921f88b
3 changed files with 23 additions and 9 deletions
|
@ -201,6 +201,7 @@ pub trait PlatformDispatcher: Send + Sync {
|
||||||
pub(crate) trait PlatformTextSystem: Send + Sync {
|
pub(crate) trait PlatformTextSystem: Send + Sync {
|
||||||
fn add_fonts(&self, fonts: &[Arc<Vec<u8>>]) -> Result<()>;
|
fn add_fonts(&self, fonts: &[Arc<Vec<u8>>]) -> Result<()>;
|
||||||
fn all_font_names(&self) -> Vec<String>;
|
fn all_font_names(&self) -> Vec<String>;
|
||||||
|
fn all_font_families(&self) -> Vec<String>;
|
||||||
fn font_id(&self, descriptor: &Font) -> Result<FontId>;
|
fn font_id(&self, descriptor: &Font) -> Result<FontId>;
|
||||||
fn font_metrics(&self, font_id: FontId) -> FontMetrics;
|
fn font_metrics(&self, font_id: FontId) -> FontMetrics;
|
||||||
fn typographic_bounds(&self, font_id: FontId, glyph_id: GlyphId) -> Result<Bounds<f32>>;
|
fn typographic_bounds(&self, font_id: FontId, glyph_id: GlyphId) -> Result<Bounds<f32>>;
|
||||||
|
|
|
@ -85,7 +85,9 @@ impl PlatformTextSystem for MacTextSystem {
|
||||||
};
|
};
|
||||||
let mut names = BTreeSet::new();
|
let mut names = BTreeSet::new();
|
||||||
for descriptor in descriptors.into_iter() {
|
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() {
|
if let Ok(fonts_in_memory) = self.0.read().memory_source.all_families() {
|
||||||
names.extend(fonts_in_memory);
|
names.extend(fonts_in_memory);
|
||||||
|
@ -93,6 +95,14 @@ impl PlatformTextSystem for MacTextSystem {
|
||||||
names.into_iter().collect()
|
names.into_iter().collect()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn all_font_families(&self) -> Vec<String> {
|
||||||
|
self.0
|
||||||
|
.read()
|
||||||
|
.system_source
|
||||||
|
.all_families()
|
||||||
|
.expect("core text should never return an error")
|
||||||
|
}
|
||||||
|
|
||||||
fn font_id(&self, font: &Font) -> Result<FontId> {
|
fn font_id(&self, font: &Font) -> Result<FontId> {
|
||||||
let lock = self.0.upgradable_read();
|
let lock = self.0.upgradable_read();
|
||||||
if let Some(font_id) = lock.font_selections.get(font) {
|
if let Some(font_id) = lock.font_selections.get(font) {
|
||||||
|
|
|
@ -13,7 +13,7 @@ use crate::{
|
||||||
SharedString, Size, UnderlineStyle,
|
SharedString, Size, UnderlineStyle,
|
||||||
};
|
};
|
||||||
use anyhow::anyhow;
|
use anyhow::anyhow;
|
||||||
use collections::{FxHashMap, FxHashSet};
|
use collections::{BTreeSet, FxHashMap, FxHashSet};
|
||||||
use core::fmt;
|
use core::fmt;
|
||||||
use itertools::Itertools;
|
use itertools::Itertools;
|
||||||
use parking_lot::{Mutex, RwLock, RwLockUpgradableReadGuard};
|
use parking_lot::{Mutex, RwLock, RwLockUpgradableReadGuard};
|
||||||
|
@ -66,15 +66,18 @@ impl TextSystem {
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn all_font_names(&self) -> Vec<String> {
|
pub fn all_font_names(&self) -> Vec<String> {
|
||||||
let mut families = self.platform_text_system.all_font_names();
|
let mut names: BTreeSet<_> = self
|
||||||
families.append(
|
.platform_text_system
|
||||||
&mut self
|
.all_font_names()
|
||||||
.fallback_font_stack
|
.into_iter()
|
||||||
|
.collect();
|
||||||
|
names.extend(self.platform_text_system.all_font_families().into_iter());
|
||||||
|
names.extend(
|
||||||
|
self.fallback_font_stack
|
||||||
.iter()
|
.iter()
|
||||||
.map(|font| font.family.to_string())
|
.map(|font| font.family.to_string()),
|
||||||
.collect(),
|
|
||||||
);
|
);
|
||||||
families
|
names.into_iter().collect()
|
||||||
}
|
}
|
||||||
pub fn add_fonts(&self, fonts: &[Arc<Vec<u8>>]) -> Result<()> {
|
pub fn add_fonts(&self, fonts: &[Arc<Vec<u8>>]) -> Result<()> {
|
||||||
self.platform_text_system.add_fonts(fonts)
|
self.platform_text_system.add_fonts(fonts)
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue