Split Length into LengthHorizontal/LengthVertical/LengthBoth

This will help remove the Data associated type from the Parse trait.
parent bbb1e285
......@@ -3,7 +3,7 @@ use cairo::{self, MatrixTrait};
use bbox::BoundingBox;
use drawing_ctx::DrawingCtx;
use length::Length;
use length::{LengthHorizontal, LengthVertical};
use rect::IRect;
use super::context::{FilterContext, FilterInput, FilterOutput};
......@@ -21,10 +21,10 @@ pub struct BoundsBuilder<'a> {
standard_input_was_referenced: bool,
/// Filter primitive properties.
x: Option<Length>,
y: Option<Length>,
width: Option<Length>,
height: Option<Length>,
x: Option<LengthHorizontal>,
y: Option<LengthVertical>,
width: Option<LengthHorizontal>,
height: Option<LengthVertical>,
}
impl<'a> BoundsBuilder<'a> {
......@@ -32,10 +32,10 @@ impl<'a> BoundsBuilder<'a> {
#[inline]
pub fn new(
ctx: &'a FilterContext,
x: Option<Length>,
y: Option<Length>,
width: Option<Length>,
height: Option<Length>,
x: Option<LengthHorizontal>,
y: Option<LengthVertical>,
width: Option<LengthHorizontal>,
height: Option<LengthVertical>,
) -> Self {
Self {
ctx,
......
......@@ -9,7 +9,7 @@ use attributes::Attribute;
use coord_units::CoordUnits;
use drawing_ctx::DrawingCtx;
use error::{RenderingError, ValueErrorKind};
use length::{Length, LengthDir, LengthUnit};
use length::{LengthHorizontal, LengthUnit, LengthVertical};
use node::{NodeResult, NodeTrait, NodeType, RsvgNode};
use parsers::{ParseError, ParseValue};
use properties::{ColorInterpolationFilters, ComputedValues};
......@@ -70,10 +70,10 @@ trait Filter: NodeTrait {
/// The base filter primitive node containing common properties.
struct Primitive {
x: Cell<Option<Length>>,
y: Cell<Option<Length>>,
width: Cell<Option<Length>>,
height: Cell<Option<Length>>,
x: Cell<Option<LengthHorizontal>>,
y: Cell<Option<LengthVertical>>,
width: Cell<Option<LengthHorizontal>>,
height: Cell<Option<LengthVertical>>,
result: RefCell<Option<String>>,
}
......@@ -124,42 +124,62 @@ impl NodeTrait for Primitive {
.unwrap_or(CoordUnits::UserSpaceOnUse);
let no_units_allowed = primitiveunits == CoordUnits::ObjectBoundingBox;
let check_units = |length: Length| {
let check_units_horizontal = |length: LengthHorizontal| {
if !no_units_allowed {
return Ok(length);
}
match length.unit() {
LengthUnit::Default | LengthUnit::Percent => Ok(length),
_ => Err(ValueErrorKind::Parse(ParseError::new(
"unit identifiers are not allowed with primitiveUnits set to objectBoundingBox",
))),
}
};
let check_units_vertical = |length: LengthVertical| {
if !no_units_allowed {
return Ok(length);
}
match length.unit {
match length.unit() {
LengthUnit::Default | LengthUnit::Percent => Ok(length),
_ => Err(ValueErrorKind::Parse(ParseError::new(
"unit identifiers are not allowed with primitiveUnits set to objectBoundingBox",
))),
}
};
let check_units_and_ensure_nonnegative =
|length: Length| check_units(length).and_then(Length::check_nonnegative);
let check_units_horizontal_and_ensure_nonnegative = |length: LengthHorizontal| {
check_units_horizontal(length).and_then(LengthHorizontal::check_nonnegative)
};
let check_units_vertical_and_ensure_nonnegative = |length: LengthVertical| {
check_units_vertical(length).and_then(LengthVertical::check_nonnegative)
};
for (attr, value) in pbag.iter() {
match attr {
Attribute::X => self.x.set(Some(attr.parse_and_validate(
value,
LengthDir::Horizontal,
check_units,
(),
check_units_horizontal,
)?)),
Attribute::Y => self.y.set(Some(attr.parse_and_validate(
value,
LengthDir::Vertical,
check_units,
(),
check_units_vertical,
)?)),
Attribute::Width => self.width.set(Some(attr.parse_and_validate(
value,
LengthDir::Horizontal,
check_units_and_ensure_nonnegative,
(),
check_units_horizontal_and_ensure_nonnegative,
)?)),
Attribute::Height => self.height.set(Some(attr.parse_and_validate(
value,
LengthDir::Vertical,
check_units_and_ensure_nonnegative,
(),
check_units_vertical_and_ensure_nonnegative,
)?)),
Attribute::Result => *self.result.borrow_mut() = Some(value.to_string()),
_ => (),
......
......@@ -4,17 +4,17 @@ use std::cell::Cell;
use attributes::Attribute;
use coord_units::CoordUnits;
use error::ValueErrorKind;
use length::{Length, LengthDir, LengthUnit};
use length::{LengthHorizontal, LengthUnit, LengthVertical};
use node::{NodeResult, NodeTrait, RsvgNode};
use parsers::{Parse, ParseError, ParseValue};
use property_bag::PropertyBag;
/// The <filter> node.
pub struct NodeFilter {
pub x: Cell<Length>,
pub y: Cell<Length>,
pub width: Cell<Length>,
pub height: Cell<Length>,
pub x: Cell<LengthHorizontal>,
pub y: Cell<LengthVertical>,
pub width: Cell<LengthHorizontal>,
pub height: Cell<LengthVertical>,
pub filterunits: Cell<CoordUnits>,
pub primitiveunits: Cell<CoordUnits>,
}
......@@ -24,10 +24,10 @@ impl NodeFilter {
#[inline]
pub fn new() -> Self {
Self {
x: Cell::new(Length::parse_str("-10%", LengthDir::Horizontal).unwrap()),
y: Cell::new(Length::parse_str("-10%", LengthDir::Vertical).unwrap()),
width: Cell::new(Length::parse_str("120%", LengthDir::Horizontal).unwrap()),
height: Cell::new(Length::parse_str("120%", LengthDir::Vertical).unwrap()),
x: Cell::new(LengthHorizontal::parse_str("-10%", ()).unwrap()),
y: Cell::new(LengthVertical::parse_str("-10%", ()).unwrap()),
width: Cell::new(LengthHorizontal::parse_str("120%", ()).unwrap()),
height: Cell::new(LengthVertical::parse_str("120%", ()).unwrap()),
filterunits: Cell::new(CoordUnits::ObjectBoundingBox),
primitiveunits: Cell::new(CoordUnits::UserSpaceOnUse),
}
......@@ -46,42 +46,61 @@ impl NodeTrait for NodeFilter {
// With ObjectBoundingBox, only fractions and percents are allowed.
let no_units_allowed = self.filterunits.get() == CoordUnits::ObjectBoundingBox;
let check_units = |length: Length| {
let check_units_horizontal = |length: LengthHorizontal| {
if !no_units_allowed {
return Ok(length);
}
match length.unit {
match length.unit() {
LengthUnit::Default | LengthUnit::Percent => Ok(length),
_ => Err(ValueErrorKind::Parse(ParseError::new(
"unit identifiers are not allowed with filterUnits set to objectBoundingBox",
))),
}
};
let check_units_and_ensure_nonnegative =
|length: Length| check_units(length).and_then(Length::check_nonnegative);
let check_units_vertical = |length: LengthVertical| {
if !no_units_allowed {
return Ok(length);
}
match length.unit() {
LengthUnit::Default | LengthUnit::Percent => Ok(length),
_ => Err(ValueErrorKind::Parse(ParseError::new(
"unit identifiers are not allowed with filterUnits set to objectBoundingBox",
))),
}
};
let check_units_horizontal_and_ensure_nonnegative = |length: LengthHorizontal| {
check_units_horizontal(length).and_then(LengthHorizontal::check_nonnegative)
};
let check_units_vertical_and_ensure_nonnegative = |length: LengthVertical| {
check_units_vertical(length).and_then(LengthVertical::check_nonnegative)
};
// Parse the rest of the attributes.
for (attr, value) in pbag.iter() {
match attr {
Attribute::X => self.x.set(attr.parse_and_validate(
value,
LengthDir::Horizontal,
check_units,
)?),
Attribute::X => {
self.x
.set(attr.parse_and_validate(value, (), check_units_horizontal)?)
}
Attribute::Y => {
self.y
.set(attr.parse_and_validate(value, LengthDir::Vertical, check_units)?)
.set(attr.parse_and_validate(value, (), check_units_vertical)?)
}
Attribute::Width => self.width.set(attr.parse_and_validate(
value,
LengthDir::Horizontal,
check_units_and_ensure_nonnegative,
(),
check_units_horizontal_and_ensure_nonnegative,
)?),
Attribute::Height => self.height.set(attr.parse_and_validate(
value,
LengthDir::Vertical,
check_units_and_ensure_nonnegative,
(),
check_units_vertical_and_ensure_nonnegative,
)?),
Attribute::PrimitiveUnits => self.primitiveunits.set(attr.parse(value, ())?),
_ => (),
......
......@@ -2,7 +2,7 @@ use cssparser::{BasicParseError, Parser, Token};
use drawing_ctx::ViewParams;
use error::*;
use length::{Length, LengthDir, LengthUnit, POINTS_PER_INCH};
use length::{LengthBoth, LengthHorizontal, LengthUnit, POINTS_PER_INCH};
use parsers::{Parse, ParseError};
use properties::ComputedValues;
......@@ -18,11 +18,11 @@ pub enum FontSizeSpec {
Large,
XLarge,
XXLarge,
Value(Length),
Value(LengthBoth),
}
impl FontSizeSpec {
pub fn value(&self) -> Length {
pub fn value(&self) -> LengthBoth {
match self {
FontSizeSpec::Value(s) => s.clone(),
_ => unreachable!(),
......@@ -35,31 +35,17 @@ impl FontSizeSpec {
let size = v.font_size.0.value();
let new_size = match self {
FontSizeSpec::Smaller => Length::new(size.length / 1.2, size.unit, LengthDir::Both),
FontSizeSpec::Larger => Length::new(size.length * 1.2, size.unit, LengthDir::Both),
FontSizeSpec::XXSmall => {
Length::new(compute_points(-3.0), LengthUnit::Inch, LengthDir::Both)
}
FontSizeSpec::XSmall => {
Length::new(compute_points(-2.0), LengthUnit::Inch, LengthDir::Both)
}
FontSizeSpec::Small => {
Length::new(compute_points(-1.0), LengthUnit::Inch, LengthDir::Both)
}
FontSizeSpec::Medium => {
Length::new(compute_points(0.0), LengthUnit::Inch, LengthDir::Both)
}
FontSizeSpec::Large => {
Length::new(compute_points(1.0), LengthUnit::Inch, LengthDir::Both)
}
FontSizeSpec::XLarge => {
Length::new(compute_points(2.0), LengthUnit::Inch, LengthDir::Both)
}
FontSizeSpec::XXLarge => {
Length::new(compute_points(3.0), LengthUnit::Inch, LengthDir::Both)
}
FontSizeSpec::Value(s) if s.unit == LengthUnit::Percent => {
Length::new(size.length * s.length, size.unit, LengthDir::Both)
FontSizeSpec::Smaller => LengthBoth::new(size.length() / 1.2, size.unit()),
FontSizeSpec::Larger => LengthBoth::new(size.length() * 1.2, size.unit()),
FontSizeSpec::XXSmall => LengthBoth::new(compute_points(-3.0), LengthUnit::Inch),
FontSizeSpec::XSmall => LengthBoth::new(compute_points(-2.0), LengthUnit::Inch),
FontSizeSpec::Small => LengthBoth::new(compute_points(-1.0), LengthUnit::Inch),
FontSizeSpec::Medium => LengthBoth::new(compute_points(0.0), LengthUnit::Inch),
FontSizeSpec::Large => LengthBoth::new(compute_points(1.0), LengthUnit::Inch),
FontSizeSpec::XLarge => LengthBoth::new(compute_points(2.0), LengthUnit::Inch),
FontSizeSpec::XXLarge => LengthBoth::new(compute_points(3.0), LengthUnit::Inch),
FontSizeSpec::Value(s) if s.unit() == LengthUnit::Percent => {
LengthBoth::new(size.length() * s.length(), size.unit())
}
FontSizeSpec::Value(s) => s.clone(),
};
......@@ -82,7 +68,7 @@ impl Parse for FontSizeSpec {
) -> Result<FontSizeSpec, ::error::ValueErrorKind> {
let parser_state = parser.state();
Length::parse(parser, LengthDir::Both)
LengthBoth::parse(parser, ())
.and_then(|s| Ok(FontSizeSpec::Value(s)))
.or_else(|e| {
parser.reset(&parser_state);
......@@ -184,11 +170,11 @@ impl Parse for FontWeightSpec {
#[derive(Debug, Copy, Clone, PartialEq)]
pub enum LetterSpacingSpec {
Normal,
Value(Length),
Value(LengthHorizontal),
}
impl LetterSpacingSpec {
pub fn value(&self) -> Length {
pub fn value(&self) -> LengthHorizontal {
match self {
LetterSpacingSpec::Value(s) => s.clone(),
_ => unreachable!(),
......@@ -197,9 +183,7 @@ impl LetterSpacingSpec {
pub fn compute(&self) -> Self {
let spacing = match self {
LetterSpacingSpec::Normal => {
Length::new(0.0, LengthUnit::Default, LengthDir::Horizontal)
}
LetterSpacingSpec::Normal => LengthHorizontal::new(0.0, LengthUnit::Default),
LetterSpacingSpec::Value(s) => s.clone(),
};
......@@ -221,7 +205,7 @@ impl Parse for LetterSpacingSpec {
) -> Result<LetterSpacingSpec, ::error::ValueErrorKind> {
let parser_state = parser.state();
Length::parse(parser, LengthDir::Horizontal)
LengthHorizontal::parse(parser, ())
.and_then(|s| Ok(LetterSpacingSpec::Value(s)))
.or_else(|e| {
parser.reset(&parser_state);
......@@ -323,10 +307,9 @@ mod tests {
);
assert_eq!(
<LetterSpacingSpec as Parse>::parse_str("10em", ()),
Ok(LetterSpacingSpec::Value(Length::new(
Ok(LetterSpacingSpec::Value(LengthHorizontal::new(
10.0,
LengthUnit::FontEm,
LengthDir::Horizontal
)))
);
}
......@@ -335,18 +318,16 @@ mod tests {
fn computes_letter_spacing() {
assert_eq!(
<LetterSpacingSpec as Parse>::parse_str("normal", ()).map(|s| s.compute()),
Ok(LetterSpacingSpec::Value(Length::new(
Ok(LetterSpacingSpec::Value(LengthHorizontal::new(
0.0,
LengthUnit::Default,
LengthDir::Horizontal
)))
);
assert_eq!(
<LetterSpacingSpec as Parse>::parse_str("10em", ()).map(|s| s.compute()),
Ok(LetterSpacingSpec::Value(Length::new(
Ok(LetterSpacingSpec::Value(LengthHorizontal::new(
10.0,
LengthUnit::FontEm,
LengthDir::Horizontal
)))
);
}
......
......@@ -91,18 +91,18 @@ pub struct GradientCommon {
#[derive(Copy, Clone)]
pub enum GradientVariant {
Linear {
x1: Option<Length>,
y1: Option<Length>,
x2: Option<Length>,
y2: Option<Length>,
x1: Option<LengthHorizontal>,
y1: Option<LengthVertical>,
x2: Option<LengthHorizontal>,
y2: Option<LengthVertical>,
},
Radial {
cx: Option<Length>,
cy: Option<Length>,
r: Option<Length>,
fx: Option<Length>,
fy: Option<Length>,
cx: Option<LengthHorizontal>,
cy: Option<LengthVertical>,
r: Option<LengthBoth>,
fx: Option<LengthHorizontal>,
fy: Option<LengthVertical>,
},
}
......@@ -256,10 +256,10 @@ impl GradientVariant {
// https://www.w3.org/TR/SVG/pservers.html#LinearGradients
GradientVariant::Linear {
x1: Some(Length::parse_str("0%", LengthDir::Horizontal).unwrap()),
y1: Some(Length::parse_str("0%", LengthDir::Vertical).unwrap()),
x2: Some(Length::parse_str("100%", LengthDir::Horizontal).unwrap()),
y2: Some(Length::parse_str("0%", LengthDir::Vertical).unwrap()),
x1: Some(LengthHorizontal::parse_str("0%", ()).unwrap()),
y1: Some(LengthVertical::parse_str("0%", ()).unwrap()),
x2: Some(LengthHorizontal::parse_str("100%", ()).unwrap()),
y2: Some(LengthVertical::parse_str("0%", ()).unwrap()),
}
}
......@@ -267,9 +267,9 @@ impl GradientVariant {
// https://www.w3.org/TR/SVG/pservers.html#RadialGradients
GradientVariant::Radial {
cx: Some(Length::parse_str("50%", LengthDir::Horizontal).unwrap()),
cy: Some(Length::parse_str("50%", LengthDir::Vertical).unwrap()),
r: Some(Length::parse_str("50%", LengthDir::Both).unwrap()),
cx: Some(LengthHorizontal::parse_str("50%", ()).unwrap()),
cy: Some(LengthVertical::parse_str("50%", ()).unwrap()),
r: Some(LengthBoth::parse_str("50%", ()).unwrap()),
fx: None,
fy: None,
......@@ -684,16 +684,16 @@ impl NodeTrait for NodeGradient {
// Attributes specific to each gradient type. The defaults mandated by the spec
// are in GradientVariant::resolve_from_defaults()
Attribute::X1 => x1 = Some(attr.parse(value, LengthDir::Horizontal)?),
Attribute::Y1 => y1 = Some(attr.parse(value, LengthDir::Vertical)?),
Attribute::X2 => x2 = Some(attr.parse(value, LengthDir::Horizontal)?),
Attribute::Y2 => y2 = Some(attr.parse(value, LengthDir::Vertical)?),
Attribute::Cx => cx = Some(attr.parse(value, LengthDir::Horizontal)?),
Attribute::Cy => cy = Some(attr.parse(value, LengthDir::Vertical)?),
Attribute::R => r = Some(attr.parse(value, LengthDir::Both)?),
Attribute::Fx => fx = Some(attr.parse(value, LengthDir::Horizontal)?),
Attribute::Fy => fy = Some(attr.parse(value, LengthDir::Vertical)?),
Attribute::X1 => x1 = Some(attr.parse(value, ())?),
Attribute::Y1 => y1 = Some(attr.parse(value, ())?),
Attribute::X2 => x2 = Some(attr.parse(value, ())?),
Attribute::Y2 => y2 = Some(attr.parse(value, ())?),
Attribute::Cx => cx = Some(attr.parse(value, ())?),
Attribute::Cy => cy = Some(attr.parse(value, ())?),
Attribute::R => r = Some(attr.parse(value, ())?),
Attribute::Fx => fx = Some(attr.parse(value, ())?),
Attribute::Fy => fy = Some(attr.parse(value, ())?),
_ => (),
}
......
......@@ -9,17 +9,17 @@ use bbox::BoundingBox;
use drawing_ctx::DrawingCtx;
use error::{NodeError, RenderingError};
use float_eq_cairo::ApproxEqCairo;
use length::*;
use length::{LengthHorizontal, LengthVertical};
use node::*;
use parsers::{ParseError, ParseValue};
use property_bag::PropertyBag;
pub struct NodeImage {
aspect: Cell<AspectRatio>,
x: Cell<Length>,
y: Cell<Length>,
w: Cell<Length>,
h: Cell<Length>,
x: Cell<LengthHorizontal>,
y: Cell<LengthVertical>,
w: Cell<LengthHorizontal>,
h: Cell<LengthVertical>,
href: RefCell<Option<Href>>,
}
......@@ -27,10 +27,10 @@ impl NodeImage {
pub fn new() -> NodeImage {
NodeImage {
aspect: Cell::new(AspectRatio::default()),
x: Cell::new(Length::default()),
y: Cell::new(Length::default()),
w: Cell::new(Length::default()),
h: Cell::new(Length::default()),
x: Cell::new(Default::default()),
y: Cell::new(Default::default()),
w: Cell::new(Default::default()),
h: Cell::new(Default::default()),
href: RefCell::new(None),
}
}
......@@ -44,17 +44,17 @@ impl NodeTrait for NodeImage {
for (attr, value) in pbag.iter() {
match attr {
Attribute::X => self.x.set(attr.parse(value, LengthDir::Horizontal)?),
Attribute::Y => self.y.set(attr.parse(value, LengthDir::Vertical)?),
Attribute::X => self.x.set(attr.parse(value, ())?),
Attribute::Y => self.y.set(attr.parse(value, ())?),
Attribute::Width => self.w.set(attr.parse_and_validate(
value,
LengthDir::Horizontal,
Length::check_nonnegative,
(),
LengthHorizontal::check_nonnegative,
)?),
Attribute::Height => self.h.set(attr.parse_and_validate(
value,
LengthDir::Vertical,
Length::check_nonnegative,
(),
LengthVertical::check_nonnegative,
)?),
Attribute::PreserveAspectRatio => self.aspect.set(attr.parse(value, ())?),
......
......@@ -17,29 +17,105 @@ pub enum LengthUnit {
}
#[derive(Debug, PartialEq, Copy, Clone)]
pub enum LengthDir {
enum LengthDir {
Horizontal,
Vertical,
Both,
}
macro_rules! define_length_type {
($name:ident, $dir:expr) => {
#[derive(Debug, PartialEq, Copy, Clone)]
pub struct $name(Length);
impl $name {
pub fn new(length: f64, unit: LengthUnit) -> Self {
$name(Length::new(length, unit, $dir))
}
pub fn length(&self) -> f64 {
self.0.length
}
pub fn unit(&self) -> LengthUnit {
self.0.unit
}
pub fn get_unitless(&self) -> f64 {
self.0.get_unitless()
}
pub fn check_nonnegative(self) -> Result<Self, ValueErrorKind> {
if self.length() >= 0.0 {
Ok(self)
} else {
Err(ValueErrorKind::Value(
"value must be non-negative".to_string(),
))
}
}
pub fn normalize(&self, values: &ComputedValues, params: &ViewParams) -> f64 {
self.0.normalize(values, params)
}
pub fn hand_normalize(
&self,
pixels_per_inch: f64,
width_or_height: f64,
font_size: f64,
) -> f64 {
self.0
.hand_normalize(pixels_per_inch, width_or_height, font_size)
}
pub fn from_cssparser(parser: &mut Parser<'_, '_>) -> Result<Self, ValueErrorKind> {
Ok($name(Length::from_cssparser(parser, $dir)?))
}
}
impl Default for $name {
fn default() -> Self {
$name(Length::new(0.0, LengthUnit::Default, $dir))
}
}
impl Parse for $name {
type Data = ();
type Err = ValueErrorKind;
fn parse(parser: &mut Parser<'_, '_>, _: ()) -> Result<$name, ValueErrorKind> {
Ok($name(Length::parse(parser, $dir)?))
}
}
};
}
/// Horizontal length
///
/// When this is specified as a percent value, it will get resolved
/// against the current viewport's width.
define_length_type!(LengthHorizontal, LengthDir::Horizontal);
/// Vertical length
///
/// When this is specified as a percent value, it will get resolved
/// against the current viewport's height.
define_length_type!(LengthVertical, LengthDir::Vertical);
/// "Both" length
///
/// When this is specified as a percent value, it will get resolved
/// against the current viewport's width and height.
define_length_type!(LengthBoth, LengthDir::Both);
#[derive(Debug, PartialEq, Copy, Clone)]
pub struct Length {
struct Length {
pub length: f64,
pub unit: LengthUnit,
dir: LengthDir,
}
impl Default for Length {
fn default() -> Length {
Length {
length: 0.0,
unit: LengthUnit::Default,
dir: LengthDir::Both,
}
}
}
pub const POINTS_PER_INCH: f64 = 72.0;
const CM_PER_INCH: f64 = 2.54;
const MM_PER_INCH: f64 = 25.4;
......@@ -76,7 +152,7 @@ impl Parse for Length {
}
impl Length {
pub fn new(l: f64, unit: LengthUnit, dir: LengthDir) -> Length {
fn new(l: f64, unit: LengthUnit, dir: LengthDir) -> Length {
Length {
length: l,
unit,
......@@ -84,16 +160,6 @@ impl Length {
}
}
pub fn check_nonnegative(self) -> Result<Length, ValueErrorKind> {
if self.length >= 0.0 {
Ok(self)
} else {
Err(ValueErrorKind::Value(
"value must be non-negative".to_string(),
))
}
}
pub fn normalize(&self, values: &ComputedValues, params: &ViewParams) -> f64 {
match self.unit {
LengthUnit::Default => self.length,
......@@ -236,7 +302,7 @@ fn font_size_from_inch(length: f64, dir: LengthDir, params: &ViewParams) -> f64
}
fn font_size_from_values(values: &ComputedValues, params: &ViewParams) -> f64 {
let v = &values.font_size.0.value();
let v = &values.font_size.0.value().0;
match v.unit {
LengthUnit::Default => v.length,
......@@ -263,7 +329,7 @@ fn viewport_percentage(x: f64, y: f64) -> f64 {
#[derive(Debug, PartialEq, Clone)]
pub enum Dasharray {
None,
Array(Vec<Length>),
Array(Vec<LengthBoth>),
}
impl Default for Dasharray {
......@@ -286,13 +352,11 @@ impl Parse for Dasharray {
}
// This does not handle "inherit" or "none" state, the caller is responsible for that.
fn parse_dash_array(parser: &mut Parser<'_, '_>) -> Result<Vec<Length>, ValueErrorKind> {
fn parse_dash_array(parser: &mut Parser<'_, '_>) -> Result<Vec<LengthBoth>, ValueErrorKind> {
let mut dasharray = Vec::new();
loop {