Merge remote-tracking branch 'origin/main' into ownership-post

This commit is contained in:
Nathan Sobo 2024-01-18 07:01:54 -07:00
commit 9e37232a13
21 changed files with 119 additions and 128 deletions

View file

@ -201,6 +201,7 @@ pub trait PlatformDispatcher: Send + Sync {
pub(crate) trait PlatformTextSystem: Send + Sync {
fn add_fonts(&self, fonts: &[Arc<Vec<u8>>]) -> Result<()>;
fn all_font_names(&self) -> Vec<String>;
fn all_font_families(&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>>;
@ -282,8 +283,6 @@ pub(crate) trait PlatformAtlas: Send + Sync {
key: &AtlasKey,
build: &mut dyn FnMut() -> Result<(Size<DevicePixels>, Cow<'a, [u8]>)>,
) -> Result<AtlasTile>;
fn clear(&self);
}
#[derive(Clone, Debug, PartialEq, Eq)]

View file

@ -74,20 +74,6 @@ impl PlatformAtlas for MetalAtlas {
Ok(tile)
}
}
fn clear(&self) {
let mut lock = self.0.lock();
lock.tiles_by_key.clear();
for texture in &mut lock.monochrome_textures {
texture.clear();
}
for texture in &mut lock.polychrome_textures {
texture.clear();
}
for texture in &mut lock.path_textures {
texture.clear();
}
}
}
impl MetalAtlasState {

View file

@ -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<String> {
self.0
.read()
.system_source
.all_families()
.expect("core text should never return an error")
}
fn font_id(&self, font: &Font) -> Result<FontId> {
let lock = self.0.upgradable_read();
if let Some(font_id) = lock.font_selections.get(font) {

View file

@ -325,10 +325,4 @@ impl PlatformAtlas for TestAtlas {
Ok(state.tiles[key].clone())
}
fn clear(&self) {
let mut state = self.0.lock();
state.tiles = HashMap::default();
state.next_id = 0;
}
}

View file

@ -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<String> {
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<Vec<u8>>]) -> Result<()> {
self.platform_text_system.add_fonts(fonts)