feat: add CompositeIcon struct for nesting SVGs
This commit is contained in:
Generated
+7
@@ -23,6 +23,12 @@ version = "1.5.1"
|
|||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "f2032f911046de80f0a198e0901378627c33f59ea0ac00e363d481118bd70a53"
|
checksum = "f2032f911046de80f0a198e0901378627c33f59ea0ac00e363d481118bd70a53"
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "base64"
|
||||||
|
version = "0.23.0"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "b25655df2c3cdd83c5e5b293b88acd880332b2ddadd7c30ac43144fdc0033da9"
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "bitflags"
|
name = "bitflags"
|
||||||
version = "2.13.1"
|
version = "2.13.1"
|
||||||
@@ -402,6 +408,7 @@ name = "icon-color-tool"
|
|||||||
version = "0.1.0"
|
version = "0.1.0"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"anyhow",
|
"anyhow",
|
||||||
|
"base64",
|
||||||
"gtk4",
|
"gtk4",
|
||||||
"regex",
|
"regex",
|
||||||
"serde",
|
"serde",
|
||||||
|
|||||||
@@ -10,3 +10,4 @@ regex = "1"
|
|||||||
serde = { version = "1", features = ["derive"] }
|
serde = { version = "1", features = ["derive"] }
|
||||||
toml = "0.8"
|
toml = "0.8"
|
||||||
walkdir = "2"
|
walkdir = "2"
|
||||||
|
base64 = "0.23.0"
|
||||||
|
|||||||
+2
-1
@@ -21,8 +21,9 @@ impl ColorScheme {
|
|||||||
.with_context(|| format!("reading {}", path.display()))?;
|
.with_context(|| format!("reading {}", path.display()))?;
|
||||||
|
|
||||||
if !namespace.is_empty() {
|
if !namespace.is_empty() {
|
||||||
|
let class_re = Regex::new(r#"class=(['"])([^'"]*?)ColorScheme-([^'"]*?)(['"])"#).unwrap();
|
||||||
|
content = class_re.replace_all(&content, format!("class=${{1}}${{2}}{namespace}-ColorScheme-${{3}}${{4}}").as_str()).into_owned();
|
||||||
content = content.replace(".ColorScheme-", &format!(".{namespace}-ColorScheme-"));
|
content = content.replace(".ColorScheme-", &format!(".{namespace}-ColorScheme-"));
|
||||||
content = content.replace("class=\"ColorScheme-", &format!("class=\"{namespace}-ColorScheme-"));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
let colors = parse_colors(&content);
|
let colors = parse_colors(&content);
|
||||||
|
|||||||
@@ -25,16 +25,15 @@ impl CompositeIcon {
|
|||||||
|
|
||||||
pub fn render(&self) -> String {
|
pub fn render(&self) -> String {
|
||||||
if let Some(emblem) = &self.emblem {
|
if let Some(emblem) = &self.emblem {
|
||||||
|
use base64::prelude::*;
|
||||||
|
let bg_b64 = BASE64_STANDARD.encode(&self.bg.content);
|
||||||
|
let emblem_b64 = BASE64_STANDARD.encode(&emblem.content);
|
||||||
format!(
|
format!(
|
||||||
r#"<svg viewBox="0 0 64 64" xmlns="http://www.w3.org/2000/svg">
|
r#"<svg viewBox="0 0 64 64" xmlns="http://www.w3.org/2000/svg">
|
||||||
<svg x="0" y="0" width="64" height="64" overflow="visible">
|
<image x="0" y="0" width="64" height="64" href="data:image/svg+xml;base64,{}" />
|
||||||
{}
|
<image x="{}" y="{}" width="{}" height="{}" href="data:image/svg+xml;base64,{}" />
|
||||||
</svg>
|
|
||||||
<svg x="{}" y="{}" width="{}" height="{}" overflow="visible">
|
|
||||||
{}
|
|
||||||
</svg>
|
|
||||||
</svg>"#,
|
</svg>"#,
|
||||||
self.bg.content, self.emblem_x, self.emblem_y, self.emblem_size, self.emblem_size, emblem.content
|
bg_b64, self.emblem_x, self.emblem_y, self.emblem_size, self.emblem_size, emblem_b64
|
||||||
)
|
)
|
||||||
} else {
|
} else {
|
||||||
self.bg.content.clone()
|
self.bg.content.clone()
|
||||||
|
|||||||
Reference in New Issue
Block a user