[librsvg] Make NodeTrait::set_atts() return a NodeResult
- From: Federico Mena Quintero <federico src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [librsvg] Make NodeTrait::set_atts() return a NodeResult
- Date: Thu, 16 Mar 2017 05:15:40 +0000 (UTC)
commit 657182c210416c627232dcce4d370c7f268e37ee
Author: Federico Mena Quintero <federico gnome org>
Date: Fri Mar 3 10:46:43 2017 -0600
Make NodeTrait::set_atts() return a NodeResult
Set this on node.result from the toplevel Node::set_atts() that calls
into NodeTrait::set_atts().
For now, just return Ok from all the set_atts() implementations; we'll
propagate errors later.
rust/src/cnode.rs | 4 +++-
rust/src/marker.rs | 4 +++-
rust/src/node.rs | 7 ++++---
rust/src/shapes.rs | 24 ++++++++++++++++++------
4 files changed, 28 insertions(+), 11 deletions(-)
---
diff --git a/rust/src/cnode.rs b/rust/src/cnode.rs
index c838d09..bfba391 100644
--- a/rust/src/cnode.rs
+++ b/rust/src/cnode.rs
@@ -19,8 +19,10 @@ struct CNode {
}
impl NodeTrait for CNode {
- fn set_atts (&self, node: &RsvgNode, handle: *const RsvgHandle, pbag: *const RsvgPropertyBag) {
+ fn set_atts (&self, node: &RsvgNode, handle: *const RsvgHandle, pbag: *const RsvgPropertyBag) ->
NodeResult {
unsafe { (self.set_atts_fn) (node as *const RsvgNode, self.c_node_impl, handle, pbag); }
+
+ Ok (())
}
fn draw (&self, node: &RsvgNode, draw_ctx: *const RsvgDrawingCtx, dominate: i32) {
diff --git a/rust/src/marker.rs b/rust/src/marker.rs
index e6281bf..e112a1e 100644
--- a/rust/src/marker.rs
+++ b/rust/src/marker.rs
@@ -212,7 +212,7 @@ impl NodeMarker {
}
impl NodeTrait for NodeMarker {
- fn set_atts (&self, _: &RsvgNode, _: *const RsvgHandle, pbag: *const RsvgPropertyBag) {
+ fn set_atts (&self, _: &RsvgNode, _: *const RsvgHandle, pbag: *const RsvgPropertyBag) -> NodeResult {
self.units.set (property_bag::lookup_and_parse (pbag, "markerUnits"));
self.ref_x.set (property_bag::lookup_length (pbag, "refX", LengthDir::Horizontal));
@@ -226,6 +226,8 @@ impl NodeTrait for NodeMarker {
self.orient.set (property_bag::lookup_and_parse (pbag, "orient"));
self.aspect.set (property_bag::lookup_and_parse (pbag, "preserveAspectRatio"));
self.vbox.set (property_bag::lookup_and_parse (pbag, "viewBox"));
+
+ Ok (())
}
fn draw (&self, _: &RsvgNode, _: *const RsvgDrawingCtx, _: i32) {
diff --git a/rust/src/node.rs b/rust/src/node.rs
index d04a88b..31e6610 100644
--- a/rust/src/node.rs
+++ b/rust/src/node.rs
@@ -30,7 +30,7 @@ pub type RsvgNode = Rc<Node>;
pub enum RsvgCNodeImpl {}
pub trait NodeTrait: Downcast {
- fn set_atts (&self, node: &RsvgNode, handle: *const RsvgHandle, pbag: *const RsvgPropertyBag);
+ fn set_atts (&self, node: &RsvgNode, handle: *const RsvgHandle, pbag: *const RsvgPropertyBag) ->
NodeResult;
fn draw (&self, node: &RsvgNode, draw_ctx: *const RsvgDrawingCtx, dominate: i32);
fn get_c_impl (&self) -> *const RsvgCNodeImpl;
}
@@ -193,7 +193,7 @@ impl Node {
}
pub fn set_atts (&self, node: &RsvgNode, handle: *const RsvgHandle, pbag: *const RsvgPropertyBag) {
- self.node_impl.set_atts (node, handle, pbag);
+ *self.result.borrow_mut () = self.node_impl.set_atts (node, handle, pbag);
}
pub fn draw (&self, node: &RsvgNode, draw_ctx: *const RsvgDrawingCtx, dominate: i32) {
@@ -377,7 +377,8 @@ mod tests {
struct TestNodeImpl {}
impl NodeTrait for TestNodeImpl {
- fn set_atts (&self, _: &RsvgNode, _: *const RsvgHandle, _: *const RsvgPropertyBag) {
+ fn set_atts (&self, _: &RsvgNode, _: *const RsvgHandle, _: *const RsvgPropertyBag) -> NodeResult {
+ Ok (())
}
fn draw (&self, _: &RsvgNode, _: *const RsvgDrawingCtx, _: i32) {
diff --git a/rust/src/shapes.rs b/rust/src/shapes.rs
index 713dc78..9291205 100644
--- a/rust/src/shapes.rs
+++ b/rust/src/shapes.rs
@@ -86,7 +86,7 @@ impl NodePath {
}
impl NodeTrait for NodePath {
- fn set_atts (&self, _: &RsvgNode, _: *const RsvgHandle, pbag: *const RsvgPropertyBag) {
+ fn set_atts (&self, _: &RsvgNode, _: *const RsvgHandle, pbag: *const RsvgPropertyBag) -> NodeResult {
if let Some (value) = property_bag::lookup (pbag, "d") {
let mut builder = self.builder.borrow_mut ();
@@ -95,6 +95,8 @@ impl NodeTrait for NodePath {
// path is OK per the spec
}
}
+
+ Ok (())
}
fn draw (&self, node: &RsvgNode, draw_ctx: *const RsvgDrawingCtx, dominate: i32) {
@@ -129,7 +131,7 @@ impl NodePoly {
}
impl NodeTrait for NodePoly {
- fn set_atts (&self, _: &RsvgNode, _: *const RsvgHandle, pbag: *const RsvgPropertyBag) {
+ fn set_atts (&self, _: &RsvgNode, _: *const RsvgHandle, pbag: *const RsvgPropertyBag) -> NodeResult {
// support for svg < 1.0 which used verts
if let Some (value) = property_bag::lookup (pbag, "verts").or (property_bag::lookup (pbag,
"points")) {
let result = parsers::list_of_points (value.trim ().as_bytes ()).to_full_result ();
@@ -145,6 +147,8 @@ impl NodeTrait for NodePoly {
}
}
}
+
+ Ok (())
}
fn draw (&self, node: &RsvgNode, draw_ctx: *const RsvgDrawingCtx, dominate: i32) {
@@ -193,11 +197,13 @@ impl NodeLine {
}
impl NodeTrait for NodeLine {
- fn set_atts (&self, _: &RsvgNode, _: *const RsvgHandle, pbag: *const RsvgPropertyBag) {
+ fn set_atts (&self, _: &RsvgNode, _: *const RsvgHandle, pbag: *const RsvgPropertyBag) -> NodeResult {
self.x1.set (property_bag::lookup_length (pbag, "x1", LengthDir::Horizontal));
self.y1.set (property_bag::lookup_length (pbag, "y1", LengthDir::Vertical));
self.x2.set (property_bag::lookup_length (pbag, "x2", LengthDir::Horizontal));
self.y2.set (property_bag::lookup_length (pbag, "y2", LengthDir::Vertical));
+
+ Ok (())
}
fn draw (&self, node: &RsvgNode, draw_ctx: *const RsvgDrawingCtx, dominate: i32) {
@@ -248,7 +254,7 @@ impl NodeRect {
}
impl NodeTrait for NodeRect {
- fn set_atts (&self, _: &RsvgNode, _: *const RsvgHandle, pbag: *const RsvgPropertyBag) {
+ fn set_atts (&self, _: &RsvgNode, _: *const RsvgHandle, pbag: *const RsvgPropertyBag) -> NodeResult {
self.x.set (property_bag::lookup_length (pbag, "x", LengthDir::Horizontal));
self.y.set (property_bag::lookup_length (pbag, "y", LengthDir::Vertical));
self.w.set (property_bag::lookup_length (pbag, "width", LengthDir::Horizontal));
@@ -271,6 +277,8 @@ impl NodeTrait for NodeRect {
} else {
self.ry.set (None);
}
+
+ Ok (())
}
fn draw (&self, node: &RsvgNode, draw_ctx: *const RsvgDrawingCtx, dominate: i32) {
@@ -436,10 +444,12 @@ impl NodeCircle {
}
impl NodeTrait for NodeCircle {
- fn set_atts (&self, _: &RsvgNode, _: *const RsvgHandle, pbag: *const RsvgPropertyBag) {
+ fn set_atts (&self, _: &RsvgNode, _: *const RsvgHandle, pbag: *const RsvgPropertyBag) -> NodeResult {
self.cx.set (property_bag::lookup_length (pbag, "cx", LengthDir::Horizontal));
self.cy.set (property_bag::lookup_length (pbag, "cy", LengthDir::Vertical));
self.r.set (property_bag::lookup_length (pbag, "r", LengthDir::Both));
+
+ Ok (())
}
fn draw (&self, node: &RsvgNode, draw_ctx: *const RsvgDrawingCtx, dominate: i32) {
@@ -476,11 +486,13 @@ impl NodeEllipse {
}
impl NodeTrait for NodeEllipse {
- fn set_atts (&self, _: &RsvgNode, _: *const RsvgHandle, pbag: *const RsvgPropertyBag) {
+ fn set_atts (&self, _: &RsvgNode, _: *const RsvgHandle, pbag: *const RsvgPropertyBag) -> NodeResult {
self.cx.set (property_bag::lookup_length (pbag, "cx", LengthDir::Horizontal));
self.cy.set (property_bag::lookup_length (pbag, "cy", LengthDir::Vertical));
self.rx.set (property_bag::lookup_length (pbag, "rx", LengthDir::Horizontal));
self.ry.set (property_bag::lookup_length (pbag, "ry", LengthDir::Vertical));
+
+ Ok (())
}
fn draw (&self, node: &RsvgNode, draw_ctx: *const RsvgDrawingCtx, dominate: i32) {
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]