Rename all_font_families to all_font_names

This commit is contained in:
Piotr Osiewicz 2024-01-16 20:12:16 +01:00
parent ca4a8b2226
commit f011953484
4 changed files with 15 additions and 12 deletions

View file

@ -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>>;

View file

@ -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> {

View file

@ -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;

View file

@ -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();