Skip to content

Commit

Permalink
chore: update dependencies
Browse files Browse the repository at this point in the history
  • Loading branch information
vicanso committed Jun 3, 2024
1 parent 6a0ca57 commit f7574f9
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 18 deletions.
8 changes: 4 additions & 4 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "charts-rs"
version = "0.3.9"
version = "0.3.10"
authors = ["Tree Xie <tree.xie@outlook.com>"]
edition = "2021"
categories = ["multimedia::images"]
Expand All @@ -25,13 +25,13 @@ image = { version = "0.25.1", features = [
], optional = true }
once_cell = "1.19.0"
regex = "1.10.4"
resvg = { version = "0.41.0", default-features = false, features = [
resvg = { version = "0.42.0", default-features = false, features = [
"text",
"system-fonts",
], optional = true }
serde = { version = "1.0.202", features = ["derive"] }
serde = { version = "1.0.203", features = ["derive"] }
serde_json = "1.0.117"
snafu = "0.8.2"
snafu = "0.8.3"
substring = "1.4.5"

[features]
Expand Down
37 changes: 23 additions & 14 deletions src/charts/encoder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ use once_cell::sync::OnceCell;
use resvg::{tiny_skia, usvg};
use snafu::{ResultExt, Snafu};
use std::io::Cursor;
use std::sync::Arc;
use usvg::fontdb;

#[derive(Debug, Snafu)]
Expand All @@ -23,25 +24,33 @@ pub enum Error {
}
pub type Result<T, E = Error> = std::result::Result<T, E>;

pub(crate) fn get_or_init_fontdb(fonts: Option<Vec<&[u8]>>) -> &fontdb::Database {
static GLOBAL_FONT_DB: OnceCell<fontdb::Database> = OnceCell::new();
GLOBAL_FONT_DB.get_or_init(|| {
let mut fontdb = fontdb::Database::new();
if let Some(value) = fonts {
for item in value.iter() {
fontdb.load_font_data((*item).to_vec());
pub(crate) fn get_or_init_fontdb(fonts: Option<Vec<&[u8]>>) -> Arc<fontdb::Database> {
static GLOBAL_FONT_DB: OnceCell<Arc<fontdb::Database>> = OnceCell::new();
GLOBAL_FONT_DB
.get_or_init(|| {
let mut fontdb = fontdb::Database::new();
if let Some(value) = fonts {
for item in value.iter() {
fontdb.load_font_data((*item).to_vec());
}
} else {
fontdb.load_system_fonts();
}
} else {
fontdb.load_system_fonts();
}
fontdb
})
Arc::new(fontdb)
})
.clone()
}

fn save_image(svg: &str, format: image::ImageFormat) -> Result<Vec<u8>> {
let fontdb = get_or_init_fontdb(None);
let tree =
usvg::Tree::from_str(svg, &usvg::Options::default(), fontdb).context(ParseSnafu {})?;
let tree = usvg::Tree::from_str(
svg,
&usvg::Options {
fontdb,
..Default::default()
},
)
.context(ParseSnafu {})?;
let pixmap_size = tree.size().to_int_size();
let mut pixmap =
tiny_skia::Pixmap::new(pixmap_size.width(), pixmap_size.height()).ok_or(Error::Size {
Expand Down

0 comments on commit f7574f9

Please sign in to comment.