From 506a4194beef138cfc9b121b71f73147a0c3cf55 Mon Sep 17 00:00:00 2001 From: Edgar Geier Date: Wed, 1 Mar 2023 02:50:10 +0100 Subject: [PATCH 1/5] Make `FontSystem` not self-referencing --- Cargo.toml | 1 - src/cache.rs | 10 ++- src/font/fallback/mod.rs | 31 ++++--- src/font/matches.rs | 14 --- src/font/mod.rs | 41 ++++++++- src/font/system/no_std.rs | 33 ++++--- src/font/system/redox.rs | 33 ++++--- src/font/system/std.rs | 177 ++++++++++++++++++-------------------- src/shape.rs | 33 +++---- src/swash.rs | 8 +- 10 files changed, 206 insertions(+), 175 deletions(-) delete mode 100644 src/font/matches.rs diff --git a/Cargo.toml b/Cargo.toml index 1e82553..0cd125f 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -12,7 +12,6 @@ repository = "https://github.com/pop-os/cosmic-text" fontdb = { version = "0.10.0", default-features = false } libm = "0.2.6" log = "0.4.17" -ouroboros = "0.15.5" rustybuzz = { version = "0.6.0", default-features = false, features = ["libm"] } swash = { version = "0.1.6", optional = true } syntect = { version = "5.0.0", optional = true } diff --git a/src/cache.rs b/src/cache.rs index ce93b38..0da1f52 100644 --- a/src/cache.rs +++ b/src/cache.rs @@ -1,10 +1,12 @@ // SPDX-License-Identifier: MIT OR Apache-2.0 +use crate::FontKey; + /// Key for building a glyph cache #[derive(Clone, Copy, Debug, Eq, Hash, Ord, PartialEq, PartialOrd)] pub struct CacheKey { - /// Font ID - pub font_id: fontdb::ID, + /// Font key + pub font_key: FontKey, /// Glyph ID pub glyph_id: u16, /// `f32` bits of font size @@ -17,7 +19,7 @@ pub struct CacheKey { impl CacheKey { pub fn new( - font_id: fontdb::ID, + font_key: FontKey, glyph_id: u16, font_size: f32, pos: (f32, f32), @@ -26,7 +28,7 @@ impl CacheKey { let (y, y_bin) = SubpixelBin::new(pos.1); ( Self { - font_id, + font_key, glyph_id, font_size_bits: font_size.to_bits(), x_bin, diff --git a/src/font/fallback/mod.rs b/src/font/fallback/mod.rs index 7b8fa8c..dec12d9 100644 --- a/src/font/fallback/mod.rs +++ b/src/font/fallback/mod.rs @@ -1,11 +1,10 @@ // SPDX-License-Identifier: MIT OR Apache-2.0 -use alloc::sync::Arc; #[cfg(not(feature = "std"))] use alloc::vec::Vec; use unicode_script::Script; -use crate::Font; +use crate::{Font, FontKey}; use self::platform::*; @@ -26,7 +25,8 @@ mod platform; mod platform; pub struct FontFallbackIter<'a> { - fonts: &'a [Arc>], + db: &'a fontdb::Database, + font_keys: &'a [FontKey], default_families: &'a [&'a str], default_i: usize, scripts: Vec