use std::borrow::Cow;
use crate::paint::*;
impl From<BlendMode> for &'static str {
fn from(mode: BlendMode) -> Self {
match mode {
BlendMode::SourceOver => "source-over",
BlendMode::DestinationOver => "destination-over",
BlendMode::Source => "copy",
BlendMode::SourceIn => "source-in",
BlendMode::DestinationIn => "destination-in",
BlendMode::SourceOut => "source-out",
BlendMode::DestinationOut => "destination-out",
BlendMode::SourceAtop => "source-atop",
BlendMode::DestinationAtop => "destination-atop",
BlendMode::Clear => "clear",
BlendMode::Xor => "xor",
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",
}
}
}
impl From<Cap> for &'static str {
fn from(cap: Cap) -> Self {
match cap {
Cap::Butt => "butt",
Cap::Round => "round",
Cap::Square => "square",
}
}
}
impl From<Join> for &'static str {
fn from(join: Join) -> Self {
match join {
Join::Miter => "miter",
Join::Round => "round",
Join::Bevel => "bevel",
}
}
}
impl From<Color> for Cow<'static, str> {
fn from(color: Color) -> Self {
match color {
BLACK => Cow::Borrowed("black"),
WHITE => Cow::Borrowed("white"),
RED => Cow::Borrowed("red"),
GREEN => Cow::Borrowed("lime"),
BLUE => Cow::Borrowed("blue"),
YELLOW => Cow::Borrowed("yellow"),
CYAN => Cow::Borrowed("cyan"),
MAGENTA => Cow::Borrowed("magenta"),
TRANSPARENT => Cow::Borrowed("transparent"),
_ => {
let (r, g, b, a) = color.get_byte_value();
if a == 255 {
Cow::Owned(format!("#{:02x}{:02x}{:02x}", r, g, b))
} else {
Cow::Owned(format!("rgb({} {} {} /{}%)", r, g, b, (a as f64 * 100.0 / 255.0).round() as u8))
}
}
}
}
}