[librsvg/rustification] Use an accessor function rsvg_node_get_parent() throughout
- From: Federico Mena Quintero <federico src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [librsvg/rustification] Use an accessor function rsvg_node_get_parent() throughout
- Date: Fri, 25 Nov 2016 22:38:34 +0000 (UTC)
commit d1ef96e0e4c5075a5ef34df5703c6adcb49c35b0
Author: Federico Mena Quintero <federico gnome org>
Date: Tue Nov 22 14:43:56 2016 -0600
Use an accessor function rsvg_node_get_parent() throughout
Also, fix a three-part hack:
1. rsvg_standard_element_start() would set the new node's parent right
there, in redundant fashion to where rsvg_node_group_pack() sets the
node's parent.
2. Make rsvg_standard_element_start() add the new node to its parent
before node->set_atts() gets called...
3. ... so that rsvg_stop_set_atts() doesn't have to set its own parent
to ctx->priv->currentnode (!) because the stop's node hasn't been
parented yet. This was the only place where a node->parent gets
overwritten after creation.
rsvg-base.c | 20 +++++++++++++-------
rsvg-cairo-render.c | 4 ++--
rsvg-paint-server.c | 2 --
rsvg-private.h | 3 +++
rsvg-structure.c | 17 ++++++++++-------
rsvg-styles.c | 2 +-
6 files changed, 29 insertions(+), 19 deletions(-)
---
diff --git a/rsvg-base.c b/rsvg-base.c
index f259c58..9b6f651 100644
--- a/rsvg-base.c
+++ b/rsvg-base.c
@@ -415,21 +415,21 @@ rsvg_standard_element_start (RsvgHandle * ctx, const char *name, RsvgPropertyBag
if (newnode) {
g_assert (RSVG_NODE_TYPE (newnode) != RSVG_NODE_TYPE_INVALID);
- newnode->parent = ctx->priv->currentnode;
push_element_name (ctx, name);
add_node_to_handle (ctx, newnode);
register_node_in_defs (ctx, newnode, atts);
- node_set_atts (newnode, ctx, creator, atts);
if (ctx->priv->currentnode) {
rsvg_node_group_pack (ctx->priv->currentnode, newnode);
- ctx->priv->currentnode = newnode;
} else if (RSVG_NODE_TYPE (newnode) == RSVG_NODE_TYPE_SVG) {
ctx->priv->treebase = newnode;
- ctx->priv->currentnode = newnode;
}
+
+ ctx->priv->currentnode = newnode;
+
+ node_set_atts (newnode, ctx, creator, atts);
}
}
@@ -439,6 +439,12 @@ rsvg_node_get_state (RsvgNode *node)
return node->state;
}
+RsvgNode *
+rsvg_node_get_parent (RsvgNode *node)
+{
+ return node->parent;
+}
+
/* extra (title, desc, metadata) */
static void
@@ -837,7 +843,7 @@ rsvg_end_element (void *data, const xmlChar * xmlname)
}
if (ctx->priv->currentnode && topmost_element_name_is (ctx, name)) {
- ctx->priv->currentnode = ctx->priv->currentnode->parent;
+ ctx->priv->currentnode = rsvg_node_get_parent (ctx->priv->currentnode);
pop_element_name (ctx);
}
@@ -1539,7 +1545,7 @@ rsvg_handle_get_dimensions_sub (RsvgHandle * handle, RsvgDimensionData * dimensi
while (sself != NULL) {
draw->drawsub_stack = g_slist_prepend (draw->drawsub_stack, sself);
- sself = sself->parent;
+ sself = rsvg_node_get_parent (sself);
}
rsvg_state_push (draw);
@@ -1636,7 +1642,7 @@ rsvg_handle_get_position_sub (RsvgHandle * handle, RsvgPositionData * position_d
while (node != NULL) {
draw->drawsub_stack = g_slist_prepend (draw->drawsub_stack, node);
- node = node->parent;
+ node = rsvg_node_get_parent (node);
}
rsvg_state_push (draw);
diff --git a/rsvg-cairo-render.c b/rsvg-cairo-render.c
index f75d331..f196e70 100644
--- a/rsvg-cairo-render.c
+++ b/rsvg-cairo-render.c
@@ -217,13 +217,13 @@ rsvg_handle_render_cairo_sub (RsvgHandle * handle, cairo_t * cr, const char *id)
while (drawsub != NULL) {
draw->drawsub_stack = g_slist_prepend (draw->drawsub_stack, drawsub);
- drawsub = drawsub->parent;
+ drawsub = rsvg_node_get_parent (drawsub);
}
rsvg_state_push (draw);
cairo_save (cr);
- rsvg_node_draw ((RsvgNode *) handle->priv->treebase, draw, 0);
+ rsvg_node_draw (handle->priv->treebase, draw, 0);
cairo_restore (cr);
rsvg_state_pop (draw);
diff --git a/rsvg-paint-server.c b/rsvg-paint-server.c
index 0871ec9..e5477c9 100644
--- a/rsvg-paint-server.c
+++ b/rsvg-paint-server.c
@@ -197,8 +197,6 @@ rsvg_stop_set_atts (RsvgNode * self, RsvgHandle * ctx, RsvgPropertyBag * atts)
rsvg_parse_style_pairs (ctx, rsvg_node_get_state (self), atts);
- self->parent = ctx->priv->currentnode;
-
state = rsvg_state_new ();
rsvg_state_reconstruct (state, self);
diff --git a/rsvg-private.h b/rsvg-private.h
index b51c9e3..a5d55a8 100644
--- a/rsvg-private.h
+++ b/rsvg-private.h
@@ -343,6 +343,9 @@ struct _RsvgNode {
G_GNUC_INTERNAL
RsvgState *rsvg_node_get_state (RsvgNode *node);
+G_GNUC_INTERNAL
+RsvgNode *rsvg_node_get_parent (RsvgNode *node);
+
struct _RsvgNodeChars {
RsvgNode super;
GString *contents;
diff --git a/rsvg-structure.c b/rsvg-structure.c
index 43e396c..ab6ec6d 100644
--- a/rsvg-structure.c
+++ b/rsvg-structure.c
@@ -142,10 +142,10 @@ rsvg_node_is_ancestor (RsvgNode * potential_ancestor, RsvgNode * potential_desce
while (TRUE) {
if (potential_ancestor == potential_descendant)
return TRUE;
- else if (potential_descendant->parent == NULL)
+ else if (rsvg_node_get_parent (potential_descendant) == NULL)
return FALSE;
else
- potential_descendant = potential_descendant->parent;
+ potential_descendant = rsvg_node_get_parent (potential_descendant);
}
g_assert_not_reached ();
@@ -274,7 +274,7 @@ rsvg_node_svg_draw (RsvgNode * self, RsvgDrawingCtx * ctx, int dominate)
/* Bounding box addition must be AFTER the discrete layer push,
which must be AFTER the transformation happens. */
- if (!state->overflow && self->parent) {
+ if (!state->overflow && rsvg_node_get_parent (self)) {
state->affine = affine_old;
rsvg_add_clipping_rect (ctx, nx, ny, nw, nh);
state->affine = affine_new;
@@ -309,10 +309,13 @@ rsvg_node_svg_set_atts (RsvgNode * self, RsvgHandle * ctx, RsvgPropertyBag * att
* x & y attributes have no effect on outermost svg
* http://www.w3.org/TR/SVG/struct.html#SVGElement
*/
- if (self->parent && (value = rsvg_property_bag_lookup (atts, "x")))
- svg->x = rsvg_length_parse (value, LENGTH_DIR_HORIZONTAL);
- if (self->parent && (value = rsvg_property_bag_lookup (atts, "y")))
- svg->y = rsvg_length_parse (value, LENGTH_DIR_VERTICAL);
+ if (rsvg_node_get_parent (self)) {
+ if ((value = rsvg_property_bag_lookup (atts, "x")))
+ svg->x = rsvg_length_parse (value, LENGTH_DIR_HORIZONTAL);
+
+ if ((value = rsvg_property_bag_lookup (atts, "y")))
+ svg->y = rsvg_length_parse (value, LENGTH_DIR_VERTICAL);
+ }
/*
* style element is not loaded yet here, so we need to store those attribues
diff --git a/rsvg-styles.c b/rsvg-styles.c
index 4401936..8ad677c 100644
--- a/rsvg-styles.c
+++ b/rsvg-styles.c
@@ -1725,6 +1725,6 @@ rsvg_state_reconstruct (RsvgState * state, RsvgNode * current)
{
if (current == NULL)
return;
- rsvg_state_reconstruct (state, current->parent);
+ rsvg_state_reconstruct (state, rsvg_node_get_parent (current));
rsvg_state_inherit (state, rsvg_node_get_state (current));
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]