// icon-color-tool
// Copyright (C) 2026 Rootiest
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program. If not, see .
use crate::color_scheme::ColorScheme;
pub struct CompositeIcon {
pub bg: ColorScheme,
pub emblem: Option,
pub emblem_x: f64,
pub emblem_y: f64,
pub emblem_size: f64,
pub is_modified: bool,
}
impl CompositeIcon {
pub fn new(bg: ColorScheme) -> Self {
Self {
bg,
emblem: None,
emblem_x: 32.0,
emblem_y: 32.0,
emblem_size: 32.0,
is_modified: false,
}
}
pub fn set_emblem(&mut self, emblem: ColorScheme) {
self.emblem = Some(emblem);
}
pub fn render(&self) -> String {
use regex::Regex;
let strip_dimensions = |svg: &str| -> String {
if let Some(root_svg_end) = svg.find('>') {
let mut root_tag = svg[..=root_svg_end].to_string();
let re_w = Regex::new(r#"(?i)\s+width\s*=\s*"[^"]*""#).unwrap();
root_tag = re_w.replace_all(&root_tag, "").into_owned();
let re_h = Regex::new(r#"(?i)\s+height\s*=\s*"[^"]*""#).unwrap();
root_tag = re_h.replace_all(&root_tag, "").into_owned();
let mut new_svg = root_tag;
new_svg.push_str(&svg[root_svg_end + 1..]);
new_svg
} else {
svg.to_string()
}
};
if let Some(emblem) = &self.emblem {
fn parse_dims(svg: &str) -> (f64, f64) {
if let Ok(re) = Regex::new(r#"(?i)