use std::{ fmt::Display, hash::{Hash, Hasher}, io::Read, path::PathBuf, sync::Arc, }; use colors_transform::Rgb; use cosmic::{ iced::{ font::{Style, Weight}, ContentFit, Length, Size, }, prelude::*, widget::{container, image::Handle, Image}, }; use resvg::{ tiny_skia::{self, Pixmap}, usvg::{fontdb, Tree}, }; use tracing::{debug, error}; use crate::TextAlignment; #[derive(Clone, Debug, Default)] pub struct TextSvg { text: String, font: Font, shadow: Option, stroke: Option, fill: Color, alignment: TextAlignment, pub handle: Option, fontdb: Arc, } impl PartialEq for TextSvg { fn eq(&self, other: &Self) -> bool { self.text == other.text && self.font == other.font && self.shadow == other.shadow && self.stroke == other.stroke && self.fill == other.fill && self.alignment == other.alignment && self.handle == other.handle } } impl Hash for TextSvg { fn hash(&self, state: &mut H) { self.text.hash(state); self.font.hash(state); self.shadow.hash(state); self.stroke.hash(state); self.fill.hash(state); self.alignment.hash(state); } } #[derive(Clone, Debug, Default, PartialEq, Eq, Hash)] pub struct Font { name: String, weight: Weight, style: Style, size: u8, } #[derive(Clone, Debug, Default, PartialEq, Hash)] pub struct Shadow { pub offset_x: i16, pub offset_y: i16, pub spread: u16, pub color: Color, } #[derive(Clone, Debug, Default, PartialEq, Hash)] pub struct Stroke { size: u16, color: Color, } pub enum Message { None, } #[derive(Clone, Debug, PartialEq)] pub struct Color(Rgb); impl From for Font { fn from(value: cosmic::font::Font) -> Self { Self { name: match value.family { cosmic::iced::font::Family::Name(name) => { name.to_string() } _ => "Quicksand Bold".into(), }, size: 20, ..Default::default() } } } impl From for Font { fn from(value: String) -> Self { Self { name: value, ..Default::default() } } } impl From<&str> for Font { fn from(value: &str) -> Self { Self { name: value.to_owned(), ..Default::default() } } } impl Font { pub fn get_name(&self) -> String { self.name.clone() } pub fn get_weight(&self) -> Weight { self.weight } pub fn get_style(&self) -> Style { self.style } pub fn weight(mut self, weight: impl Into) -> Self { self.weight = weight.into(); self } pub fn style(mut self, style: impl Into