Move all the RsvgLength::check_nonnegative() calls to the validation function

This lets us remove the duplicated code that validates nonnegative
lengths and converts the result to the appropriate error.
parent 6be9e887
...@@ -200,16 +200,12 @@ impl NodeTrait for NodeMarker { ...@@ -200,16 +200,12 @@ impl NodeTrait for NodeMarker {
self.width.set (property_bag::parse_or_value (pbag, "markerWidth", self.width.set (property_bag::parse_or_value (pbag, "markerWidth",
LengthDir::Horizontal, LengthDir::Horizontal,
NodeMarker::get_default_size (LengthDir::Horizontal), NodeMarker::get_default_size (LengthDir::Horizontal),
None)? Some(RsvgLength::check_nonnegative))?);
.check_nonnegative ()
.map_err (|e| NodeError::attribute_error ("markerWidth", e))?);
self.height.set (property_bag::parse_or_value (pbag, "markerHeight", self.height.set (property_bag::parse_or_value (pbag, "markerHeight",
LengthDir::Vertical, LengthDir::Vertical,
NodeMarker::get_default_size (LengthDir::Vertical), NodeMarker::get_default_size (LengthDir::Vertical),
None)? Some(RsvgLength::check_nonnegative))?);
.check_nonnegative ()
.map_err (|e| NodeError::attribute_error ("markerHeight", e))?);
self.orient.set (property_bag::parse_or_default (pbag, "orient", (), None)?); self.orient.set (property_bag::parse_or_default (pbag, "orient", (), None)?);
self.aspect.set (property_bag::parse_or_default (pbag, "preserveAspectRatio", (), None)?); self.aspect.set (property_bag::parse_or_default (pbag, "preserveAspectRatio", (), None)?);
......
...@@ -436,9 +436,8 @@ impl NodeTrait for NodeCircle { ...@@ -436,9 +436,8 @@ impl NodeTrait for NodeCircle {
self.cx.set (property_bag::parse_or_default (pbag, "cx", LengthDir::Horizontal, None)?); self.cx.set (property_bag::parse_or_default (pbag, "cx", LengthDir::Horizontal, None)?);
self.cy.set (property_bag::parse_or_default (pbag, "cy", LengthDir::Vertical, None)?); self.cy.set (property_bag::parse_or_default (pbag, "cy", LengthDir::Vertical, None)?);
self.r.set (property_bag::parse_or_default (pbag, "r", LengthDir::Both, None) self.r.set (property_bag::parse_or_default (pbag, "r", LengthDir::Both,
.and_then (|l: RsvgLength| l.check_nonnegative () Some(RsvgLength::check_nonnegative))?);
.map_err (|e| NodeError::attribute_error ("r", e)))?);
Ok (()) Ok (())
} }
...@@ -481,13 +480,11 @@ impl NodeTrait for NodeEllipse { ...@@ -481,13 +480,11 @@ impl NodeTrait for NodeEllipse {
self.cx.set (property_bag::parse_or_default (pbag, "cx", LengthDir::Horizontal, None)?); self.cx.set (property_bag::parse_or_default (pbag, "cx", LengthDir::Horizontal, None)?);
self.cy.set (property_bag::parse_or_default (pbag, "cy", LengthDir::Vertical, None)?); self.cy.set (property_bag::parse_or_default (pbag, "cy", LengthDir::Vertical, None)?);
self.rx.set (property_bag::parse_or_default (pbag, "rx", LengthDir::Horizontal, None) self.rx.set (property_bag::parse_or_default (pbag, "rx", LengthDir::Horizontal,
.and_then (|l: RsvgLength| l.check_nonnegative () Some(RsvgLength::check_nonnegative))?);
.map_err (|e| NodeError::attribute_error ("rx", e)))?);
self.ry.set (property_bag::parse_or_default (pbag, "ry", LengthDir::Vertical, None) self.ry.set (property_bag::parse_or_default (pbag, "ry", LengthDir::Vertical,
.and_then (|l: RsvgLength| l.check_nonnegative () Some(RsvgLength::check_nonnegative))?);
.map_err (|e| NodeError::attribute_error ("ry", e)))?);
Ok (()) Ok (())
} }
......
...@@ -149,17 +149,13 @@ impl NodeTrait for NodeSvg { ...@@ -149,17 +149,13 @@ impl NodeTrait for NodeSvg {
"width", "width",
LengthDir::Horizontal, LengthDir::Horizontal,
RsvgLength::parse ("100%", LengthDir::Horizontal).unwrap (), RsvgLength::parse ("100%", LengthDir::Horizontal).unwrap (),
None) Some(RsvgLength::check_nonnegative))?);
.and_then (|l| l.check_nonnegative ()
.map_err (|e| NodeError::attribute_error ("width", e)))?);
self.h.set (property_bag::parse_or_value (pbag, self.h.set (property_bag::parse_or_value (pbag,
"height", "height",
LengthDir::Vertical, LengthDir::Vertical,
RsvgLength::parse ("100%", LengthDir::Vertical).unwrap (), RsvgLength::parse ("100%", LengthDir::Vertical).unwrap (),
None) Some(RsvgLength::check_nonnegative))?);
.and_then (|l| l.check_nonnegative ()
.map_err (|e| NodeError::attribute_error ("height", e)))?);
self.vbox.set (property_bag::parse_or_none (pbag, "viewBox", (), None)?); self.vbox.set (property_bag::parse_or_none (pbag, "viewBox", (), None)?);
...@@ -276,28 +272,11 @@ impl NodeTrait for NodeUse { ...@@ -276,28 +272,11 @@ impl NodeTrait for NodeUse {
self.x.set (property_bag::parse_or_default (pbag, "x", LengthDir::Horizontal, None)?); self.x.set (property_bag::parse_or_default (pbag, "x", LengthDir::Horizontal, None)?);
self.y.set (property_bag::parse_or_default (pbag, "y", LengthDir::Vertical, None)?); self.y.set (property_bag::parse_or_default (pbag, "y", LengthDir::Vertical, None)?);
let opt_w: Option<RsvgLength> = property_bag::parse_or_none (pbag, "width", LengthDir::Horizontal, None)?; self.w.set (property_bag::parse_or_none (pbag, "width", LengthDir::Horizontal,
self.w.set (match opt_w { Some(RsvgLength::check_nonnegative))?);
Some (w) => {
Some (w.check_nonnegative ().map_err (|e| NodeError::attribute_error ("width", e))?)
},
None => { self.h.set (property_bag::parse_or_none (pbag, "height", LengthDir::Vertical,
None Some(RsvgLength::check_nonnegative))?);
}
});
let opt_h: Option<RsvgLength> = property_bag::parse_or_none (pbag, "height", LengthDir::Vertical, None)?;
let h = match opt_h {
Some (h) => {
Some (h.check_nonnegative ().map_err (|e| NodeError::attribute_error ("height", e))?)
},
None => {
None
}
};
self.h.set (h);
Ok (()) Ok (())
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment