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
|
@ -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