use std::fmt;
use std::ops::Deref;
pub use svgdom::{
Align,
AspectRatio,
Color,
FuzzyEq,
FuzzyZero,
NumberList,
Transform,
};
use geom::*;
#[derive(Clone, Copy, Debug)]
pub struct Opacity(f64);
impl Opacity {
pub fn new(n: f64) -> Self {
debug_assert!(n >= 0.0 && n <= 1.0);
Opacity(f64_bound(0.0, n, 1.0))
}
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;
#[derive(Clone, Copy, Debug)]
pub struct StrokeWidth(f64);
impl StrokeWidth {
pub fn new(n: f64) -> Self {
debug_assert!(n > 0.0);
let n = if n <= 0.0 { 1.0 } else { n };
StrokeWidth(n)
}
pub fn value(&self) -> f64 {
self.0
}
}
impl From<f64> for StrokeWidth {
fn from(n: f64) -> Self {
StrokeWidth::new(n)
}
}
impl Deref for StrokeWidth {
type Target = f64;
fn deref(&self) -> &Self::Target {
&self.0
}
}
impl Default for StrokeWidth {
fn default() -> Self {
StrokeWidth::new(1.0)
}
}
#[derive(Clone, Copy, Debug)]
pub struct PositiveNumber(f64);
impl PositiveNumber {
pub fn new(n: f64) -> Self {
debug_assert!(!n.is_sign_negative());
let n = if n.is_sign_negative() { 0.0 } else { n };
PositiveNumber(n)
}
pub fn value(&self) -> f64 {
self.0
}
pub fn is_zero(&self) -> bool {
self.0.is_fuzzy_zero()
}
}
impl From<f64> for PositiveNumber {
fn from(n: f64) -> Self {
PositiveNumber::new(n)
}
}
impl Deref for PositiveNumber {
type Target = f64;
fn deref(&self) -> &Self::Target {
&self.0
}
}
#[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, Copy, PartialEq, Debug)]
pub enum Visibility {
Visible,
Hidden,
Collapse,
}
#[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::black()),
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: 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: 4.0,
opacity: 1.0.into(),
width: StrokeWidth::default(),
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,
}
#[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()
}
}