[librsvg] svg: make the tree member private
- From: Federico Mena Quintero <federico src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [librsvg] svg: make the tree member private
- Date: Sun, 13 Jan 2019 17:32:05 +0000 (UTC)
commit 3b09b7332e95745889d4985bb16d25664abb74ac
Author: Paolo Borelli <pborelli gnome org>
Date: Sun Jan 13 12:29:30 2019 +0100
svg: make the tree member private
We only need to expose methods to get the root and to cascade
rsvg_internals/src/handle.rs | 36 ++++++++++++------------------------
rsvg_internals/src/svg.rs | 10 +++++++++-
2 files changed, 21 insertions(+), 25 deletions(-)
---
diff --git a/rsvg_internals/src/handle.rs b/rsvg_internals/src/handle.rs
index fa26b27b..f71a7ddd 100644
--- a/rsvg_internals/src/handle.rs
+++ b/rsvg_internals/src/handle.rs
@@ -279,13 +279,6 @@ impl Handle {
Ok(())
}
- fn cascade(&mut self) {
- let svg_ref = self.svg.borrow();
- let svg = svg_ref.as_ref().unwrap();
-
- svg.tree.cascade();
- }
-
fn create_drawing_ctx_for_node(
&mut self,
cr: &cairo::Context,
@@ -307,7 +300,9 @@ impl Handle {
draw_ctx.add_node_and_ancestors_to_stack(node);
}
- self.cascade();
+ let svg_ref = self.svg.borrow();
+ let svg = svg_ref.as_ref().unwrap();
+ svg.cascade();
draw_ctx
}
@@ -378,6 +373,12 @@ impl Handle {
})
}
+ fn get_root(&self) -> RsvgNode {
+ let svg_ref = self.svg.borrow();
+ let svg = svg_ref.as_ref().unwrap();
+ svg.root()
+ }
+
/// Returns (ink_rect, logical_rect)
fn get_node_geometry(
&mut self,
@@ -387,9 +388,7 @@ impl Handle {
let target = ImageSurface::create(cairo::Format::Rgb24, 1, 1)?;
let cr = cairo::Context::new(&target);
let mut draw_ctx = self.create_drawing_ctx_for_node(&cr, &dimensions, Some(node));
- let svg_ref = self.svg.borrow();
- let svg = svg_ref.as_ref().unwrap();
- let root = svg.tree.root();
+ let root = self.get_root();
draw_ctx.draw_node_from_stack(&root.get_cascaded_values(), &root, false)?;
@@ -412,12 +411,7 @@ impl Handle {
&mut self,
id: Option<&str>,
) -> Result<(RsvgRectangle, RsvgRectangle), RenderingError> {
- let root = {
- let svg_ref = self.svg.borrow();
- let svg = svg_ref.as_ref().unwrap();
-
- svg.tree.root()
- };
+ let root = self.get_root();
let (node, is_root) = if let Some(id) = id {
let n = self.lookup_node(id).map_err(RenderingError::InvalidId)?;
@@ -515,17 +509,11 @@ impl Handle {
};
let dimensions = self.get_dimensions()?;
+ let root = self.get_root();
cr.save();
-
let mut draw_ctx = self.create_drawing_ctx_for_node(cr, &dimensions, node.as_ref());
-
- let svg_ref = self.svg.borrow();
- let svg = svg_ref.as_ref().unwrap();
- let root = svg.tree.root();
-
let res = draw_ctx.draw_node_from_stack(&root.get_cascaded_values(), &root, false);
-
cr.restore();
res
diff --git a/rsvg_internals/src/svg.rs b/rsvg_internals/src/svg.rs
index 848700f6..a2c61c93 100644
--- a/rsvg_internals/src/svg.rs
+++ b/rsvg_internals/src/svg.rs
@@ -18,7 +18,7 @@ use xml2_load::xml_state_load_from_possibly_compressed_stream;
/// This contains the tree of nodes (SVG elements), the mapping
/// of id to node, and the CSS styles defined for this SVG.
pub struct Svg {
- pub tree: Tree,
+ tree: Tree,
ids: HashMap<String, RsvgNode>,
@@ -54,6 +54,10 @@ impl Svg {
xml.steal_result()
}
+ pub fn root(&self) -> RsvgNode {
+ self.tree.root()
+ }
+
pub fn lookup(&self, fragment: &Fragment) -> Option<RsvgNode> {
if fragment.uri().is_some() {
self.externs
@@ -67,6 +71,10 @@ impl Svg {
pub fn lookup_node_by_id(&self, id: &str) -> Option<RsvgNode> {
self.ids.get(id).map(|n| (*n).clone())
}
+
+ pub fn cascade(&self) {
+ self.tree.cascade();
+ }
}
struct Resources {
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]