forked from katzen-cafe/iowo
svg-filters: rework macro slightly
This commit is contained in:
parent
aeeee54200
commit
c31a158d9b
11 changed files with 52 additions and 96 deletions
|
@ -1,6 +1,4 @@
|
|||
use std::{borrow::Cow, fmt::Display};
|
||||
|
||||
use quick_xml::{events::attributes::Attribute, name::QName};
|
||||
use std::fmt::Display;
|
||||
|
||||
use super::WriteElement;
|
||||
|
||||
|
@ -29,7 +27,7 @@ impl WriteElement for Blend {
|
|||
if let BlendMode::Normal = self.mode {
|
||||
Vec::new()
|
||||
} else {
|
||||
gen_attrs![b"mode" = self.mode]
|
||||
gen_attrs![b"mode": self.mode]
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -16,7 +16,7 @@ impl WriteElement for ColorMatrix {
|
|||
fn attrs(&self) -> Vec<quick_xml::events::attributes::Attribute> {
|
||||
match &self.cm_type {
|
||||
ColorMatrixType::Matrix(v) => gen_attrs![
|
||||
b"values" = v
|
||||
b"values": v
|
||||
.iter()
|
||||
.map(std::string::ToString::to_string)
|
||||
.reduce(|mut acc, e| {
|
||||
|
@ -27,7 +27,7 @@ impl WriteElement for ColorMatrix {
|
|||
.expect("fixed length arr should always work")
|
||||
],
|
||||
ColorMatrixType::Saturate(v) | ColorMatrixType::HueRotate(v) => {
|
||||
gen_attrs![b"values" = v]
|
||||
gen_attrs![b"values": v]
|
||||
}
|
||||
ColorMatrixType::LuminanceToAlpha => Vec::new(),
|
||||
}
|
||||
|
|
|
@ -70,10 +70,10 @@ impl WriteElement for Composite {
|
|||
// },
|
||||
// ]);
|
||||
r.append(&mut gen_attrs![
|
||||
b"k1" = k1,
|
||||
b"k2" = k2,
|
||||
b"k3" = k3,
|
||||
b"k4" = k4
|
||||
b"k1": k1,
|
||||
b"k2": k2,
|
||||
b"k3": k3,
|
||||
b"k4": k4
|
||||
]);
|
||||
}
|
||||
|
||||
|
|
|
@ -1,7 +1,4 @@
|
|||
use std::borrow::Cow;
|
||||
|
||||
use csscolorparser::Color;
|
||||
use quick_xml::{events::attributes::Attribute, name::QName};
|
||||
|
||||
use super::WriteElement;
|
||||
|
||||
|
@ -15,8 +12,8 @@ pub struct Flood {
|
|||
impl WriteElement for Flood {
|
||||
fn attrs(&self) -> Vec<quick_xml::events::attributes::Attribute> {
|
||||
gen_attrs![
|
||||
b"flood-color" = self.flood_color.to_hex_string(),
|
||||
b"flood-opacity" = self.flood_opacity
|
||||
b"flood-color": self.flood_color.to_hex_string(),
|
||||
b"flood-opacity": self.flood_opacity
|
||||
]
|
||||
}
|
||||
|
||||
|
|
|
@ -26,7 +26,7 @@ impl GaussianBlur {
|
|||
|
||||
impl WriteElement for GaussianBlur {
|
||||
fn attrs(&self) -> Vec<quick_xml::events::attributes::Attribute> {
|
||||
gen_attrs![b"stdDeviation" = format!("{} {}", self.std_deviation.0, self.std_deviation.1)]
|
||||
gen_attrs![b"stdDeviation": format!("{} {}", self.std_deviation.0, self.std_deviation.1)]
|
||||
}
|
||||
|
||||
fn tag_name(&self) -> &'static str {
|
||||
|
|
|
@ -1,8 +1,5 @@
|
|||
use std::{borrow::Cow, fmt::Display};
|
||||
|
||||
use quick_xml::{events::attributes::Attribute, name::QName};
|
||||
|
||||
use super::WriteElement;
|
||||
use std::fmt::Display;
|
||||
|
||||
/// [feMorphology](https://www.w3.org/TR/SVG11/filters.html#feMorphologyElement)
|
||||
#[derive(Debug)]
|
||||
|
@ -14,8 +11,8 @@ pub struct Morphology {
|
|||
impl WriteElement for Morphology {
|
||||
fn attrs(&self) -> Vec<quick_xml::events::attributes::Attribute> {
|
||||
gen_attrs![
|
||||
b"operator" = self.operator,
|
||||
b"radius" = format!("{} {}", self.radius.0, self.radius.1)
|
||||
b"operator": self.operator,
|
||||
b"radius": format!("{} {}", self.radius.0, self.radius.1)
|
||||
]
|
||||
}
|
||||
|
||||
|
|
|
@ -1,7 +1,3 @@
|
|||
use std::borrow::Cow;
|
||||
|
||||
use quick_xml::{events::attributes::Attribute, name::QName};
|
||||
|
||||
use super::WriteElement;
|
||||
|
||||
/// [feOffset](https://www.w3.org/TR/SVG11/filters.html#feOffsetElement)
|
||||
|
@ -19,7 +15,7 @@ impl Offset {
|
|||
|
||||
impl WriteElement for Offset {
|
||||
fn attrs(&self) -> Vec<quick_xml::events::attributes::Attribute> {
|
||||
gen_attrs![b"dx" = self.dx, b"dy" = self.dy]
|
||||
gen_attrs![b"dx": self.dx, b"dy": self.dy]
|
||||
}
|
||||
|
||||
fn tag_name(&self) -> &'static str {
|
||||
|
|
|
@ -14,32 +14,15 @@ pub struct Turbulence {
|
|||
impl WriteElement for Turbulence {
|
||||
#[allow(clippy::str_to_string, reason = "in macro invocation")]
|
||||
fn attrs(&self) -> Vec<quick_xml::events::attributes::Attribute> {
|
||||
// let mut r = gen_attrs!(
|
||||
// b"baseFrequency" = format!("{} {}", self.base_frequency.0, self.base_frequency.1)
|
||||
// );
|
||||
|
||||
// if self.num_octaves != 1 {
|
||||
// r.push(gen_attr!(b"numOctaves" = self.num_octaves));
|
||||
// }
|
||||
|
||||
// if self.seed != 0 {
|
||||
// r.push(gen_attr!(b"seed" = self.seed));
|
||||
// }
|
||||
|
||||
// if self.stitch_tiles != StitchTiles::NoStitch {
|
||||
// r.push(gen_attr!(b"stitchTiles" = "stitch"));
|
||||
// }
|
||||
|
||||
// if self.noise_type != NoiseType::Turbulence {
|
||||
// r.push(gen_attr!(b"type" = "fractalNoise"));
|
||||
// }
|
||||
gen_attrs_with_conds![
|
||||
b"baseFrequency" = format!("{} {}", self.base_frequency.0, self.base_frequency.1),
|
||||
self.num_octaves != 1 => b"numOctaves" = self.num_octaves,
|
||||
self.seed != 0 => b"seed" = self.seed,
|
||||
self.stitch_tiles != StitchTiles::NoStitch => b"stitchTiles" = "stitch",
|
||||
self.noise_type != NoiseType::Turbulence => b"type" = "fractalNoise"
|
||||
]
|
||||
let mut r = gen_attrs![b"baseFrequency": format!("{} {}", self.base_frequency.0, self.base_frequency.1)];
|
||||
gen_attrs![
|
||||
r;
|
||||
self.num_octaves != 1 => b"numOctaves": self.num_octaves,
|
||||
self.seed != 0 => b"seed": self.seed,
|
||||
self.stitch_tiles != StitchTiles::NoStitch => b"stitchTiles": "stitch",
|
||||
self.noise_type != NoiseType::Turbulence => b"type": "fractalNoise"
|
||||
];
|
||||
r
|
||||
}
|
||||
|
||||
fn tag_name(&self) -> &'static str {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue