[librsvg: 1/4] node: call directly NodeData methods
- From: Federico Mena Quintero <federico src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [librsvg: 1/4] node: call directly NodeData methods
- Date: Mon, 10 Jun 2019 13:42:27 +0000 (UTC)
commit 5600f4b5eaac60bdc953b3b9075bf4f03b0057f5
Author: Paolo Borelli <pborelli gnome org>
Date: Thu Jun 6 09:01:41 2019 +0200
node: call directly NodeData methods
Wrapping the calls through RsvgNode does not add value,
it is actually more clear that we borrow the node data from
the tree structure and then call its methods.
rsvg_internals/src/css.rs | 9 +--
rsvg_internals/src/drawing_ctx.rs | 15 +++--
rsvg_internals/src/filters/component_transfer.rs | 23 ++++---
rsvg_internals/src/filters/context.rs | 4 +-
rsvg_internals/src/filters/light/lighting.rs | 18 +++---
rsvg_internals/src/filters/merge.rs | 10 +--
rsvg_internals/src/filters/mod.rs | 19 ++++--
rsvg_internals/src/gradient.rs | 21 ++++---
rsvg_internals/src/handle.rs | 2 +-
rsvg_internals/src/marker.rs | 2 +-
rsvg_internals/src/mask.rs | 2 +-
rsvg_internals/src/node.rs | 78 +++++++++---------------
rsvg_internals/src/pattern.rs | 9 ++-
rsvg_internals/src/structure.rs | 10 +--
rsvg_internals/src/style.rs | 4 +-
rsvg_internals/src/svg.rs | 6 +-
rsvg_internals/src/text.rs | 10 +--
rsvg_internals/src/xml.rs | 15 +++--
18 files changed, 135 insertions(+), 122 deletions(-)
---
diff --git a/rsvg_internals/src/css.rs b/rsvg_internals/src/css.rs
index b4dc827e..830a6313 100644
--- a/rsvg_internals/src/css.rs
+++ b/rsvg_internals/src/css.rs
@@ -215,8 +215,9 @@ impl CssRules {
//
// This is basically a semi-compliant CSS2 selection engine
- let element_name = node.element_name();
- let id = node.get_id();
+ let node_data = node.borrow();
+ let element_name = node_data.element_name();
+ let id = node_data.get_id();
// *
if *selector == Selector::new("*") {
@@ -228,8 +229,8 @@ impl CssRules {
return true;
}
- if let Some(klazz) = node.get_class() {
- for cls in klazz.split_whitespace() {
+ if let Some(class) = node_data.get_class() {
+ for cls in class.split_whitespace() {
if !cls.is_empty() {
// tag.class#id
if let Some(id) = id {
diff --git a/rsvg_internals/src/drawing_ctx.rs b/rsvg_internals/src/drawing_ctx.rs
index 5ec629df..56703fb8 100644
--- a/rsvg_internals/src/drawing_ctx.rs
+++ b/rsvg_internals/src/drawing_ctx.rs
@@ -351,7 +351,7 @@ impl DrawingCtx {
{
let clip_node = clip_node.get().clone();
- let ClipPathUnits(units) = clip_node.get_impl::<NodeClipPath>().get_units();
+ let ClipPathUnits(units) = clip_node.borrow().get_impl::<NodeClipPath>().get_units();
if units == CoordUnits::UserSpaceOnUse {
(Some(clip_node), None)
@@ -368,7 +368,7 @@ impl DrawingCtx {
if let Some(node) = clip_node {
let orig_bbox = self.bbox;
- let clip_path = node.get_impl::<NodeClipPath>();
+ let clip_path = node.borrow().get_impl::<NodeClipPath>();
let res = clip_path.to_cairo_context(&node, self, &orig_bbox);
// FIXME: this is an EPIC HACK to keep the clipping context from
@@ -398,7 +398,7 @@ impl DrawingCtx {
let mask = values.mask.0.get();
// The `filter` property does not apply to masks.
- let filter = if node.get_type() == NodeType::Mask {
+ let filter = if node.borrow().get_type() == NodeType::Mask {
None
} else {
values.filter.0.get()
@@ -487,6 +487,7 @@ impl DrawingCtx {
res = res.and_then(|_| {
let bbox = dc.bbox;
mask_node
+ .borrow()
.get_impl::<NodeMask>()
.generate_cairo_mask(&mask_node, &affines, dc, &bbox)
});
@@ -567,7 +568,7 @@ impl DrawingCtx {
Some(acquired) => {
let filter_node = acquired.get();
- if !filter_node.is_in_error() {
+ if !filter_node.borrow().is_in_error() {
// FIXME: deal with out of memory here
filters::render(&filter_node, values, child_surface, self, node_bbox)
} else {
@@ -630,11 +631,13 @@ impl DrawingCtx {
if let Some(acquired) = self.acquired_nodes.get_node(iri) {
let node = acquired.get();
- had_paint_server = match node.get_type() {
+ had_paint_server = match node.borrow().get_type() {
NodeType::LinearGradient | NodeType::RadialGradient => node
+ .borrow()
.get_impl::<NodeGradient>()
.resolve_fallbacks_and_set_pattern(&node, self, opacity, bbox)?,
NodeType::Pattern => node
+ .borrow()
.get_impl::<NodePattern>()
.resolve_fallbacks_and_set_pattern(&node, self, opacity, bbox)?,
_ => false,
@@ -1135,7 +1138,7 @@ impl AcquiredNodes {
fragment
.and_then(move |fragment| self.get_node(fragment))
.and_then(|acquired| {
- if acquired.get().get_type() == node_type {
+ if acquired.get().borrow().get_type() == node_type {
Some(acquired)
} else {
None
diff --git a/rsvg_internals/src/filters/component_transfer.rs
b/rsvg_internals/src/filters/component_transfer.rs
index c36a6212..becebfbe 100644
--- a/rsvg_internals/src/filters/component_transfer.rs
+++ b/rsvg_internals/src/filters/component_transfer.rs
@@ -283,19 +283,22 @@ impl Filter for ComponentTransfer {
)?;
// Enumerate all child <feFuncX> nodes.
- let functions = node.children().rev().filter(|c| match c.get_type() {
- NodeType::ComponentTransferFunctionA
- | NodeType::ComponentTransferFunctionB
- | NodeType::ComponentTransferFunctionG
- | NodeType::ComponentTransferFunctionR => true,
- _ => false,
- });
+ let functions = node
+ .children()
+ .rev()
+ .filter(|c| match c.borrow().get_type() {
+ NodeType::ComponentTransferFunctionA
+ | NodeType::ComponentTransferFunctionB
+ | NodeType::ComponentTransferFunctionG
+ | NodeType::ComponentTransferFunctionR => true,
+ _ => false,
+ });
// Get a node for every pixel component.
let get_node = |channel| {
functions
.clone()
- .find(|c| c.get_impl::<FuncX>().channel == channel)
+ .find(|c| c.borrow().get_impl::<FuncX>().channel == channel)
};
let func_r = get_node(Channel::R);
let func_g = get_node(Channel::G);
@@ -306,7 +309,7 @@ impl Filter for ComponentTransfer {
.iter()
.filter_map(|x| x.as_ref())
{
- if node.is_in_error() {
+ if node.borrow().is_in_error() {
return Err(FilterError::ChildNodeInError);
}
}
@@ -320,7 +323,7 @@ impl Filter for ComponentTransfer {
#[inline]
fn func_or_default<'a>(func: &'a Option<RsvgNode>, default: &'a FuncX) -> &'a FuncX {
func.as_ref()
- .map(|c| c.get_impl::<FuncX>())
+ .map(|c| c.borrow().get_impl::<FuncX>())
.unwrap_or(default)
}
diff --git a/rsvg_internals/src/filters/context.rs b/rsvg_internals/src/filters/context.rs
index f6544e84..edd2f736 100644
--- a/rsvg_internals/src/filters/context.rs
+++ b/rsvg_internals/src/filters/context.rs
@@ -114,7 +114,7 @@ impl FilterContext {
height: 0.0,
});
- let filter = filter_node.get_impl::<NodeFilter>();
+ let filter = filter_node.borrow().get_impl::<NodeFilter>();
let affine = match filter.filterunits.get() {
CoordUnits::UserSpaceOnUse => cr_affine,
@@ -305,7 +305,7 @@ impl FilterContext {
/// Pushes the viewport size based on the value of `primitiveUnits`.
pub fn get_view_params(&self, draw_ctx: &mut DrawingCtx) -> ViewParams {
- let filter = self.node.get_impl::<NodeFilter>();
+ let filter = self.node.borrow().get_impl::<NodeFilter>();
// See comments in compute_effects_region() for how this works.
if filter.primitiveunits.get() == CoordUnits::ObjectBoundingBox {
diff --git a/rsvg_internals/src/filters/light/lighting.rs b/rsvg_internals/src/filters/light/lighting.rs
index ae23f8cd..be60c16f 100644
--- a/rsvg_internals/src/filters/light/lighting.rs
+++ b/rsvg_internals/src/filters/light/lighting.rs
@@ -222,22 +222,26 @@ impl Filter for Lighting {
cssparser::Color::RGBA(rgba) => rgba,
};
- let mut light_sources = node.children().rev().filter(|c| match c.get_type() {
- NodeType::DistantLight | NodeType::PointLight | NodeType::SpotLight => true,
- _ => false,
- });
+ let mut light_sources = node
+ .children()
+ .rev()
+ .filter(|c| match c.borrow().get_type() {
+ NodeType::DistantLight | NodeType::PointLight | NodeType::SpotLight => true,
+ _ => false,
+ });
+
let light_source = light_sources.next();
if light_source.is_none() || light_sources.next().is_some() {
return Err(FilterError::InvalidLightSourceCount);
}
let light_source = light_source.unwrap();
- if light_source.is_in_error() {
+ if light_source.borrow().is_in_error() {
return Err(FilterError::ChildNodeInError);
}
- let light_source = light_source.get_impl::<LightSource>();
- let light_source = light_source.transform(ctx);
+ let node_data = light_source.borrow();
+ let light_source = node_data.get_impl::<LightSource>().transform(ctx);
let mut input_surface = input.surface().clone();
diff --git a/rsvg_internals/src/filters/merge.rs b/rsvg_internals/src/filters/merge.rs
index 45d5824b..b2fe46d8 100644
--- a/rsvg_internals/src/filters/merge.rs
+++ b/rsvg_internals/src/filters/merge.rs
@@ -123,15 +123,15 @@ impl Filter for Merge {
let mut bounds = self.base.get_bounds(ctx);
for child in node
.children()
- .filter(|c| c.get_type() == NodeType::FeMergeNode)
+ .filter(|c| c.borrow().get_type() == NodeType::FeMergeNode)
{
- if child.is_in_error() {
+ if child.borrow().is_in_error() {
return Err(FilterError::ChildNodeInError);
}
let input = ctx.get_input(
draw_ctx,
- child.get_impl::<MergeNode>().in_.borrow().as_ref(),
+ child.borrow().get_impl::<MergeNode>().in_.borrow().as_ref(),
)?;
bounds = bounds.add_input(&input);
}
@@ -141,9 +141,9 @@ impl Filter for Merge {
let mut output_surface = None;
for child in node
.children()
- .filter(|c| c.get_type() == NodeType::FeMergeNode)
+ .filter(|c| c.borrow().get_type() == NodeType::FeMergeNode)
{
- output_surface = Some(child.get_impl::<MergeNode>().render(
+ output_surface = Some(child.borrow().get_impl::<MergeNode>().render(
ctx,
draw_ctx,
bounds,
diff --git a/rsvg_internals/src/filters/mod.rs b/rsvg_internals/src/filters/mod.rs
index 0b9a2e40..04f002d6 100644
--- a/rsvg_internals/src/filters/mod.rs
+++ b/rsvg_internals/src/filters/mod.rs
@@ -124,8 +124,14 @@ impl NodeTrait for Primitive {
let primitiveunits = node
.parent()
.and_then(|parent| {
- if parent.get_type() == NodeType::Filter {
- Some(parent.get_impl::<NodeFilter>().primitiveunits.get())
+ if parent.borrow().get_type() == NodeType::Filter {
+ Some(
+ parent
+ .borrow()
+ .get_impl::<NodeFilter>()
+ .primitiveunits
+ .get(),
+ )
} else {
None
}
@@ -263,8 +269,8 @@ pub fn render(
node_bbox: BoundingBox,
) -> Result<cairo::ImageSurface, RenderingError> {
let filter_node = &*filter_node;
- assert_eq!(filter_node.get_type(), NodeType::Filter);
- assert!(!filter_node.is_in_error());
+ assert_eq!(filter_node.borrow().get_type(), NodeType::Filter);
+ assert!(!filter_node.borrow().is_in_error());
// The source surface has multiple references. We need to copy it to a new surface to have a
// unique reference to be able to safely access the pixel data.
@@ -288,7 +294,7 @@ pub fn render(
.children()
// Skip nodes in error.
.filter(|c| {
- let in_error = c.is_in_error();
+ let in_error = c.borrow().is_in_error();
if in_error {
rsvg_log!("(ignoring filter primitive {} because it is in error)", c);
@@ -311,7 +317,8 @@ pub fn render(
});
for (c, linear_rgb) in primitives {
- let filter = c.borrow().get_node_trait().as_filter().unwrap();
+ let node_data = c.borrow();
+ let filter = node_data.get_node_trait().as_filter().unwrap();
let mut render = |filter_ctx: &mut FilterContext| {
if let Err(err) = filter
diff --git a/rsvg_internals/src/gradient.rs b/rsvg_internals/src/gradient.rs
index f0e01567..99cc521f 100644
--- a/rsvg_internals/src/gradient.rs
+++ b/rsvg_internals/src/gradient.rs
@@ -367,18 +367,18 @@ impl Gradient {
fn add_color_stops_from_node(&mut self, node: &RsvgNode) {
assert!(
- node.get_type() == NodeType::LinearGradient
- || node.get_type() == NodeType::RadialGradient
+ node.borrow().get_type() == NodeType::LinearGradient
+ || node.borrow().get_type() == NodeType::RadialGradient
);
for child in node
.children()
- .filter(|child| child.get_type() == NodeType::Stop)
+ .filter(|child| child.borrow().get_type() == NodeType::Stop)
{
- if child.is_in_error() {
+ if child.borrow().is_in_error() {
rsvg_log!("(not using gradient stop {} because it is in error)", child);
} else {
- let offset = child.get_impl::<NodeStop>().get_offset();
+ let offset = child.borrow().get_impl::<NodeStop>().get_offset();
let cascaded = CascadedValues::new_from_node(&child);
let values = cascaded.get();
let rgba = match values.stop_color {
@@ -437,7 +437,7 @@ fn acquire_gradient<'a>(
) -> Option<AcquiredNode> {
name.and_then(move |fragment| draw_ctx.acquired_nodes().get_node(fragment))
.and_then(|acquired| {
- let node_type = acquired.get().get_type();
+ let node_type = acquired.get().borrow().get_type();
if node_type == NodeType::LinearGradient || node_type == NodeType::RadialGradient {
Some(acquired)
@@ -608,7 +608,12 @@ impl PaintSource for NodeGradient {
}
fn get_gradient_with_color_stops_from_node(node: &RsvgNode) -> Gradient {
- let mut gradient = node.get_impl::<NodeGradient>().gradient.borrow().clone();
+ let mut gradient = node
+ .borrow()
+ .get_impl::<NodeGradient>()
+ .gradient
+ .borrow()
+ .clone();
gradient.add_color_stops_from_node(node);
gradient
}
@@ -679,7 +684,7 @@ impl NodeTrait for NodeGradient {
}
}
- match node.get_type() {
+ match node.borrow().get_type() {
NodeType::LinearGradient => {
g.variant = GradientVariant::Linear { x1, y1, x2, y2 };
}
diff --git a/rsvg_internals/src/handle.rs b/rsvg_internals/src/handle.rs
index 4fb1846f..c70f7b72 100644
--- a/rsvg_internals/src/handle.rs
+++ b/rsvg_internals/src/handle.rs
@@ -240,7 +240,7 @@ impl Handle {
let values = cascaded.get();
if let Some((root_width, root_height)) =
- node.get_impl::<NodeSvg>().get_size(&values, dpi)
+ node.borrow().get_impl::<NodeSvg>().get_size(&values, dpi)
{
let ink_r = RsvgRectangle {
x: 0.0,
diff --git a/rsvg_internals/src/marker.rs b/rsvg_internals/src/marker.rs
index 4c6c67ae..39277f79 100644
--- a/rsvg_internals/src/marker.rs
+++ b/rsvg_internals/src/marker.rs
@@ -606,7 +606,7 @@ fn emit_marker_by_name(
{
let node = acquired.get();
- node.get_impl::<NodeMarker>().render(
+ node.borrow().get_impl::<NodeMarker>().render(
&node,
draw_ctx,
xpos,
diff --git a/rsvg_internals/src/mask.rs b/rsvg_internals/src/mask.rs
index 8718bf66..52d1c562 100644
--- a/rsvg_internals/src/mask.rs
+++ b/rsvg_internals/src/mask.rs
@@ -93,7 +93,7 @@ impl NodeMask {
{
let mask_cr = cairo::Context::new(&mask_content_surface);
mask_cr.set_matrix(affines.for_temporary_surface);
- mask_cr.transform(mask_node.get_transform());
+ mask_cr.transform(mask_node.borrow().get_transform());
draw_ctx.push_cairo_context(mask_cr);
diff --git a/rsvg_internals/src/node.rs b/rsvg_internals/src/node.rs
index 648a9fbd..520c0f2b 100644
--- a/rsvg_internals/src/node.rs
+++ b/rsvg_internals/src/node.rs
@@ -8,8 +8,8 @@ use std::fmt;
use crate::cond::{RequiredExtensions, RequiredFeatures, SystemLanguage};
use crate::css::CssRules;
use crate::drawing_ctx::DrawingCtx;
-use crate::filters::Filter;
use crate::error::*;
+use crate::filters::Filter;
use crate::parsers::Parse;
use crate::properties::{ComputedValues, SpecifiedValue, SpecifiedValues};
use crate::property_bag::PropertyBag;
@@ -65,8 +65,12 @@ impl NodeData {
self.node_impl.as_ref()
}
- pub fn get_impl<T: NodeTrait>(&self) -> Option<&T> {
- (&self.node_impl).downcast_ref::<T>()
+ pub fn get_impl<T: NodeTrait>(&self) -> &T {
+ if let Some(t) = (&self.node_impl).downcast_ref::<T>() {
+ t
+ } else {
+ panic!("could not downcast");
+ }
}
pub fn get_type(&self) -> NodeType {
@@ -85,6 +89,18 @@ impl NodeData {
self.class.as_ref().map(String::as_str)
}
+ pub fn get_cond(&self) -> bool {
+ self.cond.get()
+ }
+
+ pub fn get_transform(&self) -> Matrix {
+ self.transform.get()
+ }
+
+ pub fn is_overflow(&self) -> bool {
+ self.specified_values.borrow().is_overflow()
+ }
+
pub fn set_atts(&self, node: &RsvgNode, pbag: &PropertyBag<'_>, locale: &Locale) {
if self.node_impl.overflow_hidden() {
let mut specified_values = self.specified_values.borrow_mut();
@@ -246,6 +262,10 @@ impl NodeData {
fn set_error(&self, error: NodeError) {
*self.result.borrow_mut() = Err(error);
}
+
+ pub fn is_in_error(&self) -> bool {
+ self.result.borrow().is_err()
+ }
}
impl fmt::Display for NodeData {
@@ -452,26 +472,6 @@ pub enum NodeType {
}
impl RsvgNode {
- pub fn get_type(&self) -> NodeType {
- self.borrow().get_type()
- }
-
- pub fn element_name(&self) -> &str {
- self.borrow().element_name()
- }
-
- pub fn get_id(&self) -> Option<&str> {
- self.borrow().get_id()
- }
-
- pub fn get_class(&self) -> Option<&str> {
- self.borrow().get_class()
- }
-
- pub fn get_transform(&self) -> Matrix {
- self.borrow().transform.get()
- }
-
pub fn cascade(&self, values: &ComputedValues) {
let mut values = values.clone();
self.borrow()
@@ -493,26 +493,20 @@ impl RsvgNode {
}
}
- pub fn get_cond(&self) -> bool {
- self.borrow().cond.get()
- }
-
- pub fn set_atts(&self, node: &RsvgNode, pbag: &PropertyBag<'_>, locale: &Locale) {
- self.borrow().set_atts(node, pbag, locale);
- }
-
pub fn draw(
&self,
cascaded: &CascadedValues<'_>,
draw_ctx: &mut DrawingCtx,
clipping: bool,
) -> Result<(), RenderingError> {
- if !self.is_in_error() {
+ if !self.borrow().is_in_error() {
draw_ctx.with_saved_matrix(&mut |dc| {
let cr = dc.get_cairo_context();
- cr.transform(self.get_transform());
+ cr.transform(self.borrow().get_transform());
- self.borrow().get_node_trait().draw(self, cascaded, dc, clipping)
+ self.borrow()
+ .get_node_trait()
+ .draw(self, cascaded, dc, clipping)
})
} else {
rsvg_log!("(not rendering element {} because it is in error)", self);
@@ -521,18 +515,6 @@ impl RsvgNode {
}
}
- pub fn is_in_error(&self) -> bool {
- self.borrow().result.borrow().is_err()
- }
-
- pub fn get_impl<T: NodeTrait>(&self) -> &T {
- if let Some(t) = self.borrow().get_impl::<T>() {
- t
- } else {
- panic!("could not downcast");
- }
- }
-
pub fn draw_children(
&self,
cascaded: &CascadedValues<'_>,
@@ -549,8 +531,4 @@ impl RsvgNode {
Ok(())
}
-
- pub fn is_overflow(&self) -> bool {
- self.borrow().specified_values.borrow().is_overflow()
- }
}
diff --git a/rsvg_internals/src/pattern.rs b/rsvg_internals/src/pattern.rs
index e62d04f1..e6c3ce26 100644
--- a/rsvg_internals/src/pattern.rs
+++ b/rsvg_internals/src/pattern.rs
@@ -229,7 +229,12 @@ impl PaintSource for NodePattern {
draw_ctx: &mut DrawingCtx,
_bbox: &BoundingBox,
) -> Result<Option<Self::Source>, RenderingError> {
- let mut result = node.get_impl::<NodePattern>().pattern.borrow().clone();
+ let mut result = node
+ .borrow()
+ .get_impl::<NodePattern>()
+ .pattern
+ .borrow()
+ .clone();
let mut stack = NodeStack::new();
while !result.is_resolved() {
@@ -244,7 +249,7 @@ impl PaintSource for NodePattern {
return Err(RenderingError::CircularReference);
}
- let fallback = a_node.get_impl::<NodePattern>().pattern.borrow();
+ let fallback = a_node.borrow().get_impl::<NodePattern>().pattern.borrow();
result.resolve_from_fallback(&fallback);
stack.push(a_node);
diff --git a/rsvg_internals/src/structure.rs b/rsvg_internals/src/structure.rs
index 9cc68e1d..4e19068c 100644
--- a/rsvg_internals/src/structure.rs
+++ b/rsvg_internals/src/structure.rs
@@ -76,8 +76,8 @@ impl NodeTrait for NodeSwitch {
draw_ctx.with_discrete_layer(node, values, clipping, &mut |dc| {
if let Some(child) = node
.children()
- .filter(|c| c.get_type() != NodeType::Chars)
- .find(|c| c.get_cond())
+ .filter(|c| c.borrow().get_type() != NodeType::Chars)
+ .find(|c| c.borrow().get_cond())
{
dc.draw_node_from_stack(&CascadedValues::new(cascaded, &child), &child, clipping)
} else {
@@ -383,7 +383,7 @@ impl NodeTrait for NodeUse {
let viewport = Rectangle::new(nx, ny, nw, nh);
- if child.get_type() != NodeType::Symbol {
+ if child.borrow().get_type() != NodeType::Symbol {
let cr = draw_ctx.get_cairo_context();
cr.translate(viewport.x, viewport.y);
@@ -395,10 +395,10 @@ impl NodeTrait for NodeUse {
)
})
} else {
- let symbol = child.get_impl::<NodeSymbol>();
+ let symbol = child.borrow().get_impl::<NodeSymbol>();
let clip_mode = if !values.is_overflow()
- || (values.overflow == Overflow::Visible && child.is_overflow())
+ || (values.overflow == Overflow::Visible && child.borrow().is_overflow())
{
Some(ClipMode::ClipToVbox)
} else {
diff --git a/rsvg_internals/src/style.rs b/rsvg_internals/src/style.rs
index 9bdacf02..4e4bd362 100644
--- a/rsvg_internals/src/style.rs
+++ b/rsvg_internals/src/style.rs
@@ -37,8 +37,8 @@ impl NodeStyle {
node.children()
.into_iter()
.filter_map(|child| {
- if child.get_type() == NodeType::Chars {
- Some(child.get_impl::<NodeChars>().get_string())
+ if child.borrow().get_type() == NodeType::Chars {
+ Some(child.borrow().get_impl::<NodeChars>().get_string())
} else {
None
}
diff --git a/rsvg_internals/src/svg.rs b/rsvg_internals/src/svg.rs
index b9596061..c3fc42be 100644
--- a/rsvg_internals/src/svg.rs
+++ b/rsvg_internals/src/svg.rs
@@ -88,9 +88,11 @@ impl Svg {
pub fn get_intrinsic_dimensions(&self) -> IntrinsicDimensions {
let root = self.root();
- assert!(root.get_type() == NodeType::Svg);
+ assert!(root.borrow().get_type() == NodeType::Svg);
- root.get_impl::<NodeSvg>().get_intrinsic_dimensions()
+ root.borrow()
+ .get_impl::<NodeSvg>()
+ .get_intrinsic_dimensions()
}
}
diff --git a/rsvg_internals/src/text.rs b/rsvg_internals/src/text.rs
index e1d01cd8..6592c71d 100644
--- a/rsvg_internals/src/text.rs
+++ b/rsvg_internals/src/text.rs
@@ -419,17 +419,18 @@ fn children_to_chunks(
depth: usize,
) {
for child in node.children() {
- match child.get_type() {
+ match child.borrow().get_type() {
NodeType::Chars => {
let values = cascaded.get();
child
+ .borrow()
.get_impl::<NodeChars>()
.to_chunks(&child, values, chunks, dx, dy, depth);
}
NodeType::TSpan => {
let cascaded = CascadedValues::new(cascaded, &child);
- child.get_impl::<NodeTSpan>().to_chunks(
+ child.borrow().get_impl::<NodeTSpan>().to_chunks(
&child,
&cascaded,
draw_ctx,
@@ -440,7 +441,7 @@ fn children_to_chunks(
NodeType::TRef => {
let cascaded = CascadedValues::new(cascaded, &child);
- child.get_impl::<NodeTRef>().to_chunks(
+ child.borrow().get_impl::<NodeTRef>().to_chunks(
&child,
&cascaded,
draw_ctx,
@@ -696,8 +697,9 @@ fn extract_chars_children_to_chunks_recursively(
depth: usize,
) {
for child in node.children() {
- match child.get_type() {
+ match child.borrow().get_type() {
NodeType::Chars => child
+ .borrow()
.get_impl::<NodeChars>()
.to_chunks(&child, values, chunks, None, None, depth),
_ => extract_chars_children_to_chunks_recursively(chunks, &child, values, depth + 1),
diff --git a/rsvg_internals/src/xml.rs b/rsvg_internals/src/xml.rs
index c7dce978..de663675 100644
--- a/rsvg_internals/src/xml.rs
+++ b/rsvg_internals/src/xml.rs
@@ -113,7 +113,7 @@ impl XmlState {
pub fn steal_result(&mut self) -> Result<Svg, LoadingError> {
match self.tree_root {
None => Err(LoadingError::SvgHasNoElements),
- Some(ref root) if root.get_type() == NodeType::Svg => {
+ Some(ref root) if root.borrow().get_type() == NodeType::Svg => {
let root = self.tree_root.take().unwrap();
root.set_styles_recursively(&root, self.css_rules.as_ref().unwrap());
@@ -259,6 +259,7 @@ impl XmlState {
_ => {
let parent = self.current_node.clone();
let node = self.create_node(parent.as_ref(), name, pbag);
+
if self.current_node.is_none() {
self.set_root(&node);
}
@@ -272,8 +273,8 @@ impl XmlState {
fn element_creation_end_element(&mut self) {
let node = self.current_node.take().unwrap();
- if node.get_type() == NodeType::Style {
- let css_data = node.get_impl::<NodeStyle>().get_css(&node);
+ if node.borrow().get_type() == NodeType::Style {
+ let css_data = node.borrow().get_impl::<NodeStyle>().get_css(&node);
let css_rules = self.css_rules.as_mut().unwrap();
@@ -291,7 +292,7 @@ impl XmlState {
// the text and avoid screwing up the Pango layouts
let chars_node = if let Some(child) = node
.last_child()
- .filter(|c| c.get_type() == NodeType::Chars)
+ .filter(|c| c.borrow().get_type() == NodeType::Chars)
{
child
} else {
@@ -309,7 +310,7 @@ impl XmlState {
child
};
- chars_node.get_impl::<NodeChars>().append(text);
+ chars_node.borrow().get_impl::<NodeChars>().append(text);
}
}
@@ -327,7 +328,9 @@ impl XmlState {
parent.append(&new_node);
}
- new_node.set_atts(&new_node, pbag, self.load_options.locale());
+ new_node
+ .borrow()
+ .set_atts(&new_node, pbag, self.load_options.locale());
new_node
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]