diff --git a/justfile b/justfile index 1da1804..2ce3275 100644 --- a/justfile +++ b/justfile @@ -18,7 +18,7 @@ clean: test: RUST_LOG=debug cargo test --benches --tests --all-features -- --nocapture profile: - cargo flamegraph --image-width 8000 -- {{ui}} {{file}} + cargo flamegraph -- {{ui}} alias b := build alias r := run diff --git a/src/ui/text_svg.rs b/src/ui/text_svg.rs index 250ea44..c158e79 100644 --- a/src/ui/text_svg.rs +++ b/src/ui/text_svg.rs @@ -14,11 +14,12 @@ use cosmic::{ prelude::*, widget::{Image, image::Handle}, }; +use rayon::str::ParallelString; use resvg::{ tiny_skia::{self, Pixmap}, usvg::{Tree, fontdb}, }; -use tracing::{debug, error}; +use tracing::{debug, error, warn}; use crate::TextAlignment; @@ -248,31 +249,14 @@ impl TextSvg { } pub fn build(mut self) -> Self { - // debug!("starting..."); + debug!("starting..."); // let mut path = dirs::data_local_dir().unwrap(); // path.push(PathBuf::from("lumina")); // path.push(PathBuf::from("temp")); - let shadow = if let Some(shadow) = &self.shadow { - format!( - "", - shadow.offset_x, - shadow.offset_y, - shadow.spread, - shadow.color - ) - } else { - String::new() - }; - let stroke = if let Some(stroke) = &self.stroke { - format!( - "stroke=\"{}\" stroke-width=\"{}px\" stroke-linejoin=\"arcs\" paint-order=\"stroke\"", - stroke.color, stroke.size - ) - } else { - String::new() - }; + let mut final_svg = String::with_capacity(1024); + let size = Size::new(1920.0, 1080.0); let font_size = f32::from(self.font.size); let total_lines = self.text.lines().count(); @@ -283,6 +267,29 @@ impl TextSvg { let starting_y_position = half_lines .mul_add(-text_and_line_spacing, middle_position); + final_svg.push_str(&format!("", size.width, size.height)); + + if let Some(shadow) = &self.shadow { + final_svg.push_str(&format!( + "", + shadow.offset_x, + shadow.offset_y, + shadow.spread, + shadow.color + )) + }; + final_svg.push_str(""); + + final_svg.push_str(&format!(""); + let text_pieces: Vec = self .text .lines() @@ -299,18 +306,21 @@ impl TextSvg { }) .collect(); let text: String = text_pieces.join("\n"); + final_svg.push_str(&text); - let final_svg = format!( - "{}{}", - size.width, - size.height, - shadow, - self.font.name, - font_size, - self.fill, - stroke, - text - ); + final_svg.push_str(""); + + // final_svg.push_str(&format!( + // "{}{}", + // size.width, + // size.height, + // shadow, + // 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())); @@ -323,7 +333,7 @@ impl TextSvg { // return self; // } - // debug!("text string built..."); + debug!("text string built..."); let resvg_tree = Tree::from_data( final_svg.as_bytes(), &resvg::usvg::Options {