Skip to content

Commit 7616dc9

Browse files
improv: use cosmic_text's persistent cached fonts
1 parent 62b9017 commit 7616dc9

4 files changed

Lines changed: 14 additions & 13 deletions

File tree

Cargo.lock

Lines changed: 4 additions & 5 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -238,8 +238,8 @@ async-std = "1.0"
238238
bitflags = "2.5"
239239
bytemuck = { version = "1.0", features = ["derive"] }
240240
bytes = "1.6"
241-
cosmic-text = "0.19"
242-
cryoglyph = { git = "https://github.com/iced-rs/cryoglyph.git", rev = "e429a025df36ab8145708acb309080ae3deec17a" }
241+
cosmic-text = { git = "https://github.com/pop-os/cosmic-text.git", rev = "4fe1195e6451d6aaa3dc383895d6fd366ea9fc7b" }
242+
cryoglyph = { git = "https://github.com/hojjatabdollahi/cryoglyph.git", rev = "76e8d4bcd28b92faa42a1c6107f5724a2db068aa" }
243243
dark-light = "1.0"
244244
resvg = "0.45"
245245
web-sys = "0.3.69"

graphics/src/text.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -133,7 +133,7 @@ pub fn font_system() -> &'static RwLock<FontSystem> {
133133

134134
FONT_SYSTEM.get_or_init(|| {
135135
RwLock::new(FontSystem {
136-
raw: cosmic_text::FontSystem::new_with_fonts([
136+
raw: cosmic_text::FontSystem::new_with_fonts_and_cache([
137137
cosmic_text::fontdb::Source::Binary(Arc::new(
138138
include_bytes!("../fonts/Iced-Icons.ttf").as_slice(),
139139
)),

wgpu/src/image/vector.rs

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
use crate::core::svg;
22
use crate::core::{Color, Size};
3+
use crate::graphics::text;
34
use crate::image::atlas::{self, Atlas};
45

56
use resvg::tiny_skia;
@@ -40,6 +41,7 @@ pub struct Cache {
4041
rasterized_hits: FxHashSet<(u64, u32, u32, ColorFilter)>,
4142
should_trim: bool,
4243
fontdb: Option<Arc<usvg::fontdb::Database>>,
44+
fontdb_version: Option<text::Version>,
4345
}
4446

4547
type ColorFilter = Option<[u8; 4]>;
@@ -51,12 +53,12 @@ impl Cache {
5153
return self.svgs.get(&handle.id()).unwrap();
5254
}
5355

54-
// TODO: Reuse `cosmic-text` font database
55-
if self.fontdb.is_none() {
56-
let mut fontdb = usvg::fontdb::Database::new();
57-
fontdb.load_system_fonts();
56+
let font_system = text::font_system().read().expect("Read font system");
57+
let version = font_system.version();
5858

59-
self.fontdb = Some(Arc::new(fontdb));
59+
if self.fontdb_version != Some(version) {
60+
self.fontdb = Some(Arc::new(font_system.db().clone()));
61+
self.fontdb_version = Some(version);
6062
}
6163

6264
let options = usvg::Options {

0 commit comments

Comments
 (0)