forked from katzen-cafe/iowo
82 lines
1.9 KiB
Rust
82 lines
1.9 KiB
Rust
use std::fmt::Display;
|
|
|
|
use super::WriteElement;
|
|
|
|
/// [feBlend](https://www.w3.org/TR/SVG11/filters.html#feBlendElement)
|
|
#[derive(Debug)]
|
|
pub struct Blend {
|
|
mode: BlendMode,
|
|
}
|
|
|
|
impl Blend {
|
|
pub fn new(mode: BlendMode) -> Self {
|
|
Self { mode }
|
|
}
|
|
}
|
|
|
|
impl Default for Blend {
|
|
fn default() -> Self {
|
|
Self {
|
|
mode: BlendMode::Normal,
|
|
}
|
|
}
|
|
}
|
|
|
|
impl WriteElement for Blend {
|
|
fn attrs(&self) -> Vec<quick_xml::events::attributes::Attribute> {
|
|
if let BlendMode::Normal = self.mode {
|
|
Vec::new()
|
|
} else {
|
|
gen_attrs![b"mode": self.mode]
|
|
}
|
|
}
|
|
|
|
fn tag_name(&self) -> &'static str {
|
|
"feBlend"
|
|
}
|
|
}
|
|
|
|
/// as according to https://drafts.fxtf.org/compositing-1/#blending
|
|
#[derive(Debug)]
|
|
pub enum BlendMode {
|
|
Normal,
|
|
Multiply,
|
|
Screen,
|
|
Overlay,
|
|
Darken,
|
|
Lighten,
|
|
ColorDodge,
|
|
ColorBurn,
|
|
HardLight,
|
|
SoftLight,
|
|
Difference,
|
|
Exclusion,
|
|
|
|
Hue,
|
|
Saturation,
|
|
Color,
|
|
Luminosity,
|
|
}
|
|
|
|
impl Display for BlendMode {
|
|
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
|
|
f.write_str(match self {
|
|
BlendMode::Normal => "normal",
|
|
BlendMode::Multiply => "multiply",
|
|
BlendMode::Screen => "screen",
|
|
BlendMode::Overlay => "overlay",
|
|
BlendMode::Darken => "darken",
|
|
BlendMode::Lighten => "lighten",
|
|
BlendMode::ColorDodge => "color-dodge",
|
|
BlendMode::ColorBurn => "color-burn",
|
|
BlendMode::HardLight => "hard-light",
|
|
BlendMode::SoftLight => "soft-light",
|
|
BlendMode::Difference => "difference",
|
|
BlendMode::Exclusion => "exclusion",
|
|
BlendMode::Hue => "hue",
|
|
BlendMode::Saturation => "saturation",
|
|
BlendMode::Color => "color",
|
|
BlendMode::Luminosity => "luminosity",
|
|
})
|
|
}
|
|
}
|