use std::fmt;
use std::path::PathBuf;
pub use svgdom::{
Align,
AspectRatio,
Color,
FuzzyEq,
FuzzyZero,
Transform,
};
use geom::*;
pub use super::numbers::*;
macro_rules! enum_default {
($name:ident, $def_value:ident) => {
impl Default for $name {
fn default() -> Self {
$name::$def_value
}
}
};
}
#[allow(missing_docs)]
#[derive(Clone, Copy, PartialEq, Debug)]
pub enum LineCap {
Butt,
Round,
Square,
}
enum_default!(LineCap, Butt);
impl ToString for LineCap {
fn to_string(&self) -> String {
match self {
LineCap::Butt => "butt",
LineCap::Round => "round",
LineCap::Square => "square",
}.to_string()
}
}
#[allow(missing_docs)]
#[derive(Clone, Copy, PartialEq, Debug)]
pub enum LineJoin {
Miter,
Round,
Bevel,
}
enum_default!(LineJoin, Miter);
impl ToString for LineJoin {
fn to_string(&self) -> String {
match self {
LineJoin::Miter => "miter",
LineJoin::Round => "round",
LineJoin::Bevel => "bevel",
}.to_string()
}
}
#[allow(missing_docs)]
#[derive(Clone, Copy, PartialEq, Debug)]
pub enum FillRule {
NonZero,
EvenOdd,
}
enum_default!(FillRule, NonZero);
impl ToString for FillRule {
fn to_string(&self) -> String {
match self {
FillRule::NonZero => "nonzero",
FillRule::EvenOdd => "evenodd",
}.to_string()
}
}
#[allow(missing_docs)]
#[derive(Clone, Copy, PartialEq, Debug)]
pub enum Units {
UserSpaceOnUse,
ObjectBoundingBox,
}
impl ToString for Units {
fn to_string(&self) -> String {
match self {
Units::UserSpaceOnUse => "userSpaceOnUse",
Units::ObjectBoundingBox => "objectBoundingBox",
}.to_string()
}
}
#[allow(missing_docs)]
#[derive(Clone, Copy, PartialEq, Debug)]
pub enum SpreadMethod {
Pad,
Reflect,
Repeat,
}
enum_default!(SpreadMethod, Pad);
impl ToString for SpreadMethod {
fn to_string(&self) -> String {
match self {
SpreadMethod::Pad => "pad",
SpreadMethod::Reflect => "reflect",
SpreadMethod::Repeat => "repeat",
}.to_string()
}
}
#[allow(missing_docs)]
#[derive(Clone, Copy, PartialEq, Debug)]
pub enum Visibility {
Visible,
Hidden,
Collapse,
}
enum_default!(Visibility, Visible);
impl ToString for Visibility {
fn to_string(&self) -> String {
match self {
Visibility::Visible => "visible",
Visibility::Hidden => "hidden",
Visibility::Collapse => "collapse",
}.to_string()
}
}
#[allow(missing_docs)]
#[derive(Clone, Default, Debug)]
pub struct TextDecorationStyle {
pub fill: Option<Fill>,
pub stroke: Option<Stroke>,
}
#[derive(Clone, Default, Debug)]
pub struct TextDecoration {
pub underline: Option<TextDecorationStyle>,
pub overline: Option<TextDecorationStyle>,
pub line_through: Option<TextDecorationStyle>,
}
#[allow(missing_docs)]
#[derive(Clone, Copy, PartialEq, Debug)]
pub enum TextAnchor {
Start,
Middle,
End,
}
enum_default!(TextAnchor, Start);
impl ToString for TextAnchor {
fn to_string(&self) -> String {
match self {
TextAnchor::Start => "start",
TextAnchor::Middle => "middle",
TextAnchor::End => "end",
}.to_string()
}
}
#[allow(missing_docs)]
#[derive(Clone, Copy, PartialEq, Debug)]
pub enum FontStyle {
Normal,
Italic,
Oblique,
}
enum_default!(FontStyle, Normal);
impl ToString for FontStyle {
fn to_string(&self) -> String {
match self {
FontStyle::Normal => "normal",
FontStyle::Italic => "italic",
FontStyle::Oblique => "oblique",
}.to_string()
}
}
#[allow(missing_docs)]
#[derive(Clone, Copy, PartialEq, Debug)]
pub enum FontVariant {
Normal,
SmallCaps,
}
enum_default!(FontVariant, Normal);
impl ToString for FontVariant {
fn to_string(&self) -> String {
match self {
FontVariant::Normal => "normal",
FontVariant::SmallCaps => "small-caps",
}.to_string()
}
}
#[allow(missing_docs)]
#[derive(Clone, Copy, PartialEq, Debug)]
pub enum FontWeight {
W100,
W200,
W300,
W400,
W500,
W600,
W700,
W800,
W900,
}
enum_default!(FontWeight, W400);
impl ToString for FontWeight {
fn to_string(&self) -> String {
match self {
FontWeight::W100 => "100",
FontWeight::W200 => "200",
FontWeight::W300 => "300",
FontWeight::W400 => "400",
FontWeight::W500 => "500",
FontWeight::W600 => "600",
FontWeight::W700 => "700",
FontWeight::W800 => "800",
FontWeight::W900 => "900",
}.to_string()
}
}
#[allow(missing_docs)]
#[derive(Clone, Copy, PartialEq, Debug)]
pub enum FontStretch {
Normal,
Wider,
Narrower,
UltraCondensed,
ExtraCondensed,
Condensed,
SemiCondensed,
SemiExpanded,
Expanded,
ExtraExpanded,
UltraExpanded,
}
enum_default!(FontStretch, Normal);
impl ToString for FontStretch {
fn to_string(&self) -> String {
match self {
FontStretch::Normal => "normal",
FontStretch::Wider => "wider",
FontStretch::Narrower => "narrower",
FontStretch::UltraCondensed => "ultra-condensed",
FontStretch::ExtraCondensed => "extra-condensed",
FontStretch::Condensed => "condensed",
FontStretch::SemiCondensed => "semi-condensed",
FontStretch::SemiExpanded => "semi-expanded",
FontStretch::Expanded => "expanded",
FontStretch::ExtraExpanded => "extra-expanded",
FontStretch::UltraExpanded => "ultra-expanded",
}.to_string()
}
}
#[allow(missing_docs)]
#[derive(Clone)]
pub enum Paint {
Color(Color),
Link(String),
}
impl fmt::Debug for Paint {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
match *self {
Paint::Color(c) => write!(f, "Color({})", c),
Paint::Link(_) => write!(f, "Link"),
}
}
}
#[allow(missing_docs)]
#[derive(Clone, Debug)]
pub struct Fill {
pub paint: Paint,
pub opacity: Opacity,
pub rule: FillRule,
}
impl Default for Fill {
fn default() -> Self {
Fill {
paint: Paint::Color(Color::black()),
opacity: Opacity::default(),
rule: FillRule::default(),
}
}
}
#[allow(missing_docs)]
#[derive(Clone, Debug)]
pub struct Stroke {
pub paint: Paint,
pub dasharray: Option<Vec<f64>>,
pub dashoffset: f32,
pub miterlimit: StrokeMiterlimit,
pub opacity: Opacity,
pub width: StrokeWidth,
pub linecap: LineCap,
pub linejoin: LineJoin,
}
impl Default for Stroke {
fn default() -> Self {
Stroke {
paint: Paint::Color(Color::black()),
dasharray: None,
dashoffset: 0.0,
miterlimit: StrokeMiterlimit::default(),
opacity: Opacity::default(),
width: StrokeWidth::default(),
linecap: LineCap::default(),
linejoin: LineJoin::default(),
}
}
}
#[allow(missing_docs)]
#[derive(Clone, Debug)]
pub struct Font {
pub family: String,
pub size: FontSize,
pub style: FontStyle,
pub variant: FontVariant,
pub weight: FontWeight,
pub stretch: FontStretch,
pub letter_spacing: Option<f64>,
pub word_spacing: Option<f64>,
}
#[derive(Clone, Copy, Debug)]
pub struct ViewBox {
pub rect: Rect,
pub aspect: AspectRatio,
}
#[allow(missing_docs)]
#[derive(Clone, Copy, Debug)]
pub enum PathSegment {
MoveTo {
x: f64,
y: f64,
},
LineTo {
x: f64,
y: f64,
},
CurveTo {
x1: f64,
y1: f64,
x2: f64,
y2: f64,
x: f64,
y: f64,
},
ClosePath,
}
#[allow(missing_docs)]
#[derive(Clone, PartialEq, Debug)]
pub enum FilterInput {
SourceGraphic,
SourceAlpha,
BackgroundImage,
BackgroundAlpha,
FillPaint,
StrokePaint,
Reference(String),
}
impl ToString for FilterInput {
fn to_string(&self) -> String {
match self {
FilterInput::SourceGraphic => "SourceGraphic",
FilterInput::SourceAlpha => "SourceAlpha",
FilterInput::BackgroundImage => "BackgroundImage",
FilterInput::BackgroundAlpha => "BackgroundAlpha",
FilterInput::FillPaint => "FillPaint",
FilterInput::StrokePaint => "StrokePaint",
FilterInput::Reference(ref s) => s,
}.to_string()
}
}
#[allow(missing_docs)]
#[derive(Clone, Copy, PartialEq, Debug)]
pub enum ColorInterpolation {
SRGB,
LinearRGB,
}
impl ToString for ColorInterpolation {
fn to_string(&self) -> String {
match self {
ColorInterpolation::SRGB => "sRGB",
ColorInterpolation::LinearRGB => "linearRGB",
}.to_string()
}
}
#[derive(Clone, Debug)]
pub enum ImageData {
Path(PathBuf),
Raw(Vec<u8>),
}
#[allow(missing_docs)]
#[derive(Clone, Copy, PartialEq, Debug)]
pub enum ImageFormat {
PNG,
JPEG,
SVG,
}
#[allow(missing_docs)]
#[derive(Clone, Copy, PartialEq, Debug)]
pub enum FeBlendMode {
Normal,
Multiply,
Screen,
Darken,
Lighten,
}
impl ToString for FeBlendMode {
fn to_string(&self) -> String {
match self {
FeBlendMode::Normal => "normal",
FeBlendMode::Multiply => "multiply",
FeBlendMode::Screen => "screen",
FeBlendMode::Darken => "darken",
FeBlendMode::Lighten => "lighten",
}.to_string()
}
}
#[allow(missing_docs)]
#[derive(Clone, Copy, PartialEq, Debug)]
pub enum FeCompositeOperator {
Over,
In,
Out,
Atop,
Xor,
Arithmetic,
}
impl ToString for FeCompositeOperator {
fn to_string(&self) -> String {
match self {
FeCompositeOperator::Over => "over",
FeCompositeOperator::In => "in",
FeCompositeOperator::Out => "out",
FeCompositeOperator::Atop => "atop",
FeCompositeOperator::Xor => "xor",
FeCompositeOperator::Arithmetic => "arithmetic",
}.to_string()
}
}
#[derive(Clone, Debug)]
pub enum FeImageKind {
None,
Image(ImageData, ImageFormat),
Use(String),
}