svg-filters: get bare basic xml generation going

This commit is contained in:
Schrottkatze 2024-03-15 22:45:28 +01:00
parent 56848a1b05
commit 01b1880089
Signed by: schrottkatze
SSH key fingerprint: SHA256:hXb3t1vINBFCiDCmhRABHX5ocdbLiKyCdKI4HK2Rbbc
6 changed files with 227 additions and 9 deletions

View file

@ -1,6 +1,6 @@
/// [feBlend](https://www.w3.org/TR/SVG11/filters.html#feBlendElement)
#[derive(Debug)]
pub(in crate::types::nodes) struct Blend {
pub struct Blend {
mode: BlendMode,
}

View file

@ -1,3 +1,9 @@
use std::borrow::Cow;
use quick_xml::{events::attributes::Attribute, name::QName, se::to_string};
use super::WriteElement;
/// [feColorMatrix](https://www.w3.org/TR/SVG11/filters.html#feColorMatrixElement)
#[derive(Debug)]
pub struct ColorMatrix {
@ -10,6 +16,34 @@ impl ColorMatrix {
}
}
impl WriteElement for ColorMatrix {
fn attrs(&self) -> Vec<quick_xml::events::attributes::Attribute> {
match &self.cm_type {
ColorMatrixType::Matrix(v) => vec![Attribute {
key: QName(b"values"),
value: Cow::from(
v.iter()
.map(|v| v.to_string())
.reduce(|mut acc, e| {
acc.push(' ');
acc.push_str(&e);
acc
})
.expect("Should be able to concatenate the thingies")
.into_bytes(),
),
}],
ColorMatrixType::Saturate(v) => todo!(),
ColorMatrixType::HueRotate(v) => todo!(),
ColorMatrixType::LuminanceToAlpha => todo!(),
}
}
fn tag_name(&self) -> &'static str {
"feColorMatrix"
}
}
#[derive(Debug)]
pub enum ColorMatrixType {
Matrix(Box<[f32; 20]>),