[librsvg: 16/43] Convert Length and all properties/attributes of that type to CssParseError



commit 8801315ae5696002e7ff20f463ac83c78301d482
Author: Federico Mena Quintero <federico gnome org>
Date:   Fri Dec 20 11:28:27 2019 -0600

    Convert Length and all properties/attributes of that type to CssParseError

 rsvg_internals/src/dasharray.rs     | 49 ++++++++++++++------
 rsvg_internals/src/filter.rs        | 27 ++++++-----
 rsvg_internals/src/filters/mod.rs   | 10 ++---
 rsvg_internals/src/font_props.rs    |  6 +--
 rsvg_internals/src/gradient.rs      | 36 +++++++--------
 rsvg_internals/src/image.rs         | 10 ++---
 rsvg_internals/src/length.rs        | 90 +++++++++++++++++--------------------
 rsvg_internals/src/marker.rs        | 14 +++---
 rsvg_internals/src/mask.rs          | 18 ++++----
 rsvg_internals/src/parsers.rs       | 14 +++---
 rsvg_internals/src/pattern.rs       | 12 ++---
 rsvg_internals/src/properties.rs    |  6 +--
 rsvg_internals/src/property_defs.rs | 22 ++++-----
 rsvg_internals/src/shapes.rs        | 36 +++++++--------
 rsvg_internals/src/structure.rs     | 32 ++++++-------
 rsvg_internals/src/text.rs          | 20 ++++-----
 16 files changed, 211 insertions(+), 191 deletions(-)
---
diff --git a/rsvg_internals/src/dasharray.rs b/rsvg_internals/src/dasharray.rs
index d818e5ff..4f83fc4a 100644
--- a/rsvg_internals/src/dasharray.rs
+++ b/rsvg_internals/src/dasharray.rs
@@ -4,7 +4,7 @@ use cssparser::Parser;
 
 use crate::error::*;
 use crate::length::*;
-use crate::parsers::{optional_comma, Parse, ParseToParseError};
+use crate::parsers::{optional_comma, ParseToParseError};
 
 #[derive(Debug, PartialEq, Clone)]
 pub enum Dasharray {
@@ -34,9 +34,8 @@ impl ParseToParseError for Dasharray {
         loop {
             let loc = parser.current_source_location();
 
-            let d = Length::<Both>::parse(parser)
-                .map_err(|e| e.into())
-                .and_then(Length::<Both>::check_nonnegative)
+            let d = Length::<Both>::parse_to_parse_error(parser)?
+                .check_nonnegative()
                 .map_err(|e| loc.new_custom_error(e))?;
             dasharray.push(d);
 
@@ -58,7 +57,7 @@ mod tests {
     #[test]
     fn parses_dash_array() {
         // helper to cut down boilderplate
-        let length_parse = |s| Length::<Both>::parse_str(s).unwrap();
+        let length_parse = |s| Length::<Both>::parse_str_to_parse_error(s).unwrap();
 
         let expected = Dasharray::Array(vec![
             length_parse("1"),
@@ -92,14 +91,38 @@ mod tests {
         let sample_6 = Dasharray::Array(vec![length_parse("5"), length_parse("3.14")]);
         let sample_7 = Dasharray::Array(vec![length_parse("2")]);
 
-        assert_eq!(Dasharray::parse_str_to_parse_error("none").unwrap(), Dasharray::None);
-        assert_eq!(Dasharray::parse_str_to_parse_error("1 2in,3 4%").unwrap(), expected);
-        assert_eq!(Dasharray::parse_str_to_parse_error("10,6").unwrap(), sample_1);
-        assert_eq!(Dasharray::parse_str_to_parse_error("5,5,20").unwrap(), sample_2);
-        assert_eq!(Dasharray::parse_str_to_parse_error("10px 20px 20px").unwrap(), sample_3);
-        assert_eq!(Dasharray::parse_str_to_parse_error("25  5 , 5 5").unwrap(), sample_4);
-        assert_eq!(Dasharray::parse_str_to_parse_error("3.1415926,8").unwrap(), sample_5);
-        assert_eq!(Dasharray::parse_str_to_parse_error("5, 3.14").unwrap(), sample_6);
+        assert_eq!(
+            Dasharray::parse_str_to_parse_error("none").unwrap(),
+            Dasharray::None
+        );
+        assert_eq!(
+            Dasharray::parse_str_to_parse_error("1 2in,3 4%").unwrap(),
+            expected
+        );
+        assert_eq!(
+            Dasharray::parse_str_to_parse_error("10,6").unwrap(),
+            sample_1
+        );
+        assert_eq!(
+            Dasharray::parse_str_to_parse_error("5,5,20").unwrap(),
+            sample_2
+        );
+        assert_eq!(
+            Dasharray::parse_str_to_parse_error("10px 20px 20px").unwrap(),
+            sample_3
+        );
+        assert_eq!(
+            Dasharray::parse_str_to_parse_error("25  5 , 5 5").unwrap(),
+            sample_4
+        );
+        assert_eq!(
+            Dasharray::parse_str_to_parse_error("3.1415926,8").unwrap(),
+            sample_5
+        );
+        assert_eq!(
+            Dasharray::parse_str_to_parse_error("5, 3.14").unwrap(),
+            sample_6
+        );
         assert_eq!(Dasharray::parse_str_to_parse_error("2").unwrap(), sample_7);
 
         // Negative numbers
diff --git a/rsvg_internals/src/filter.rs b/rsvg_internals/src/filter.rs
index 16e813e7..e86b6bb3 100644
--- a/rsvg_internals/src/filter.rs
+++ b/rsvg_internals/src/filter.rs
@@ -9,7 +9,7 @@ use crate::drawing_ctx::DrawingCtx;
 use crate::error::ValueErrorKind;
 use crate::length::*;
 use crate::node::{NodeResult, NodeTrait, RsvgNode};
-use crate::parsers::{Parse, ParseValue};
+use crate::parsers::{ParseToParseError, ParseValue, ParseValueToParseError};
 use crate::properties::ComputedValues;
 use crate::property_bag::PropertyBag;
 use crate::rect::Rect;
@@ -28,10 +28,10 @@ impl Default for Filter {
     /// Constructs a new `Filter` with default properties.
     fn default() -> Self {
         Self {
-            x: Length::<Horizontal>::parse_str("-10%").unwrap(),
-            y: Length::<Vertical>::parse_str("-10%").unwrap(),
-            width: Length::<Horizontal>::parse_str("120%").unwrap(),
-            height: Length::<Vertical>::parse_str("120%").unwrap(),
+            x: Length::<Horizontal>::parse_str_to_parse_error("-10%").unwrap(),
+            y: Length::<Vertical>::parse_str_to_parse_error("-10%").unwrap(),
+            width: Length::<Horizontal>::parse_str_to_parse_error("120%").unwrap(),
+            height: Length::<Vertical>::parse_str_to_parse_error("120%").unwrap(),
             filterunits: CoordUnits::ObjectBoundingBox,
             primitiveunits: CoordUnits::UserSpaceOnUse,
         }
@@ -161,18 +161,23 @@ impl NodeTrait for Filter {
         for (attr, value) in pbag.iter() {
             match attr.expanded() {
                 expanded_name!(svg "x") => {
-                    self.x = attr.parse_and_validate(value, check_units_horizontal)?
+                    self.x =
+                        attr.parse_to_parse_error_and_validate(value, check_units_horizontal)?
                 }
                 expanded_name!(svg "y") => {
-                    self.y = attr.parse_and_validate(value, check_units_vertical)?
+                    self.y = attr.parse_to_parse_error_and_validate(value, check_units_vertical)?
                 }
                 expanded_name!(svg "width") => {
-                    self.width = attr
-                        .parse_and_validate(value, check_units_horizontal_and_ensure_nonnegative)?
+                    self.width = attr.parse_to_parse_error_and_validate(
+                        value,
+                        check_units_horizontal_and_ensure_nonnegative,
+                    )?
                 }
                 expanded_name!(svg "height") => {
-                    self.height =
-                        attr.parse_and_validate(value, check_units_vertical_and_ensure_nonnegative)?
+                    self.height = attr.parse_to_parse_error_and_validate(
+                        value,
+                        check_units_vertical_and_ensure_nonnegative,
+                    )?
                 }
                 expanded_name!(svg "primitiveUnits") => self.primitiveunits = attr.parse(value)?,
                 _ => (),
diff --git a/rsvg_internals/src/filters/mod.rs b/rsvg_internals/src/filters/mod.rs
index 49c67c85..844f082a 100644
--- a/rsvg_internals/src/filters/mod.rs
+++ b/rsvg_internals/src/filters/mod.rs
@@ -13,7 +13,7 @@ use crate::error::{RenderingError, ValueErrorKind};
 use crate::filter::Filter;
 use crate::length::*;
 use crate::node::{CascadedValues, NodeResult, NodeTrait, NodeType, RsvgNode};
-use crate::parsers::ParseValue;
+use crate::parsers::{ParseValue, ParseValueToParseError};
 use crate::properties::ComputedValues;
 use crate::property_bag::PropertyBag;
 use crate::property_defs::ColorInterpolationFilters;
@@ -163,21 +163,21 @@ impl NodeTrait for Primitive {
         for (attr, value) in pbag.iter() {
             match attr.expanded() {
                 expanded_name!(svg "x") => {
-                    self.x = Some(attr.parse_and_validate(value, check_units_horizontal)?)
+                    self.x = Some(attr.parse_to_parse_error_and_validate(value, check_units_horizontal)?)
                 }
                 expanded_name!(svg "y") => {
-                    self.y = Some(attr.parse_and_validate(value, check_units_vertical)?)
+                    self.y = Some(attr.parse_to_parse_error_and_validate(value, check_units_vertical)?)
                 }
                 expanded_name!(svg "width") => {
                     self.width =
-                        Some(attr.parse_and_validate(
+                        Some(attr.parse_to_parse_error_and_validate(
                             value,
                             check_units_horizontal_and_ensure_nonnegative,
                         )?)
                 }
                 expanded_name!(svg "height") => {
                     self.height =
-                        Some(attr.parse_and_validate(
+                        Some(attr.parse_to_parse_error_and_validate(
                             value,
                             check_units_vertical_and_ensure_nonnegative,
                         )?)
diff --git a/rsvg_internals/src/font_props.rs b/rsvg_internals/src/font_props.rs
index 165817ce..b4be79ac 100644
--- a/rsvg_internals/src/font_props.rs
+++ b/rsvg_internals/src/font_props.rs
@@ -5,7 +5,7 @@ use cssparser::{BasicParseError, Parser};
 use crate::drawing_ctx::ViewParams;
 use crate::error::*;
 use crate::length::*;
-use crate::parsers::{Parse, ParseToParseError};
+use crate::parsers::ParseToParseError;
 use crate::properties::ComputedValues;
 
 // https://www.w3.org/TR/2008/REC-CSS2-20080411/fonts.html#propdef-font-size
@@ -65,7 +65,7 @@ impl ParseToParseError for FontSizeSpec {
         parser: &mut Parser<'i, '_>,
     ) -> Result<FontSizeSpec, CssParseError<'i>> {
         parser
-            .try_parse(|p| Length::<Both>::parse(p))
+            .try_parse(|p| Length::<Both>::parse_to_parse_error(p))
             .and_then(|l| Ok(FontSizeSpec::Value(l)))
             .or_else(|_| {
                 Ok(parse_identifiers!(
@@ -169,7 +169,7 @@ impl ParseToParseError for LetterSpacingSpec {
         parser: &mut Parser<'i, '_>,
     ) -> Result<LetterSpacingSpec, CssParseError<'i>> {
         parser
-            .try_parse(|p| Length::<Horizontal>::parse(p))
+            .try_parse(|p| Length::<Horizontal>::parse_to_parse_error(p))
             .and_then(|l| Ok(LetterSpacingSpec::Value(l)))
             .or_else(|_| {
                 Ok(parse_identifiers!(
diff --git a/rsvg_internals/src/gradient.rs b/rsvg_internals/src/gradient.rs
index 9c557b9f..97cfcef8 100644
--- a/rsvg_internals/src/gradient.rs
+++ b/rsvg_internals/src/gradient.rs
@@ -13,7 +13,7 @@ use crate::error::*;
 use crate::length::*;
 use crate::node::{CascadedValues, NodeResult, NodeTrait, NodeType, RsvgNode};
 use crate::paint_server::{AsPaintSource, PaintSource};
-use crate::parsers::{Parse, ParseValue};
+use crate::parsers::{Parse, ParseToParseError, ParseValue, ParseValueToParseError};
 use crate::properties::ComputedValues;
 use crate::property_bag::PropertyBag;
 use crate::property_defs::StopColor;
@@ -134,7 +134,7 @@ impl NodeTrait for Stop {
             match attr.expanded() {
                 expanded_name!(svg "offset") => {
                     self.offset = attr
-                        .parse_and_validate(value, validate_offset)
+                        .parse_to_parse_error_and_validate(value, validate_offset)
                         .map(|l| UnitInterval::clamp(l.length))?
                 }
                 _ => (),
@@ -248,16 +248,16 @@ impl UnresolvedVariant {
     fn resolve_from_defaults(&self) -> UnresolvedVariant {
         match self {
             UnresolvedVariant::Linear { x1, y1, x2, y2 } => UnresolvedVariant::Linear {
-                x1: x1.or_else(|| Some(Length::<Horizontal>::parse_str("0%").unwrap())),
-                y1: y1.or_else(|| Some(Length::<Vertical>::parse_str("0%").unwrap())),
-                x2: x2.or_else(|| Some(Length::<Horizontal>::parse_str("100%").unwrap())),
-                y2: y2.or_else(|| Some(Length::<Vertical>::parse_str("0%").unwrap())),
+                x1: x1.or_else(|| Some(Length::<Horizontal>::parse_str_to_parse_error("0%").unwrap())),
+                y1: y1.or_else(|| Some(Length::<Vertical>::parse_str_to_parse_error("0%").unwrap())),
+                x2: x2.or_else(|| Some(Length::<Horizontal>::parse_str_to_parse_error("100%").unwrap())),
+                y2: y2.or_else(|| Some(Length::<Vertical>::parse_str_to_parse_error("0%").unwrap())),
             },
 
             UnresolvedVariant::Radial { cx, cy, r, fx, fy } => {
-                let cx = cx.or_else(|| Some(Length::<Horizontal>::parse_str("50%").unwrap()));
-                let cy = cy.or_else(|| Some(Length::<Vertical>::parse_str("50%").unwrap()));
-                let r = r.or_else(|| Some(Length::<Both>::parse_str("50%").unwrap()));
+                let cx = cx.or_else(|| Some(Length::<Horizontal>::parse_str_to_parse_error("50%").unwrap()));
+                let cy = cy.or_else(|| Some(Length::<Vertical>::parse_str_to_parse_error("50%").unwrap()));
+                let r = r.or_else(|| Some(Length::<Both>::parse_str_to_parse_error("50%").unwrap()));
 
                 // fx and fy fall back to the presentational value of cx and cy
                 let fx = fx.or(cx);
@@ -568,10 +568,10 @@ impl NodeTrait for LinearGradient {
 
         for (attr, value) in pbag.iter() {
             match attr.expanded() {
-                expanded_name!(svg "x1") => self.x1 = Some(attr.parse(value)?),
-                expanded_name!(svg "y1") => self.y1 = Some(attr.parse(value)?),
-                expanded_name!(svg "x2") => self.x2 = Some(attr.parse(value)?),
-                expanded_name!(svg "y2") => self.y2 = Some(attr.parse(value)?),
+                expanded_name!(svg "x1") => self.x1 = Some(attr.parse_to_parse_error(value)?),
+                expanded_name!(svg "y1") => self.y1 = Some(attr.parse_to_parse_error(value)?),
+                expanded_name!(svg "x2") => self.x2 = Some(attr.parse_to_parse_error(value)?),
+                expanded_name!(svg "y2") => self.y2 = Some(attr.parse_to_parse_error(value)?),
 
                 _ => (),
             }
@@ -587,11 +587,11 @@ impl NodeTrait for RadialGradient {
 
         for (attr, value) in pbag.iter() {
             match attr.expanded() {
-                expanded_name!(svg "cx") => self.cx = Some(attr.parse(value)?),
-                expanded_name!(svg "cy") => self.cy = Some(attr.parse(value)?),
-                expanded_name!(svg "r") => self.r = Some(attr.parse(value)?),
-                expanded_name!(svg "fx") => self.fx = Some(attr.parse(value)?),
-                expanded_name!(svg "fy") => self.fy = Some(attr.parse(value)?),
+                expanded_name!(svg "cx") => self.cx = Some(attr.parse_to_parse_error(value)?),
+                expanded_name!(svg "cy") => self.cy = Some(attr.parse_to_parse_error(value)?),
+                expanded_name!(svg "r") => self.r = Some(attr.parse_to_parse_error(value)?),
+                expanded_name!(svg "fx") => self.fx = Some(attr.parse_to_parse_error(value)?),
+                expanded_name!(svg "fy") => self.fy = Some(attr.parse_to_parse_error(value)?),
 
                 _ => (),
             }
diff --git a/rsvg_internals/src/image.rs b/rsvg_internals/src/image.rs
index 514f36fb..c4c846db 100644
--- a/rsvg_internals/src/image.rs
+++ b/rsvg_internals/src/image.rs
@@ -11,7 +11,7 @@ use crate::error::*;
 use crate::float_eq_cairo::ApproxEqCairo;
 use crate::length::*;
 use crate::node::*;
-use crate::parsers::ParseValue;
+use crate::parsers::{ParseValue, ParseValueToParseError};
 use crate::property_bag::PropertyBag;
 use crate::rect::Rect;
 use crate::viewbox::ViewBox;
@@ -30,13 +30,13 @@ impl NodeTrait for Image {
     fn set_atts(&mut self, _: Option<&RsvgNode>, pbag: &PropertyBag<'_>) -> NodeResult {
         for (attr, value) in pbag.iter() {
             match attr.expanded() {
-                expanded_name!(svg "x") => self.x = attr.parse(value)?,
-                expanded_name!(svg "y") => self.y = attr.parse(value)?,
+                expanded_name!(svg "x") => self.x = attr.parse_to_parse_error(value)?,
+                expanded_name!(svg "y") => self.y = attr.parse_to_parse_error(value)?,
                 expanded_name!(svg "width") => {
-                    self.w = attr.parse_and_validate(value, Length::check_nonnegative)?
+                    self.w = attr.parse_to_parse_error_and_validate(value, Length::check_nonnegative)?
                 }
                 expanded_name!(svg "height") => {
-                    self.h = attr.parse_and_validate(value, Length::check_nonnegative)?
+                    self.h = attr.parse_to_parse_error_and_validate(value, Length::check_nonnegative)?
                 }
                 expanded_name!(svg "preserveAspectRatio") => self.aspect = attr.parse(value)?,
 
diff --git a/rsvg_internals/src/length.rs b/rsvg_internals/src/length.rs
index 53c7fa34..2f1b9102 100644
--- a/rsvg_internals/src/length.rs
+++ b/rsvg_internals/src/length.rs
@@ -47,7 +47,7 @@ use std::marker::PhantomData;
 
 use crate::drawing_ctx::ViewParams;
 use crate::error::*;
-use crate::parsers::{finite_f32, Parse};
+use crate::parsers::{finite_f32, ParseToParseError};
 use crate::properties::ComputedValues;
 
 /// Units for length values.
@@ -226,35 +226,29 @@ const CM_PER_INCH: f64 = 2.54;
 const MM_PER_INCH: f64 = 25.4;
 const PICA_PER_INCH: f64 = 6.0;
 
-fn make_err() -> ValueErrorKind {
-    ValueErrorKind::parse_error(
-        "expected length: number(\"em\" | \"ex\" | \"px\" | \"in\" | \"cm\" | \"mm\" | \"pt\" | \
-         \"pc\" | \"%\")?",
-    )
-}
-
-impl<N: Normalize> Parse for Length<N> {
-    fn parse(parser: &mut Parser<'_, '_>) -> Result<Length<N>, ValueErrorKind> {
+impl<N: Normalize> ParseToParseError for Length<N> {
+    fn parse_to_parse_error<'i>(
+        parser: &mut Parser<'i, '_>,
+    ) -> Result<Length<N>, CssParseError<'i>> {
         let length = {
-            let token = parser.next().map_err(|_| {
-                ValueErrorKind::parse_error(
-                    "expected number and optional symbol, or number and percentage",
-                )
-            })?;
-
-            match *token {
-                Token::Number { value, .. } => {
-                    Length::new(f64::from(finite_f32(value)?), LengthUnit::Px)
-                }
+            let token = parser.next()?.clone();
 
-                Token::Percentage { unit_value, .. } => {
-                    Length::new(f64::from(finite_f32(unit_value)?), LengthUnit::Percent)
-                }
+            match token {
+                Token::Number { value, .. } => Length::new(
+                    f64::from(finite_f32(value).map_err(|e| parser.new_custom_error(e))?),
+                    LengthUnit::Px,
+                ),
+
+                Token::Percentage { unit_value, .. } => Length::new(
+                    f64::from(finite_f32(unit_value).map_err(|e| parser.new_custom_error(e))?),
+                    LengthUnit::Percent,
+                ),
 
                 Token::Dimension {
                     value, ref unit, ..
                 } => {
-                    let value = f64::from(finite_f32(value)?);
+                    let value =
+                        f64::from(finite_f32(value).map_err(|e| parser.new_custom_error(e))?);
 
                     match unit.as_ref() {
                         "px" => Length::new(value, LengthUnit::Px),
@@ -266,11 +260,11 @@ impl<N: Normalize> Parse for Length<N> {
                         "pt" => Length::new(value, LengthUnit::Pt),
                         "pc" => Length::new(value, LengthUnit::Pc),
 
-                        _ => return Err(make_err()),
+                        _ => return Err(parser.new_unexpected_token_error(token.clone()))?,
                     }
                 }
 
-                _ => return Err(make_err()),
+                _ => return Err(parser.new_unexpected_token_error(token.clone()))?,
             }
         };
 
@@ -337,18 +331,14 @@ impl<N: Normalize> Length<N> {
 
             LengthUnit::Ex => self.length * font_size_from_values(values, params) / 2.0,
 
-            LengthUnit::In => {
-                self.length * <N as Normalize>::normalize(params.dpi_x, params.dpi_y)
-            }
+            LengthUnit::In => self.length * <N as Normalize>::normalize(params.dpi_x, params.dpi_y),
 
             LengthUnit::Cm => {
-                self.length * <N as Normalize>::normalize(params.dpi_x, params.dpi_y)
-                    / CM_PER_INCH
+                self.length * <N as Normalize>::normalize(params.dpi_x, params.dpi_y) / CM_PER_INCH
             }
 
             LengthUnit::Mm => {
-                self.length * <N as Normalize>::normalize(params.dpi_x, params.dpi_y)
-                    / MM_PER_INCH
+                self.length * <N as Normalize>::normalize(params.dpi_x, params.dpi_y) / MM_PER_INCH
             }
 
             LengthUnit::Pt => {
@@ -404,12 +394,12 @@ mod tests {
     #[test]
     fn parses_default() {
         assert_eq!(
-            Length::<Horizontal>::parse_str("42"),
+            Length::<Horizontal>::parse_str_to_parse_error("42"),
             Ok(Length::<Horizontal>::new(42.0, LengthUnit::Px))
         );
 
         assert_eq!(
-            Length::<Horizontal>::parse_str("-42px"),
+            Length::<Horizontal>::parse_str_to_parse_error("-42px"),
             Ok(Length::<Horizontal>::new(-42.0, LengthUnit::Px))
         );
     }
@@ -417,7 +407,7 @@ mod tests {
     #[test]
     fn parses_percent() {
         assert_eq!(
-            Length::<Horizontal>::parse_str("50.0%"),
+            Length::<Horizontal>::parse_str_to_parse_error("50.0%"),
             Ok(Length::<Horizontal>::new(0.5, LengthUnit::Percent))
         );
     }
@@ -425,7 +415,7 @@ mod tests {
     #[test]
     fn parses_font_em() {
         assert_eq!(
-            Length::<Vertical>::parse_str("22.5em"),
+            Length::<Vertical>::parse_str_to_parse_error("22.5em"),
             Ok(Length::<Vertical>::new(22.5, LengthUnit::Em))
         );
     }
@@ -433,7 +423,7 @@ mod tests {
     #[test]
     fn parses_font_ex() {
         assert_eq!(
-            Length::<Vertical>::parse_str("22.5ex"),
+            Length::<Vertical>::parse_str_to_parse_error("22.5ex"),
             Ok(Length::<Vertical>::new(22.5, LengthUnit::Ex))
         );
     }
@@ -441,51 +431,53 @@ mod tests {
     #[test]
     fn parses_physical_units() {
         assert_eq!(
-            Length::<Both>::parse_str("72pt"),
+            Length::<Both>::parse_str_to_parse_error("72pt"),
             Ok(Length::<Both>::new(72.0, LengthUnit::Pt))
         );
 
         assert_eq!(
-            Length::<Both>::parse_str("-22.5in"),
+            Length::<Both>::parse_str_to_parse_error("-22.5in"),
             Ok(Length::<Both>::new(-22.5, LengthUnit::In))
         );
 
         assert_eq!(
-            Length::<Both>::parse_str("-254cm"),
+            Length::<Both>::parse_str_to_parse_error("-254cm"),
             Ok(Length::<Both>::new(-254.0, LengthUnit::Cm))
         );
 
         assert_eq!(
-            Length::<Both>::parse_str("254mm"),
+            Length::<Both>::parse_str_to_parse_error("254mm"),
             Ok(Length::<Both>::new(254.0, LengthUnit::Mm))
         );
 
         assert_eq!(
-            Length::<Both>::parse_str("60pc"),
+            Length::<Both>::parse_str_to_parse_error("60pc"),
             Ok(Length::<Both>::new(60.0, LengthUnit::Pc))
         );
     }
 
     #[test]
     fn empty_length_yields_error() {
-        assert!(is_parse_error(&Length::<Both>::parse_str("")));
+        assert!(Length::<Both>::parse_str_to_parse_error("").is_err());
     }
 
     #[test]
     fn invalid_unit_yields_error() {
-        assert!(is_parse_error(&Length::<Both>::parse_str("8furlong")));
+        assert!(Length::<Both>::parse_str_to_parse_error("8furlong").is_err());
     }
 
     #[test]
     fn check_nonnegative_works() {
         // and_then with anonymous function
-        assert!(Length::<Both>::parse_str("0")
-            .and_then(|l| l.check_nonnegative())
+        assert!(Length::<Both>::parse_str_to_parse_error("0")
+            .unwrap()
+            .check_nonnegative()
             .is_ok());
 
         // and_then with named function
-        assert!(Length::<Both>::parse_str("-10")
-            .and_then(Length::check_nonnegative)
+        assert!(Length::<Both>::parse_str_to_parse_error("-10")
+            .unwrap()
+            .check_nonnegative()
             .is_err());
     }
 
diff --git a/rsvg_internals/src/marker.rs b/rsvg_internals/src/marker.rs
index d3f59840..0af3ee52 100644
--- a/rsvg_internals/src/marker.rs
+++ b/rsvg_internals/src/marker.rs
@@ -16,7 +16,7 @@ use crate::float_eq_cairo::ApproxEqCairo;
 use crate::iri::IRI;
 use crate::length::*;
 use crate::node::*;
-use crate::parsers::{Parse, ParseValue};
+use crate::parsers::{Parse, ParseToParseError, ParseValue, ParseValueToParseError};
 use crate::path_builder::*;
 use crate::properties::{ComputedValues, SpecifiedValue, SpecifiedValues};
 use crate::property_bag::PropertyBag;
@@ -91,8 +91,8 @@ impl Default for Marker {
             ref_x: Default::default(),
             ref_y: Default::default(),
             // the following two are per the spec
-            width: Length::<Horizontal>::parse_str("3").unwrap(),
-            height: Length::<Vertical>::parse_str("3").unwrap(),
+            width: Length::<Horizontal>::parse_str_to_parse_error("3").unwrap(),
+            height: Length::<Vertical>::parse_str_to_parse_error("3").unwrap(),
             orient: MarkerOrient::default(),
             aspect: AspectRatio::default(),
             vbox: None,
@@ -183,15 +183,15 @@ impl NodeTrait for Marker {
         for (attr, value) in pbag.iter() {
             match attr.expanded() {
                 expanded_name!(svg "markerUnits") => self.units = attr.parse(value)?,
-                expanded_name!(svg "refX") => self.ref_x = attr.parse(value)?,
-                expanded_name!(svg "refY") => self.ref_y = attr.parse(value)?,
+                expanded_name!(svg "refX") => self.ref_x = attr.parse_to_parse_error(value)?,
+                expanded_name!(svg "refY") => self.ref_y = attr.parse_to_parse_error(value)?,
                 expanded_name!(svg "markerWidth") => {
                     self.width =
-                        attr.parse_and_validate(value, Length::<Horizontal>::check_nonnegative)?
+                        attr.parse_to_parse_error_and_validate(value, 
Length::<Horizontal>::check_nonnegative)?
                 }
                 expanded_name!(svg "markerHeight") => {
                     self.height =
-                        attr.parse_and_validate(value, Length::<Vertical>::check_nonnegative)?
+                        attr.parse_to_parse_error_and_validate(value, Length::<Vertical>::check_nonnegative)?
                 }
                 expanded_name!(svg "orient") => self.orient = attr.parse(value)?,
                 expanded_name!(svg "preserveAspectRatio") => self.aspect = attr.parse(value)?,
diff --git a/rsvg_internals/src/mask.rs b/rsvg_internals/src/mask.rs
index 746b83ff..f5621a69 100644
--- a/rsvg_internals/src/mask.rs
+++ b/rsvg_internals/src/mask.rs
@@ -9,7 +9,7 @@ use crate::drawing_ctx::{CompositingAffines, DrawingCtx};
 use crate::error::RenderingError;
 use crate::length::*;
 use crate::node::{CascadedValues, NodeDraw, NodeResult, NodeTrait, RsvgNode};
-use crate::parsers::{Parse, ParseValue};
+use crate::parsers::{ParseToParseError, ParseValue, ParseValueToParseError};
 use crate::property_bag::PropertyBag;
 use crate::property_defs::Opacity;
 use crate::rect::Rect;
@@ -32,10 +32,10 @@ impl Default for Mask {
     fn default() -> Mask {
         Mask {
             // these values are per the spec
-            x: Length::<Horizontal>::parse_str("-10%").unwrap(),
-            y: Length::<Vertical>::parse_str("-10%").unwrap(),
-            width: Length::<Horizontal>::parse_str("120%").unwrap(),
-            height: Length::<Vertical>::parse_str("120%").unwrap(),
+            x: Length::<Horizontal>::parse_str_to_parse_error("-10%").unwrap(),
+            y: Length::<Vertical>::parse_str_to_parse_error("-10%").unwrap(),
+            width: Length::<Horizontal>::parse_str_to_parse_error("120%").unwrap(),
+            height: Length::<Vertical>::parse_str_to_parse_error("120%").unwrap(),
 
             units: MaskUnits::default(),
             content_units: MaskContentUnits::default(),
@@ -136,15 +136,15 @@ impl NodeTrait for Mask {
     fn set_atts(&mut self, _: Option<&RsvgNode>, pbag: &PropertyBag<'_>) -> NodeResult {
         for (attr, value) in pbag.iter() {
             match attr.expanded() {
-                expanded_name!(svg "x") => self.x = attr.parse(value)?,
-                expanded_name!(svg "y") => self.y = attr.parse(value)?,
+                expanded_name!(svg "x") => self.x = attr.parse_to_parse_error(value)?,
+                expanded_name!(svg "y") => self.y = attr.parse_to_parse_error(value)?,
                 expanded_name!(svg "width") => {
                     self.width =
-                        attr.parse_and_validate(value, Length::<Horizontal>::check_nonnegative)?
+                        attr.parse_to_parse_error_and_validate(value, 
Length::<Horizontal>::check_nonnegative)?
                 }
                 expanded_name!(svg "height") => {
                     self.height =
-                        attr.parse_and_validate(value, Length::<Vertical>::check_nonnegative)?
+                        attr.parse_to_parse_error_and_validate(value, Length::<Vertical>::check_nonnegative)?
                 }
                 expanded_name!(svg "maskUnits") => self.units = attr.parse(value)?,
                 expanded_name!(svg "maskContentUnits") => self.content_units = attr.parse(value)?,
diff --git a/rsvg_internals/src/parsers.rs b/rsvg_internals/src/parsers.rs
index e1fdaac5..28731b74 100644
--- a/rsvg_internals/src/parsers.rs
+++ b/rsvg_internals/src/parsers.rs
@@ -81,9 +81,9 @@ pub trait ParseValueToParseError<T: ParseToParseError> {
     fn parse_to_parse_error(&self, value: &str) -> Result<T, NodeError>;
 
     /// Parses a `value` string into a type `T` with an optional validation function.
-    fn parse_to_parse_error_and_validate<'i, F: FnOnce(T) -> Result<T, CssParseError<'i>>>(
+    fn parse_to_parse_error_and_validate<F: FnOnce(T) -> Result<T, ValueErrorKind>>(
         &self,
-        value: &'i str,
+        value: &str,
         validate: F,
     ) -> Result<T, NodeError>;
 }
@@ -96,17 +96,17 @@ impl<T: ParseToParseError> ParseValueToParseError<T> for QualName {
         T::parse_to_parse_error(&mut parser).attribute(self.clone())
     }
 
-    fn parse_to_parse_error_and_validate<'i, F: FnOnce(T) -> Result<T, CssParseError<'i>>>(
+    fn parse_to_parse_error_and_validate<F: FnOnce(T) -> Result<T, ValueErrorKind>>(
         &self,
-        value: &'i str,
+        value: &str,
         validate: F,
     ) -> Result<T, NodeError> {
         let mut input = ParserInput::new(value);
         let mut parser = Parser::new(&mut input);
 
-        T::parse_to_parse_error(&mut parser)
-            .and_then(validate)
-            .attribute(self.clone())
+        let v = T::parse_to_parse_error(&mut parser).attribute(self.clone())?;
+
+        validate(v).map_err(|e| parser.new_custom_error(e)).attribute(self.clone())
     }
 }
 
diff --git a/rsvg_internals/src/pattern.rs b/rsvg_internals/src/pattern.rs
index 2315fb84..5ed5472b 100644
--- a/rsvg_internals/src/pattern.rs
+++ b/rsvg_internals/src/pattern.rs
@@ -10,12 +10,12 @@ use crate::aspect_ratio::*;
 use crate::bbox::*;
 use crate::coord_units::CoordUnits;
 use crate::drawing_ctx::{DrawingCtx, NodeStack};
-use crate::error::{AcquireError, AttributeResultExt, RenderingError};
+use crate::error::*;
 use crate::float_eq_cairo::ApproxEqCairo;
 use crate::length::*;
 use crate::node::*;
 use crate::paint_server::{AsPaintSource, PaintSource};
-use crate::parsers::ParseValue;
+use crate::parsers::{ParseValue, ParseValueToParseError};
 use crate::properties::ComputedValues;
 use crate::property_bag::PropertyBag;
 use crate::rect::Rect;
@@ -134,16 +134,16 @@ impl NodeTrait for Pattern {
                 expanded_name!(xlink "href") => {
                     self.fallback = Some(Fragment::parse(value).attribute(attr)?);
                 }
-                expanded_name!(svg "x") => self.common.x = Some(attr.parse(value)?),
-                expanded_name!(svg "y") => self.common.y = Some(attr.parse(value)?),
+                expanded_name!(svg "x") => self.common.x = Some(attr.parse_to_parse_error(value)?),
+                expanded_name!(svg "y") => self.common.y = Some(attr.parse_to_parse_error(value)?),
                 expanded_name!(svg "width") => {
                     self.common.width = Some(
-                        attr.parse_and_validate(value, Length::<Horizontal>::check_nonnegative)?,
+                        attr.parse_to_parse_error_and_validate(value, 
Length::<Horizontal>::check_nonnegative)?,
                     )
                 }
                 expanded_name!(svg "height") => {
                     self.common.height =
-                        Some(attr.parse_and_validate(value, Length::<Vertical>::check_nonnegative)?)
+                        Some(attr.parse_to_parse_error_and_validate(value, 
Length::<Vertical>::check_nonnegative)?)
                 }
                 _ => (),
             }
diff --git a/rsvg_internals/src/properties.rs b/rsvg_internals/src/properties.rs
index e11545dd..118eeb9b 100644
--- a/rsvg_internals/src/properties.rs
+++ b/rsvg_internals/src/properties.rs
@@ -231,7 +231,7 @@ pub fn parse_property<'i>(prop_name: &QualName, input: &mut Parser<'i, '_>, acce
     // please keep these sorted
     match prop_name.expanded() {
         expanded_name!(svg "baseline-shift") =>
-            Ok(ParsedProperty::BaselineShift(parse_input(input)?)),
+            Ok(ParsedProperty::BaselineShift(parse_input_to_parse_error(input)?)),
 
         expanded_name!(svg "clip-path") =>
             Ok(ParsedProperty::ClipPath(parse_input_to_parse_error(input)?)),
@@ -338,7 +338,7 @@ pub fn parse_property<'i>(prop_name: &QualName, input: &mut Parser<'i, '_>, acce
             Ok(ParsedProperty::StrokeDasharray(parse_input_to_parse_error(input)?)),
 
         expanded_name!(svg "stroke-dashoffset") =>
-            Ok(ParsedProperty::StrokeDashoffset(parse_input(input)?)),
+            Ok(ParsedProperty::StrokeDashoffset(parse_input_to_parse_error(input)?)),
 
         expanded_name!(svg "stroke-linecap") =>
             Ok(ParsedProperty::StrokeLinecap(parse_input_to_parse_error(input)?)),
@@ -353,7 +353,7 @@ pub fn parse_property<'i>(prop_name: &QualName, input: &mut Parser<'i, '_>, acce
             Ok(ParsedProperty::StrokeOpacity(parse_input_to_parse_error(input)?)),
 
         expanded_name!(svg "stroke-width") =>
-            Ok(ParsedProperty::StrokeWidth(parse_input(input)?)),
+            Ok(ParsedProperty::StrokeWidth(parse_input_to_parse_error(input)?)),
 
         expanded_name!(svg "text-anchor") =>
             Ok(ParsedProperty::TextAnchor(parse_input_to_parse_error(input)?)),
diff --git a/rsvg_internals/src/property_defs.rs b/rsvg_internals/src/property_defs.rs
index 73df5159..2db61b75 100644
--- a/rsvg_internals/src/property_defs.rs
+++ b/rsvg_internals/src/property_defs.rs
@@ -17,7 +17,7 @@ use crate::unit_interval::UnitInterval;
 make_property!(
     ComputedValues,
     BaselineShift,
-    default: Length::<Both>::parse_str("0.0").unwrap(),
+    default: Length::<Both>::parse_str_to_parse_error("0.0").unwrap(),
     newtype: Length<Both>,
     property_impl: {
         impl Property<ComputedValues> for BaselineShift {
@@ -41,19 +41,19 @@ make_property!(
         }
     },
     parse_impl: {
-        impl Parse for BaselineShift {
+        impl ParseToParseError for BaselineShift {
             // These values come from Inkscape's SP_CSS_BASELINE_SHIFT_(SUB/SUPER/BASELINE);
             // see sp_style_merge_baseline_shift_from_parent()
-            fn parse(parser: &mut Parser<'_, '_>) -> Result<BaselineShift, crate::error::ValueErrorKind> {
-                parser.try_parse(|p| Ok(BaselineShift(Length::<Both>::parse(p)?)))
-                    .or_else(|_: ValueErrorKind| {
-                        parse_identifiers!(
+            fn parse_to_parse_error<'i>(parser: &mut Parser<'i, '_>) -> Result<BaselineShift, 
crate::error::CssParseError<'i>> {
+                parser.try_parse(|p| Ok(BaselineShift(Length::<Both>::parse_to_parse_error(p)?)))
+                    .or_else(|_: CssParseError| {
+                        Ok(parse_identifiers!(
                             parser,
                             "baseline" => BaselineShift(Length::<Both>::new(0.0, LengthUnit::Percent)),
                             "sub" => BaselineShift(Length::<Both>::new(-0.2, LengthUnit::Percent)),
 
                             "super" => BaselineShift(Length::<Both>::new(0.4, LengthUnit::Percent)),
-                        ).map_err(|_| ValueErrorKind::parse_error("parse error"))
+                        )?)
                     })
             }
         }
@@ -230,7 +230,7 @@ make_property!(
 make_property!(
     ComputedValues,
     FontSize,
-    default: FontSizeSpec::Value(Length::<Both>::parse_str("12.0").unwrap()),
+    default: FontSizeSpec::Value(Length::<Both>::parse_str_to_parse_error("12.0").unwrap()),
     newtype_parse: FontSizeSpec,
     property_impl: {
         impl Property<ComputedValues> for FontSize {
@@ -451,7 +451,7 @@ make_property!(
     StrokeDashoffset,
     default: Length::<Both>::default(),
     inherits_automatically: true,
-    newtype_parse: Length<Both>,
+    newtype_parse_to_parse_error: Length<Both>,
 );
 
 // https://www.w3.org/TR/SVG/painting.html#StrokeLinecapProperty
@@ -502,9 +502,9 @@ make_property!(
 make_property!(
     ComputedValues,
     StrokeWidth,
-    default: Length::<Both>::parse_str("1.0").unwrap(),
+    default: Length::<Both>::parse_str_to_parse_error("1.0").unwrap(),
     inherits_automatically: true,
-    newtype_parse: Length::<Both>,
+    newtype_parse_to_parse_error: Length::<Both>,
 );
 
 // https://www.w3.org/TR/SVG/text.html#TextAnchorProperty
diff --git a/rsvg_internals/src/shapes.rs b/rsvg_internals/src/shapes.rs
index a3da4204..3454efc1 100644
--- a/rsvg_internals/src/shapes.rs
+++ b/rsvg_internals/src/shapes.rs
@@ -12,7 +12,7 @@ use crate::error::*;
 use crate::length::*;
 use crate::marker;
 use crate::node::*;
-use crate::parsers::{optional_comma, Parse, ParseValue};
+use crate::parsers::{optional_comma, Parse, ParseValue, ParseValueToParseError};
 use crate::path_builder::*;
 use crate::path_parser;
 use crate::properties::ComputedValues;
@@ -313,10 +313,10 @@ impl NodeTrait for Line {
     fn set_atts(&mut self, _: Option<&RsvgNode>, pbag: &PropertyBag<'_>) -> NodeResult {
         for (attr, value) in pbag.iter() {
             match attr.expanded() {
-                expanded_name!(svg "x1") => self.x1 = attr.parse(value)?,
-                expanded_name!(svg "y1") => self.y1 = attr.parse(value)?,
-                expanded_name!(svg "x2") => self.x2 = attr.parse(value)?,
-                expanded_name!(svg "y2") => self.y2 = attr.parse(value)?,
+                expanded_name!(svg "x1") => self.x1 = attr.parse_to_parse_error(value)?,
+                expanded_name!(svg "y1") => self.y1 = attr.parse_to_parse_error(value)?,
+                expanded_name!(svg "x2") => self.x2 = attr.parse_to_parse_error(value)?,
+                expanded_name!(svg "y2") => self.y2 = attr.parse_to_parse_error(value)?,
                 _ => (),
             }
         }
@@ -375,24 +375,24 @@ impl NodeTrait for Rect {
     fn set_atts(&mut self, _: Option<&RsvgNode>, pbag: &PropertyBag<'_>) -> NodeResult {
         for (attr, value) in pbag.iter() {
             match attr.expanded() {
-                expanded_name!(svg "x") => self.x = attr.parse(value)?,
-                expanded_name!(svg "y") => self.y = attr.parse(value)?,
+                expanded_name!(svg "x") => self.x = attr.parse_to_parse_error(value)?,
+                expanded_name!(svg "y") => self.y = attr.parse_to_parse_error(value)?,
                 expanded_name!(svg "width") => {
                     self.w =
-                        attr.parse_and_validate(value, Length::<Horizontal>::check_nonnegative)?
+                        attr.parse_to_parse_error_and_validate(value, 
Length::<Horizontal>::check_nonnegative)?
                 }
                 expanded_name!(svg "height") => {
                     self.h =
-                        attr.parse_and_validate(value, Length::<Vertical>::check_nonnegative)?
+                        attr.parse_to_parse_error_and_validate(value, Length::<Vertical>::check_nonnegative)?
                 }
                 expanded_name!(svg "rx") => {
                     self.rx = attr
-                        .parse_and_validate(value, Length::<Horizontal>::check_nonnegative)
+                        .parse_to_parse_error_and_validate(value, Length::<Horizontal>::check_nonnegative)
                         .map(Some)?
                 }
                 expanded_name!(svg "ry") => {
                     self.ry = attr
-                        .parse_and_validate(value, Length::<Vertical>::check_nonnegative)
+                        .parse_to_parse_error_and_validate(value, Length::<Vertical>::check_nonnegative)
                         .map(Some)?
                 }
                 _ => (),
@@ -603,10 +603,10 @@ impl NodeTrait for Circle {
     fn set_atts(&mut self, _: Option<&RsvgNode>, pbag: &PropertyBag<'_>) -> NodeResult {
         for (attr, value) in pbag.iter() {
             match attr.expanded() {
-                expanded_name!(svg "cx") => self.cx = attr.parse(value)?,
-                expanded_name!(svg "cy") => self.cy = attr.parse(value)?,
+                expanded_name!(svg "cx") => self.cx = attr.parse_to_parse_error(value)?,
+                expanded_name!(svg "cy") => self.cy = attr.parse_to_parse_error(value)?,
                 expanded_name!(svg "r") => {
-                    self.r = attr.parse_and_validate(value, Length::<Both>::check_nonnegative)?
+                    self.r = attr.parse_to_parse_error_and_validate(value, 
Length::<Both>::check_nonnegative)?
                 }
                 _ => (),
             }
@@ -656,15 +656,15 @@ impl NodeTrait for Ellipse {
     fn set_atts(&mut self, _: Option<&RsvgNode>, pbag: &PropertyBag<'_>) -> NodeResult {
         for (attr, value) in pbag.iter() {
             match attr.expanded() {
-                expanded_name!(svg "cx") => self.cx = attr.parse(value)?,
-                expanded_name!(svg "cy") => self.cy = attr.parse(value)?,
+                expanded_name!(svg "cx") => self.cx = attr.parse_to_parse_error(value)?,
+                expanded_name!(svg "cy") => self.cy = attr.parse_to_parse_error(value)?,
                 expanded_name!(svg "rx") => {
                     self.rx =
-                        attr.parse_and_validate(value, Length::<Horizontal>::check_nonnegative)?
+                        attr.parse_to_parse_error_and_validate(value, 
Length::<Horizontal>::check_nonnegative)?
                 }
                 expanded_name!(svg "ry") => {
                     self.ry =
-                        attr.parse_and_validate(value, Length::<Vertical>::check_nonnegative)?
+                        attr.parse_to_parse_error_and_validate(value, Length::<Vertical>::check_nonnegative)?
                 }
                 _ => (),
             }
diff --git a/rsvg_internals/src/structure.rs b/rsvg_internals/src/structure.rs
index 31b9fb34..76145060 100644
--- a/rsvg_internals/src/structure.rs
+++ b/rsvg_internals/src/structure.rs
@@ -7,11 +7,11 @@ use crate::aspect_ratio::*;
 use crate::bbox::BoundingBox;
 use crate::dpi::Dpi;
 use crate::drawing_ctx::{ClipMode, DrawingCtx, ViewParams};
-use crate::error::{AcquireError, AttributeResultExt, RenderingError};
+use crate::error::*;
 use crate::float_eq_cairo::ApproxEqCairo;
 use crate::length::*;
 use crate::node::*;
-use crate::parsers::{Parse, ParseValue};
+use crate::parsers::{ParseToParseError, ParseValue, ParseValueToParseError};
 use crate::properties::ComputedValues;
 use crate::property_bag::PropertyBag;
 use crate::property_defs::Overflow;
@@ -149,16 +149,16 @@ impl Svg {
         // these defaults are per the spec
         let x = self
             .x
-            .unwrap_or_else(|| Length::<Horizontal>::parse_str("0").unwrap());
+            .unwrap_or_else(|| Length::<Horizontal>::parse_str_to_parse_error("0").unwrap());
         let y = self
             .y
-            .unwrap_or_else(|| Length::<Vertical>::parse_str("0").unwrap());
+            .unwrap_or_else(|| Length::<Vertical>::parse_str_to_parse_error("0").unwrap());
         let w = self
             .w
-            .unwrap_or_else(|| Length::<Horizontal>::parse_str("100%").unwrap());
+            .unwrap_or_else(|| Length::<Horizontal>::parse_str_to_parse_error("100%").unwrap());
         let h = self
             .h
-            .unwrap_or_else(|| Length::<Vertical>::parse_str("100%").unwrap());
+            .unwrap_or_else(|| Length::<Vertical>::parse_str_to_parse_error("100%").unwrap());
 
         (x, y, w, h)
     }
@@ -186,15 +186,15 @@ impl NodeTrait for Svg {
                 expanded_name!(svg "preserveAspectRatio") => {
                     self.preserve_aspect_ratio = attr.parse(value)?
                 }
-                expanded_name!(svg "x") if is_inner_svg => self.x = Some(attr.parse(value)?),
-                expanded_name!(svg "y") if is_inner_svg => self.y = Some(attr.parse(value)?),
+                expanded_name!(svg "x") if is_inner_svg => self.x = Some(attr.parse_to_parse_error(value)?),
+                expanded_name!(svg "y") if is_inner_svg => self.y = Some(attr.parse_to_parse_error(value)?),
                 expanded_name!(svg "width") => {
                     self.w =
-                        Some(attr.parse_and_validate(value, Length::<Horizontal>::check_nonnegative)?)
+                        Some(attr.parse_to_parse_error_and_validate(value, 
Length::<Horizontal>::check_nonnegative)?)
                 }
                 expanded_name!(svg "height") => {
                     self.h =
-                        Some(attr.parse_and_validate(value, Length::<Vertical>::check_nonnegative)?)
+                        Some(attr.parse_to_parse_error_and_validate(value, 
Length::<Vertical>::check_nonnegative)?)
                 }
                 expanded_name!(svg "viewBox") => self.vbox = attr.parse(value).map(Some)?,
                 _ => (),
@@ -278,16 +278,16 @@ impl NodeTrait for Use {
                 expanded_name!(xlink "href") => {
                     self.link = Some(Fragment::parse(value).attribute(attr)?)
                 }
-                expanded_name!(svg "x") => self.x = attr.parse(value)?,
-                expanded_name!(svg "y") => self.y = attr.parse(value)?,
+                expanded_name!(svg "x") => self.x = attr.parse_to_parse_error(value)?,
+                expanded_name!(svg "y") => self.y = attr.parse_to_parse_error(value)?,
                 expanded_name!(svg "width") => {
                     self.w = attr
-                        .parse_and_validate(value, Length::<Horizontal>::check_nonnegative)
+                        .parse_to_parse_error_and_validate(value, Length::<Horizontal>::check_nonnegative)
                         .map(Some)?
                 }
                 expanded_name!(svg "height") => {
                     self.h = attr
-                        .parse_and_validate(value, Length::<Vertical>::check_nonnegative)
+                        .parse_to_parse_error_and_validate(value, Length::<Vertical>::check_nonnegative)
                         .map(Some)?
                 }
                 _ => (),
@@ -362,11 +362,11 @@ impl NodeTrait for Use {
 
         let nw = self
             .w
-            .unwrap_or_else(|| Length::<Horizontal>::parse_str("100%").unwrap())
+            .unwrap_or_else(|| Length::<Horizontal>::parse_str_to_parse_error("100%").unwrap())
             .normalize(values, &params);
         let nh = self
             .h
-            .unwrap_or_else(|| Length::<Vertical>::parse_str("100%").unwrap())
+            .unwrap_or_else(|| Length::<Vertical>::parse_str_to_parse_error("100%").unwrap())
             .normalize(values, &params);
 
         // width or height set to 0 disables rendering of the element
diff --git a/rsvg_internals/src/text.rs b/rsvg_internals/src/text.rs
index 7e6eb3e1..c95bb4bd 100644
--- a/rsvg_internals/src/text.rs
+++ b/rsvg_internals/src/text.rs
@@ -10,12 +10,12 @@ use std::cell::RefCell;
 use crate::allowed_url::Fragment;
 use crate::bbox::BoundingBox;
 use crate::drawing_ctx::DrawingCtx;
-use crate::error::{AttributeResultExt, RenderingError};
+use crate::error::*;
 use crate::float_eq_cairo::ApproxEqCairo;
 use crate::font_props::FontWeightSpec;
 use crate::length::*;
 use crate::node::{CascadedValues, NodeResult, NodeTrait, NodeType, RsvgNode};
-use crate::parsers::ParseValue;
+use crate::parsers::ParseValueToParseError;
 use crate::properties::ComputedValues;
 use crate::property_bag::PropertyBag;
 use crate::property_defs::{
@@ -602,10 +602,10 @@ impl NodeTrait for Text {
     fn set_atts(&mut self, _: Option<&RsvgNode>, pbag: &PropertyBag<'_>) -> NodeResult {
         for (attr, value) in pbag.iter() {
             match attr.expanded() {
-                expanded_name!(svg "x") => self.x = attr.parse(value)?,
-                expanded_name!(svg "y") => self.y = attr.parse(value)?,
-                expanded_name!(svg "dx") => self.dx = attr.parse(value).map(Some)?,
-                expanded_name!(svg "dy") => self.dy = attr.parse(value).map(Some)?,
+                expanded_name!(svg "x") => self.x = attr.parse_to_parse_error(value)?,
+                expanded_name!(svg "y") => self.y = attr.parse_to_parse_error(value)?,
+                expanded_name!(svg "dx") => self.dx = attr.parse_to_parse_error(value).map(Some)?,
+                expanded_name!(svg "dy") => self.dy = attr.parse_to_parse_error(value).map(Some)?,
                 _ => (),
             }
         }
@@ -762,10 +762,10 @@ impl NodeTrait for TSpan {
     fn set_atts(&mut self, _: Option<&RsvgNode>, pbag: &PropertyBag<'_>) -> NodeResult {
         for (attr, value) in pbag.iter() {
             match attr.expanded() {
-                expanded_name!(svg "x") => self.x = attr.parse(value).map(Some)?,
-                expanded_name!(svg "y") => self.y = attr.parse(value).map(Some)?,
-                expanded_name!(svg "dx") => self.dx = attr.parse(value).map(Some)?,
-                expanded_name!(svg "dy") => self.dy = attr.parse(value).map(Some)?,
+                expanded_name!(svg "x") => self.x = attr.parse_to_parse_error(value).map(Some)?,
+                expanded_name!(svg "y") => self.y = attr.parse_to_parse_error(value).map(Some)?,
+                expanded_name!(svg "dx") => self.dx = attr.parse_to_parse_error(value).map(Some)?,
+                expanded_name!(svg "dy") => self.dy = attr.parse_to_parse_error(value).map(Some)?,
                 _ => (),
             }
         }


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]