/* This Source Code Form is subject to the terms of the Mozilla Public * License, v. 2.0. If a copy of the MPL was not distributed with this * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ //! Computed types for SVG properties. use app_units::Au; use values::RGBA; use values::computed::{LengthOrPercentage, NonNegativeLength}; use values::computed::{NonNegativeLengthOrPercentage, NonNegativeNumber, Number}; use values::computed::Opacity; use values::computed::color::Color; use values::computed::url::ComputedUrl; use values::generics::svg as generic; pub use values::specified::SVGPaintOrder; pub use values::specified::MozContextProperties; /// Computed SVG Paint value pub type SVGPaint = generic::SVGPaint; /// Computed SVG Paint Kind value pub type SVGPaintKind = generic::SVGPaintKind; impl Default for SVGPaint { fn default() -> Self { SVGPaint { kind: generic::SVGPaintKind::None, fallback: None, } } } impl SVGPaint { /// Opaque black color pub fn black() -> Self { let rgba = RGBA::from_floats(0., 0., 0., 1.).into(); SVGPaint { kind: generic::SVGPaintKind::Color(rgba), fallback: None, } } } /// A value of | | for stroke-dashoffset. /// pub type SvgLengthOrPercentageOrNumber = generic::SvgLengthOrPercentageOrNumber; /// | | | context-value pub type SVGLength = generic::SVGLength; impl From for SVGLength { fn from(length: Au) -> Self { generic::SVGLength::Length(generic::SvgLengthOrPercentageOrNumber::LengthOrPercentage( length.into(), )) } } /// A value of | | for stroke-width/stroke-dasharray. /// pub type NonNegativeSvgLengthOrPercentageOrNumber = generic::SvgLengthOrPercentageOrNumber; impl Into for SvgLengthOrPercentageOrNumber { fn into(self) -> NonNegativeSvgLengthOrPercentageOrNumber { match self { generic::SvgLengthOrPercentageOrNumber::LengthOrPercentage(lop) => { generic::SvgLengthOrPercentageOrNumber::LengthOrPercentage(lop.into()) }, generic::SvgLengthOrPercentageOrNumber::Number(num) => { generic::SvgLengthOrPercentageOrNumber::Number(num.into()) }, } } } /// An non-negative wrapper of SVGLength. pub type SVGWidth = generic::SVGLength; impl From for SVGWidth { fn from(length: NonNegativeLength) -> Self { generic::SVGLength::Length(generic::SvgLengthOrPercentageOrNumber::LengthOrPercentage( length.into(), )) } } /// [ | | ]# | context-value pub type SVGStrokeDashArray = generic::SVGStrokeDashArray; impl Default for SVGStrokeDashArray { fn default() -> Self { generic::SVGStrokeDashArray::Values(vec![]) } } /// | context-fill-opacity | context-stroke-opacity pub type SVGOpacity = generic::SVGOpacity; impl Default for SVGOpacity { fn default() -> Self { generic::SVGOpacity::Opacity(1.) } }