forked from katzen-cafe/iowo
svg-filters: get bare basic xml generation going
This commit is contained in:
parent
56848a1b05
commit
01b1880089
6 changed files with 227 additions and 9 deletions
|
@ -1,3 +1,5 @@
|
|||
use quick_xml::{events::attributes::Attribute, ElementWriter, Writer};
|
||||
|
||||
use crate::types::length::{Coordinate, Length};
|
||||
|
||||
use self::blend::BlendMode;
|
||||
|
@ -21,6 +23,19 @@ pub mod specular_lighting;
|
|||
pub mod tile;
|
||||
pub mod turbulence;
|
||||
|
||||
pub trait WriteElement {
|
||||
fn attrs(&self) -> Vec<Attribute>;
|
||||
fn tag_name(&self) -> &'static str;
|
||||
fn element_writer<'writer, 'result>(
|
||||
&self,
|
||||
writer: &'writer mut Writer<&'result mut Vec<u8>>,
|
||||
) -> ElementWriter<'writer, &'result mut Vec<u8>> {
|
||||
writer
|
||||
.create_element(self.tag_name())
|
||||
.with_attributes(self.attrs())
|
||||
}
|
||||
}
|
||||
|
||||
/// svg filter effects primitives
|
||||
#[derive(Debug)]
|
||||
pub enum FePrimitive {
|
||||
|
@ -42,3 +57,47 @@ pub enum FePrimitive {
|
|||
Tile(tile::Tile),
|
||||
Turbulence(turbulence::Turbulence),
|
||||
}
|
||||
|
||||
impl WriteElement for FePrimitive {
|
||||
fn attrs(&self) -> std::vec::Vec<quick_xml::events::attributes::Attribute<'_>> {
|
||||
match self {
|
||||
FePrimitive::Blend(_) => todo!(),
|
||||
FePrimitive::ColorMatrix(cm) => cm.attrs(),
|
||||
FePrimitive::ComponentTransfer(_) => todo!(),
|
||||
FePrimitive::Composite(_) => todo!(),
|
||||
FePrimitive::ConvolveMatrix(_) => todo!(),
|
||||
FePrimitive::DiffuseLighting(_) => todo!(),
|
||||
FePrimitive::DisplacementMap(_) => todo!(),
|
||||
FePrimitive::Flood(_) => todo!(),
|
||||
FePrimitive::GaussianBlur(_) => todo!(),
|
||||
FePrimitive::Image(_) => todo!(),
|
||||
FePrimitive::Merge(_) => todo!(),
|
||||
FePrimitive::Morphology(_) => todo!(),
|
||||
FePrimitive::Offset(_) => todo!(),
|
||||
FePrimitive::SpecularLighting(_) => todo!(),
|
||||
FePrimitive::Tile(_) => todo!(),
|
||||
FePrimitive::Turbulence(_) => todo!(),
|
||||
}
|
||||
}
|
||||
|
||||
fn tag_name(&self) -> &'static str {
|
||||
match self {
|
||||
FePrimitive::Blend(_) => todo!(),
|
||||
FePrimitive::ColorMatrix(cm) => cm.tag_name(),
|
||||
FePrimitive::ComponentTransfer(_) => todo!(),
|
||||
FePrimitive::Composite(_) => todo!(),
|
||||
FePrimitive::ConvolveMatrix(_) => todo!(),
|
||||
FePrimitive::DiffuseLighting(_) => todo!(),
|
||||
FePrimitive::DisplacementMap(_) => todo!(),
|
||||
FePrimitive::Flood(_) => todo!(),
|
||||
FePrimitive::GaussianBlur(_) => todo!(),
|
||||
FePrimitive::Image(_) => todo!(),
|
||||
FePrimitive::Merge(_) => todo!(),
|
||||
FePrimitive::Morphology(_) => todo!(),
|
||||
FePrimitive::Offset(_) => todo!(),
|
||||
FePrimitive::SpecularLighting(_) => todo!(),
|
||||
FePrimitive::Tile(_) => todo!(),
|
||||
FePrimitive::Turbulence(_) => todo!(),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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,
|
||||
}
|
||||
|
||||
|
|
|
@ -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]>),
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue