Skip to content

Commit

Permalink
refactor: Cache loaded SVG fonts
Browse files Browse the repository at this point in the history
  • Loading branch information
CosmicHorrorDev committed Jun 20, 2024
1 parent e9b15d5 commit 34bff7e
Showing 1 changed file with 8 additions and 3 deletions.
11 changes: 8 additions & 3 deletions src/image/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ mod tests;
use std::borrow::Cow;
use std::path::PathBuf;
use std::str::FromStr;
use std::sync::{Arc, Mutex};
use std::sync::{Arc, Mutex, OnceLock};
use std::time::Instant;
use std::{
fs,
Expand All @@ -21,6 +21,7 @@ use crate::utils::{usize_in_mib, Align, Point, Size};
use anyhow::Context;
use bytemuck::{Pod, Zeroable};
use image::{ImageBuffer, RgbaImage};
use usvg::fontdb;
use resvg::{tiny_skia, usvg};
use smart_debug::SmartDebug;
use wgpu::util::DeviceExt;
Expand Down Expand Up @@ -264,8 +265,12 @@ impl Image {
)
.unwrap(),
);
let mut fontdb = usvg::fontdb::Database::new();
fontdb.load_system_fonts();
static FONTDB: OnceLock<fontdb::Database> = OnceLock::new();
let fontdb = FONTDB.get_or_init(|| {
let mut db = fontdb::Database::new();
db.load_system_fonts();
db
});
tree.postprocess(Default::default(), &fontdb);
let mut pixmap =
tiny_skia::Pixmap::new(tree.size.width() as u32, tree.size.height() as u32)
Expand Down

0 comments on commit 34bff7e

Please sign in to comment.