svg-filters: new conditional attrs macro

This commit is contained in:
Schrottkatze 2024-03-19 18:43:30 +01:00
parent dc7d76dc26
commit aeeee54200
Signed by: schrottkatze
SSH key fingerprint: SHA256:hXb3t1vINBFCiDCmhRABHX5ocdbLiKyCdKI4HK2Rbbc
3 changed files with 61 additions and 41 deletions

View file

@ -3,38 +3,43 @@ use super::WriteElement;
/// [feTurbulence](https://www.w3.org/TR/SVG11/filters.html#feTurbulenceElement)
#[derive(Debug)]
pub struct Turbulence {
base_frequency: (f32, f32),
num_octaves: u16,
seed: u32,
stitch_tiles: StitchTiles,
pub base_frequency: (f32, f32),
pub num_octaves: u16,
pub seed: u32,
pub stitch_tiles: StitchTiles,
// attr name: type
noise_type: NoiseType,
pub noise_type: NoiseType,
}
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)
);
// 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.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.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.stitch_tiles != StitchTiles::NoStitch {
// r.push(gen_attr!(b"stitchTiles" = "stitch"));
// }
if self.noise_type != NoiseType::Turbulence {
r.push(gen_attr!(b"type" = "fractalNoise"));
}
r
// 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"
]
}
fn tag_name(&self) -> &'static str {