[librsvg] node.rs: Start defining node::Error type
- From: Federico Mena Quintero <federico src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [librsvg] node.rs: Start defining node::Error type
- Date: Thu, 16 Mar 2017 05:15:30 +0000 (UTC)
commit 356cfdf8dddfd4054c4d8308410ba0c19f848f1a
Author: Federico Mena Quintero <federico gnome org>
Date: Fri Mar 3 09:23:24 2017 -0600
node.rs: Start defining node::Error type
This in the context of https://bugzilla.gnome.org/show_bug.cgi?id=776932
A "transform (0, 0, 0, 0, 0, 0)" attribute ripples down the code, so
that we try to invert that matrix and panic.
We'll keep a "result" field inside struct Node. When a node
parses/validates its attributes, it will set that result to Err if it
finds a problem. This is how we'll remember that a node "is in error",
to use the SVG spec's terminology.
Later, Node::draw() will not render a node that is in error. We can
also do optimizations in the call stack above Node::draw(); for example,
making rsvg_node_draw_from_stack() ignore nodes that are in error so
that it can avoid doing a state inheritance for a node in error.
rust/src/node.rs | 40 ++++++++++++++++++++++++++++++++++++++++
1 files changed, 40 insertions(+), 0 deletions(-)
---
diff --git a/rust/src/node.rs b/rust/src/node.rs
index 4498972..7e38b98 100644
--- a/rust/src/node.rs
+++ b/rust/src/node.rs
@@ -1,5 +1,6 @@
extern crate libc;
+use std::error;
use std::rc::Rc;
use std::rc::Weak;
use std::cell::RefCell;
@@ -35,11 +36,49 @@ pub trait NodeTrait: Downcast {
impl_downcast! (NodeTrait);
+#[derive(Debug)]
+pub struct AttributeError {
+ attr_name: &'static str,
+ error: Box<error::Error + Send + Sync>
+}
+
+#[derive(Debug)]
+pub enum Error {
+ // parse error in an attribute
+ AttributeParse (AttributeError),
+
+ // attribute with an invalid value
+ AttributeValue (AttributeError),
+}
+
+// After creating/parsing a Node, it will be in a success or an error state.
+// We represent this with a Result, aliased as a NodeResult. There is no
+// extra information for the Ok case; all the interesting stuff is in the
+// Err case.
+//
+// https://www.w3.org/TR/SVG/implnote.html#ErrorProcessing
+//
+// When an element has an error during parsing, the SVG spec calls the element
+// to be "in error". We skip rendering of elements that are in error.
+//
+// When we parse an element's attributes, we stop as soon as we
+// encounter the first error: a parse error, or an invalid value,
+// etc. No further attributes will be processed, although note that
+// the order in which an element's attributes are processed is not
+// defined.
+//
+// Alternatively, we could try to parse/validate all the attributes
+// that come in an element and build up a Vec<Error>. However, we
+// don't do this now. Doing that may be more useful for an SVG
+// validator, not a renderer like librsvg is.
+pub type NodeResult = Result<(), Error>;
+
pub struct Node {
node_type: NodeType,
parent: Option<Weak<Node>>, // optional; weak ref to parent
pub children: RefCell<Vec<Rc<Node>>>, // strong references to children
state: *mut RsvgState,
+ result: RefCell <NodeResult>,
node_impl: Box<NodeTrait>
}
@@ -110,6 +149,7 @@ impl Node {
parent: parent,
children: RefCell::new (Vec::new ()),
state: state,
+ result: RefCell::new (Ok (())),
node_impl: node_impl
}
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]