forked from katzen-cafe/iowo
47 lines
1.2 KiB
Rust
47 lines
1.2 KiB
Rust
use super::WriteElement;
|
|
|
|
/// [feColorMatrix](https://www.w3.org/TR/SVG11/filters.html#feColorMatrixElement)
|
|
#[derive(Debug)]
|
|
pub struct ColorMatrix {
|
|
cm_type: ColorMatrixType,
|
|
}
|
|
|
|
impl ColorMatrix {
|
|
pub fn new(cm_type: ColorMatrixType) -> Self {
|
|
Self { cm_type }
|
|
}
|
|
}
|
|
|
|
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
|
|
.iter()
|
|
.map(std::string::ToString::to_string)
|
|
.reduce(|mut acc, e| {
|
|
acc.push(' ');
|
|
acc.push_str(&e);
|
|
acc
|
|
})
|
|
.expect("fixed length arr should always work")
|
|
],
|
|
ColorMatrixType::Saturate(v) | ColorMatrixType::HueRotate(v) => {
|
|
gen_attrs![b"values": v]
|
|
}
|
|
ColorMatrixType::LuminanceToAlpha => Vec::new(),
|
|
}
|
|
}
|
|
|
|
fn tag_name(&self) -> &'static str {
|
|
"feColorMatrix"
|
|
}
|
|
}
|
|
|
|
#[derive(Debug)]
|
|
pub enum ColorMatrixType {
|
|
Matrix(Box<[f32; 20]>),
|
|
Saturate(f32),
|
|
HueRotate(f32),
|
|
LuminanceToAlpha,
|
|
}
|