svg-filters & basic parser #15
6 changed files with 114 additions and 1 deletions
|
@ -5,4 +5,4 @@ pub mod types;
|
|||
pub use types::nodes::Node;
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {}
|
||||
mod tests;
|
||||
|
|
19
crates/svg-filters/src/tests.rs
Normal file
19
crates/svg-filters/src/tests.rs
Normal file
|
@ -0,0 +1,19 @@
|
|||
mod color_matrix;
|
||||
|
||||
mod complex;
|
||||
mod gaussian_blur;
|
||||
mod offset;
|
||||
|
||||
mod blend {}
|
||||
mod component_transfer {}
|
||||
mod composite {}
|
||||
mod convolve_matrix {}
|
||||
mod diffuse_lighting {}
|
||||
mod displacement_map {}
|
||||
mod flood {}
|
||||
mod image {}
|
||||
mod merge {}
|
||||
mod morphology {}
|
||||
mod specular_lighting {}
|
||||
mod tile {}
|
||||
mod turbulence {}
|
25
crates/svg-filters/src/tests/color_matrix.rs
Normal file
25
crates/svg-filters/src/tests/color_matrix.rs
Normal file
|
@ -0,0 +1,25 @@
|
|||
use crate::{
|
||||
codegen::SvgDocument,
|
||||
types::nodes::{primitives::color_matrix::ColorMatrixType, standard_input::StandardInput},
|
||||
};
|
||||
|
||||
#[test]
|
||||
fn test_greyscale_channel_extraction() {
|
||||
let mut doc = SvgDocument::new();
|
||||
let greyscale = doc.create_filter("greyscale");
|
||||
|
||||
greyscale.color_matrix(
|
||||
StandardInput::SourceGraphic,
|
||||
ColorMatrixType::Matrix(Box::new([
|
||||
1., 0., 0., 0., 0., //
|
||||
1., 0., 0., 0., 0., //
|
||||
1., 0., 0., 0., 0., //
|
||||
0., 0., 0., 1., 0.,
|
||||
])),
|
||||
);
|
||||
|
||||
assert_eq!(
|
||||
doc.generate_svg(),
|
||||
r#"<svg><filter id="greyscale"><feColorMatrix values="1 0 0 0 0 1 0 0 0 0 1 0 0 0 0 0 0 0 1 0" in="SourceGraphic"/></filter></svg>"#
|
||||
);
|
||||
}
|
42
crates/svg-filters/src/tests/complex.rs
Normal file
42
crates/svg-filters/src/tests/complex.rs
Normal file
|
@ -0,0 +1,42 @@
|
|||
use crate::{
|
||||
codegen::SvgDocument,
|
||||
types::nodes::{primitives::color_matrix::ColorMatrixType, standard_input::StandardInput},
|
||||
};
|
||||
|
||||
#[test]
|
||||
fn test_chrom_abb() {
|
||||
let mut doc = SvgDocument::new();
|
||||
let chromabb = doc.create_filter("chromabb_gen");
|
||||
|
||||
let chan_r = chromabb.color_matrix(
|
||||
StandardInput::SourceGraphic,
|
||||
ColorMatrixType::Matrix(Box::new([
|
||||
1., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 1., 0.,
|
||||
])),
|
||||
);
|
||||
let offset_r = chromabb.offset(chan_r, 25., 0.);
|
||||
let blur_r = chromabb.gaussian_blur_xy(offset_r, 5, 0);
|
||||
|
||||
let chan_b = chromabb.color_matrix(
|
||||
StandardInput::SourceGraphic,
|
||||
ColorMatrixType::Matrix(Box::new([
|
||||
0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 1., 0., 0., 0., 0., 0., 1., 0.,
|
||||
])),
|
||||
);
|
||||
let offset_b = chromabb.offset(chan_b, -25., 0.);
|
||||
let blur_b = chromabb.gaussian_blur_xy(offset_b, 5, 0);
|
||||
|
||||
let composite_rb = chromabb.composite_arithmetic(blur_r, blur_b, 0., 1., 1., 0.);
|
||||
|
||||
let chan_g = chromabb.color_matrix(
|
||||
StandardInput::SourceGraphic,
|
||||
ColorMatrixType::Matrix(Box::new([
|
||||
0., 0., 0., 0., 0., 0., 1., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 1., 0.,
|
||||
])),
|
||||
);
|
||||
chromabb.composite_arithmetic(composite_rb, chan_g, 0., 1., 1., 0.);
|
||||
assert_eq!(
|
||||
doc.generate_svg(),
|
||||
r#"<svg><filter id="chromabb_gen"><feColorMatrix values="0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 1 0" in="SourceGraphic" result="r13"/><feColorMatrix values="0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 1 0" in="SourceGraphic" result="r9"/><feOffset dx="-25" dy="0" in="r9" result="r10"/><feGaussianBlur stdDeviation="5 0" in="r10" result="r11"/><feColorMatrix values="1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0" in="SourceGraphic" result="r6"/><feOffset dx="25" dy="0" in="r6" result="r7"/><feGaussianBlur stdDeviation="5 0" in="r7" result="r8"/><feComposite operator="arithmetic" k1="0" k2="1" k3="1" k4="0" in="r8" in2="r11" result="r12"/><feComposite operator="arithmetic" k1="0" k2="1" k3="1" k4="0" in="r12" in2="r13"/></filter></svg>"#
|
||||
);
|
||||
}
|
13
crates/svg-filters/src/tests/gaussian_blur.rs
Normal file
13
crates/svg-filters/src/tests/gaussian_blur.rs
Normal file
|
@ -0,0 +1,13 @@
|
|||
use crate::{codegen::SvgDocument, types::nodes::standard_input::StandardInput};
|
||||
|
||||
#[test]
|
||||
fn test_simple_blur() {
|
||||
let mut doc = SvgDocument::new();
|
||||
let blur = doc.create_filter("blur");
|
||||
|
||||
blur.gaussian_blur_xy(StandardInput::SourceGraphic, 30, 30);
|
||||
assert_eq!(
|
||||
doc.generate_svg(),
|
||||
r#"<svg><filter id="blur"><feGaussianBlur stdDeviation="30 30" in="SourceGraphic"/></filter></svg>"#
|
||||
)
|
||||
}
|
14
crates/svg-filters/src/tests/offset.rs
Normal file
14
crates/svg-filters/src/tests/offset.rs
Normal file
|
@ -0,0 +1,14 @@
|
|||
use crate::{codegen::SvgDocument, types::nodes::standard_input::StandardInput};
|
||||
|
||||
#[test]
|
||||
fn test_offset_simple() {
|
||||
let mut doc = SvgDocument::new();
|
||||
let mut offset = doc.create_filter("offset");
|
||||
|
||||
offset.offset(StandardInput::SourceGraphic, 25., -25.);
|
||||
|
||||
assert_eq!(
|
||||
doc.generate_svg(),
|
||||
r#"<svg><filter id="offset"><feOffset dx="25" dy="-25" in="SourceGraphic"/></filter></svg>"#
|
||||
)
|
||||
}
|
Loading…
Reference in a new issue