use std::fmt;
use std::ops::Deref;
pub use svgdom::{
Align,
AspectRatio,
Color,
FuzzyEq,
FuzzyZero,
NumberList,
Transform,
};
use geom::*;
#[derive(Clone, Copy, PartialEq, Debug)]
pub struct Opacity(f64);
impl Opacity {
pub fn new(n: f64) -> Self {
debug_assert!(n >= 0.0 && n <= 1.0);
Opacity(n)
}
pub fn value(&self) -> f64 {
self.0
}
}
impl From<f64> for Opacity {
fn from(n: f64) -> Self {
Opacity::new(n)
}
}
impl Deref for Opacity {
type Target = f64;
fn deref(&self) -> &Self::Target {
&self.0
}
}
pub type StopOffset = Opacity;
#[allow(missing_docs)]
#[derive(Clone, Copy, PartialEq, Debug)]
pub enum LineCap {
Butt,
Round,
Square,
}
#[allow(missing_docs)]
#[derive(Clone, Copy, PartialEq, Debug)]
pub enum LineJoin {
Miter,
Round,
Bevel,
}
#[allow(missing_docs)]
#[derive(Clone, Copy, PartialEq, Debug)]
pub enum FillRule {
NonZero,
EvenOdd,
}
#[allow(missing_docs)]
#[derive(Clone, Copy, PartialEq, Debug)]
pub enum Units {
UserSpaceOnUse,
ObjectBoundingBox,
}
#[allow(missing_docs)]
#[derive(Clone, Copy, PartialEq, Debug)]
pub enum SpreadMethod {
Pad,
Reflect,
Repeat,
}
#[allow(missing_docs)]
#[derive(Clone, Debug)]
pub struct TextDecorationStyle {
pub fill: Option<Fill>,
pub stroke: Option<Stroke>,
}
impl Default for TextDecorationStyle {
fn default() -> Self {
TextDecorationStyle {
fill: None,
stroke: None,
}
}
}
#[derive(Clone, Debug)]
pub struct TextDecoration {
pub underline: Option<TextDecorationStyle>,
pub overline: Option<TextDecorationStyle>,
pub line_through: Option<TextDecorationStyle>,
}
impl Default for TextDecoration {
fn default() -> Self {
TextDecoration {
underline: None,
overline: None,
line_through: None,
}
}
}
#[allow(missing_docs)]
#[derive(Clone, Copy, PartialEq, Debug)]
pub enum TextAnchor {
Start,
Middle,
End,
}
#[allow(missing_docs)]
#[derive(Clone, Copy, PartialEq, Debug)]
pub enum FontStyle {
Normal,
Italic,
Oblique,
}
#[allow(missing_docs)]
#[derive(Clone, Copy, PartialEq, Debug)]
pub enum FontVariant {
Normal,
SmallCaps,
}
#[allow(missing_docs)]
#[derive(Clone, Copy, PartialEq, Debug)]
pub enum FontWeight {
W100,
W200,
W300,
W400,
W500,
W600,
W700,
W800,
W900,
}
#[allow(missing_docs)]
#[derive(Clone, Copy, PartialEq, Debug)]
pub enum FontStretch {
Normal,
Wider,
Narrower,
UltraCondensed,
ExtraCondensed,
Condensed,
SemiCondensed,
SemiExpanded,
Expanded,
ExtraExpanded,
UltraExpanded,
}
#[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::new(0, 0, 0)),
opacity: 1.0.into(),
rule: FillRule::NonZero,
}
}
}
#[allow(missing_docs)]
#[derive(Clone, Debug)]
pub struct Stroke {
pub paint: Paint,
pub dasharray: Option<NumberList>,
pub dashoffset: f64,
pub miterlimit: f64,
pub opacity: Opacity,
pub width: f64,
pub linecap: LineCap,
pub linejoin: LineJoin,
}
impl Default for Stroke {
fn default() -> Self {
Stroke {
paint: Paint::Color(Color::new(0, 0, 0)),
dasharray: None,
dashoffset: 0.0,
miterlimit: 4.0,
opacity: 1.0.into(),
width: 1.0,
linecap: LineCap::Butt,
linejoin: LineJoin::Miter,
}
}
}
#[allow(missing_docs)]
#[derive(Clone, Debug)]
pub struct Font {
pub family: String,
pub size: f64,
pub style: FontStyle,
pub variant: FontVariant,
pub weight: FontWeight,
pub stretch: FontStretch,
}
impl Default for Font {
fn default() -> Self {
Font {
family: ::DEFAULT_FONT_FAMILY.to_owned(),
size: ::DEFAULT_FONT_SIZE,
style: FontStyle::Normal,
variant: FontVariant::Normal,
weight: FontWeight::W400,
stretch: FontStretch::Normal,
}
}
}
#[derive(Clone, Copy, PartialEq, Debug)]
pub struct ViewBox {
pub rect: Rect,
pub aspect: AspectRatio,
}
#[allow(missing_docs)]
#[derive(Clone, Copy, PartialEq, 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,
}