mirror of
https://github.com/Brooooooklyn/Image.git
synced 2025-12-08 18:36:03 +00:00
perf(image): lazy load the Fontdb Database
This commit is contained in:
parent
5a8a6e0fd0
commit
68400a9707
@ -35,7 +35,7 @@ image = { version = "0.24", default-features = false, features = [
|
||||
"openexr",
|
||||
] }
|
||||
jpeg-decoder = "0.3"
|
||||
libavif = { version = "=0.10.1", default-features = false, features = [
|
||||
libavif = { version = "0.11", default-features = false, features = [
|
||||
"codec-aom",
|
||||
] }
|
||||
libc = "0.2"
|
||||
@ -47,6 +47,7 @@ napi-derive = { version = "2", default-features = false, features = [
|
||||
] }
|
||||
num-complex = "0.4"
|
||||
num_cpus = "1"
|
||||
once_cell = "1"
|
||||
png = "0.17"
|
||||
rexif = "0.7"
|
||||
rgb = "0.8"
|
||||
|
||||
@ -20,6 +20,12 @@ use crate::{
|
||||
png::PngEncodeOptions,
|
||||
};
|
||||
|
||||
static FONT_DB: once_cell::sync::Lazy<Database> = once_cell::sync::Lazy::new(|| {
|
||||
let mut fontdb = Database::new();
|
||||
fontdb.load_system_fonts();
|
||||
fontdb
|
||||
});
|
||||
|
||||
pub enum EncodeOptions {
|
||||
Png(PngEncodeOptions),
|
||||
Jpeg(u32),
|
||||
@ -669,8 +675,6 @@ impl Transformer {
|
||||
input: Either<String, Buffer>,
|
||||
background: Option<String>,
|
||||
) -> Result<Transformer> {
|
||||
let mut fontdb = Database::new();
|
||||
fontdb.load_system_fonts();
|
||||
let options = Options::default();
|
||||
|
||||
let mut tree = match input {
|
||||
@ -678,7 +682,7 @@ impl Transformer {
|
||||
Either::B(b) => usvg::Tree::from_data(b.as_ref(), &options),
|
||||
}
|
||||
.map_err(|err| Error::from_reason(format!("{err}")))?;
|
||||
tree.convert_text(&fontdb);
|
||||
tree.convert_text(&*FONT_DB);
|
||||
|
||||
let mut size = tree.size.to_screen_size();
|
||||
let min_svg_size = 1000;
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user