Skip to content

Commit 05daa49

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

4 files changed

Lines changed: 50 additions & 49 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: 38 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -84,11 +84,11 @@ selector = ["iced_runtime/selector"]
8484

8585
# Enables basic text shaping by default
8686
fira-sans = [
87-
"iced_renderer/fira-sans",
87+
"iced_renderer/fira-sans",
8888
] # Embeds Fira Sans into the final application; useful for testing and Wasm builds
8989
advanced = [
90-
"iced_core/advanced",
91-
"iced_widget/advanced",
90+
"iced_core/advanced",
91+
"iced_widget/advanced",
9292
] # Enables the advanced module
9393
basic-shaping = ["iced_core/basic-shaping"]
9494
# Enables advanced text shaping by default
@@ -107,16 +107,16 @@ linux-theme-detection = ["iced_winit/linux-theme-detection"]
107107
x11 = ["iced_renderer/x11", "iced_winit/x11"]
108108
# Enables the `accesskit` accessibility library
109109
a11y = [
110-
"iced_accessibility",
111-
"iced_core/a11y",
112-
"iced_widget/a11y",
113-
"iced_winit?/a11y",
110+
"iced_accessibility",
111+
"iced_core/a11y",
112+
"iced_widget/a11y",
113+
"iced_winit?/a11y",
114114
]
115115
# Enables the winit shell. Conflicts with `wayland` and `glutin`.
116116
winit = [
117-
"iced_winit",
118-
"iced_accessibility?/accesskit_winit",
119-
"iced_program/winit",
117+
"iced_winit",
118+
"iced_accessibility?/accesskit_winit",
119+
"iced_program/winit",
120120
]
121121
wayland = ["iced_renderer/wayland", "iced_winit/wayland"]
122122
cctk = ["iced_winit/cctk", "iced_widget/cctk", "iced_core/cctk", "wayland"]
@@ -171,25 +171,25 @@ strip = "debuginfo"
171171

172172
[workspace]
173173
members = [
174-
"beacon",
175-
"core",
176-
"debug",
177-
"devtools",
178-
"futures",
179-
"graphics",
180-
"highlighter",
181-
"program",
182-
"renderer",
183-
"runtime",
184-
"selector",
185-
"test",
186-
"tester",
187-
"tiny_skia",
188-
"wgpu",
189-
"widget",
190-
"winit",
191-
"examples/*",
192-
"accessibility",
174+
"beacon",
175+
"core",
176+
"debug",
177+
"devtools",
178+
"futures",
179+
"graphics",
180+
"highlighter",
181+
"program",
182+
"renderer",
183+
"runtime",
184+
"selector",
185+
"test",
186+
"tester",
187+
"tiny_skia",
188+
"wgpu",
189+
"widget",
190+
"winit",
191+
"examples/*",
192+
"accessibility",
193193
]
194194
exclude = ["examples/integration"]
195195

@@ -226,8 +226,8 @@ iced_winit = { version = "0.14.0", path = "winit", default-features = false }
226226
bincode = "1.3"
227227
cargo-hot = { version = "0.1", package = "cargo-hot-protocol" }
228228
futures = { version = "0.3", default-features = false, features = [
229-
"std",
230-
"async-await",
229+
"std",
230+
"async-await",
231231
] }
232232
glam = "0.25"
233233
iced_accessibility = { version = "0.1", path = "accessibility" }
@@ -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/pop-os/glyphon.git", rev = "273130949ef4ffc652e3d5e5255219f1f079868e" }
243243
dark-light = "1.0"
244244
resvg = "0.45"
245245
web-sys = "0.3.69"
@@ -271,25 +271,25 @@ smol_str = "0.3"
271271
sysinfo = "0.33"
272272
thiserror = "2"
273273
tiny-skia = { version = "0.11", default-features = false, features = [
274-
"std",
275-
"simd",
274+
"std",
275+
"simd",
276276
] }
277277
cctk = { git = "https://github.com/pop-os/cosmic-protocols", package = "cosmic-client-toolkit", rev = "c253ec1" }
278278
softbuffer = { git = "https://github.com/pop-os/softbuffer", tag = "cosmic-4.0" }
279279
syntect = "5.2"
280280
tokio = "1.0"
281281
tracing = "0.1"
282282
two-face = { version = "0.4", default-features = false, features = [
283-
"syntect-default-fancy",
283+
"syntect-default-fancy",
284284
] }
285285
unicode-segmentation = "1.0"
286286
url = "2.5"
287287
wasm-bindgen-futures = "0.4"
288288
wasmtimer = "0.4.2"
289289
web-time = "1.1"
290290
wgpu = { version = "28.0", default-features = false, features = [
291-
"std",
292-
"wgsl",
291+
"std",
292+
"wgsl",
293293
] }
294294
wayland-protocols = { version = "0.32.1", features = ["staging"] }
295295
wayland-client = { version = "0.31.5" }

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)