Rename all_font_families to all_font_names
This commit is contained in:
parent
ca4a8b2226
commit
f011953484
4 changed files with 15 additions and 12 deletions
|
@ -192,7 +192,7 @@ pub trait PlatformDispatcher: Send + Sync {
|
||||||
|
|
||||||
pub trait PlatformTextSystem: Send + Sync {
|
pub 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_families(&self) -> Vec<String>;
|
fn all_font_names(&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>>;
|
||||||
|
|
|
@ -5,7 +5,7 @@ use crate::{
|
||||||
};
|
};
|
||||||
use anyhow::anyhow;
|
use anyhow::anyhow;
|
||||||
use cocoa::appkit::{CGFloat, CGPoint};
|
use cocoa::appkit::{CGFloat, CGPoint};
|
||||||
use collections::HashMap;
|
use collections::{BTreeSet, HashMap};
|
||||||
use core_foundation::{
|
use core_foundation::{
|
||||||
array::CFIndex,
|
array::CFIndex,
|
||||||
attributed_string::{CFAttributedStringRef, CFMutableAttributedString},
|
attributed_string::{CFAttributedStringRef, CFMutableAttributedString},
|
||||||
|
@ -78,12 +78,16 @@ impl PlatformTextSystem for MacTextSystem {
|
||||||
self.0.write().add_fonts(fonts)
|
self.0.write().add_fonts(fonts)
|
||||||
}
|
}
|
||||||
|
|
||||||
fn all_font_families(&self) -> Vec<String> {
|
fn all_font_names(&self) -> Vec<String> {
|
||||||
self.0
|
let collection = core_text::font_collection::create_for_all_families();
|
||||||
.read()
|
let Some(descriptors) = collection.get_descriptors() else {
|
||||||
.system_source
|
return vec![];
|
||||||
.all_families()
|
};
|
||||||
.expect("core text should never return an error")
|
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> {
|
fn font_id(&self, font: &Font) -> Result<FontId> {
|
||||||
|
|
|
@ -65,8 +65,8 @@ impl TextSystem {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn all_font_families(&self) -> Vec<String> {
|
pub fn all_font_names(&self) -> Vec<String> {
|
||||||
let mut families = self.platform_text_system.all_font_families();
|
let mut families = self.platform_text_system.all_font_names();
|
||||||
families.append(
|
families.append(
|
||||||
&mut self
|
&mut self
|
||||||
.fallback_font_stack
|
.fallback_font_stack
|
||||||
|
@ -101,7 +101,6 @@ impl TextSystem {
|
||||||
if let Ok(font_id) = self.font_id(font) {
|
if let Ok(font_id) = self.font_id(font) {
|
||||||
return font_id;
|
return font_id;
|
||||||
}
|
}
|
||||||
|
|
||||||
for fallback in &self.fallback_font_stack {
|
for fallback in &self.fallback_font_stack {
|
||||||
if let Ok(font_id) = self.font_id(fallback) {
|
if let Ok(font_id) = self.font_id(fallback) {
|
||||||
return font_id;
|
return font_id;
|
||||||
|
|
|
@ -205,7 +205,7 @@ impl settings::Settings for ThemeSettings {
|
||||||
|
|
||||||
let available_fonts = cx
|
let available_fonts = cx
|
||||||
.text_system()
|
.text_system()
|
||||||
.all_font_families()
|
.all_font_names()
|
||||||
.into_iter()
|
.into_iter()
|
||||||
.map(Value::String)
|
.map(Value::String)
|
||||||
.collect();
|
.collect();
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue