adding hasing the string as filename for better caching
Some checks are pending
/ test (push) Waiting to run
Some checks are pending
/ test (push) Waiting to run
This commit is contained in:
parent
9971ccdf30
commit
64a9937776
3 changed files with 34 additions and 20 deletions
10
Cargo.lock
generated
10
Cargo.lock
generated
|
@ -3858,6 +3858,7 @@ dependencies = [
|
|||
"libcosmic",
|
||||
"miette",
|
||||
"pretty_assertions",
|
||||
"rapidhash",
|
||||
"rayon",
|
||||
"resvg 0.45.1",
|
||||
"rodio",
|
||||
|
@ -5342,6 +5343,15 @@ version = "1.6.0"
|
|||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "f93e7e49bb0bf967717f7bd674458b3d6b0c5f48ec7e3038166026a69fc22223"
|
||||
|
||||
[[package]]
|
||||
name = "rapidhash"
|
||||
version = "4.0.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "9d126f24bc587b080d7823a831d0fe832090a606fd3fd244ecbe23c561104ab8"
|
||||
dependencies = [
|
||||
"rustversion",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "rav1e"
|
||||
version = "0.7.1"
|
||||
|
|
|
@ -34,6 +34,7 @@ colors-transform = "0.2.11"
|
|||
rayon = "1.11.0"
|
||||
resvg = "0.45.1"
|
||||
image = "0.25.8"
|
||||
rapidhash = "4.0.0"
|
||||
# femtovg = { version = "0.16.0", features = ["wgpu"] }
|
||||
# wgpu = "26.0.1"
|
||||
# mupdf = "0.5.0"
|
||||
|
|
|
@ -15,6 +15,7 @@ use cosmic::{
|
|||
prelude::*,
|
||||
widget::{container, image::Handle, Image},
|
||||
};
|
||||
use rapidhash::v3::rapidhash_v3;
|
||||
use resvg::{
|
||||
tiny_skia::{self, Pixmap},
|
||||
usvg::{fontdb, Tree},
|
||||
|
@ -244,20 +245,10 @@ impl TextSvg {
|
|||
pub fn build(mut self) -> Self {
|
||||
debug!("starting...");
|
||||
|
||||
// let mut path = dirs::data_local_dir().unwrap();
|
||||
// path.push(PathBuf::from("lumina"));
|
||||
// path.push(PathBuf::from("temp"));
|
||||
// let file_title =
|
||||
// &self.text.lines().next().unwrap().trim_end();
|
||||
// path.push(PathBuf::from(file_title));
|
||||
// path.set_extension("png");
|
||||
let mut path = dirs::data_local_dir().unwrap();
|
||||
path.push(PathBuf::from("lumina"));
|
||||
path.push(PathBuf::from("temp"));
|
||||
|
||||
// if path.exists() {
|
||||
// debug!("cached");
|
||||
// let handle = Handle::from_path(path);
|
||||
// self.handle = Some(handle);
|
||||
// return self;
|
||||
// }
|
||||
let shadow = if let Some(shadow) = &self.shadow {
|
||||
format!("<filter id=\"shadow\"><feDropShadow dx=\"{}\" dy=\"{}\" stdDeviation=\"{}\" flood-color=\"{}\"/></filter>",
|
||||
shadow.offset_x,
|
||||
|
@ -307,6 +298,18 @@ impl TextSvg {
|
|||
self.font.name,
|
||||
font_size,
|
||||
self.fill, stroke, text);
|
||||
|
||||
let hashed_title = rapidhash_v3(final_svg.as_bytes());
|
||||
path.push(PathBuf::from(hashed_title.to_string()));
|
||||
path.set_extension("png");
|
||||
|
||||
if path.exists() {
|
||||
debug!("cached");
|
||||
let handle = Handle::from_path(path);
|
||||
self.handle = Some(handle);
|
||||
return self;
|
||||
}
|
||||
|
||||
debug!("text string built...");
|
||||
let resvg_tree = Tree::from_data(
|
||||
&final_svg.as_bytes(),
|
||||
|
@ -322,15 +325,15 @@ impl TextSvg {
|
|||
Pixmap::new(size.width as u32, size.height as u32)
|
||||
.expect("opops");
|
||||
resvg::render(&resvg_tree, transform, &mut pixmap.as_mut());
|
||||
// let _ = pixmap.save_png(&path);
|
||||
let _ = pixmap.save_png(&path);
|
||||
|
||||
debug!("rendered");
|
||||
// let handle = Handle::from_path(path);
|
||||
let handle = Handle::from_rgba(
|
||||
size.width as u32,
|
||||
size.height as u32,
|
||||
pixmap.take(),
|
||||
);
|
||||
let handle = Handle::from_path(path);
|
||||
// let handle = Handle::from_rgba(
|
||||
// size.width as u32,
|
||||
// size.height as u32,
|
||||
// pixmap.take(),
|
||||
// );
|
||||
self.handle = Some(handle);
|
||||
debug!("stored");
|
||||
self
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue