[librsvg] [PATCH 1/3] RsvgState has its parent state to traverse its ancestors.



commit 1f859f2b4d4e1dd820544225da41ed9e32f7f195
Author: Hiroyuki Ikezoe <hiikezoe gnome org>
Date:   Sun May 2 11:29:18 2010 +0900

    [PATCH 1/3] RsvgState has its parent state to traverse its ancestors.
    
    Now we can get ancestor's font-size.

 rsvg-base.c    |   10 +------
 rsvg-marker.c  |    3 +-
 rsvg-private.h |    2 +-
 rsvg-styles.c  |   78 +++++++++++++++++++++++++++++++++-----------------------
 rsvg-styles.h  |    5 +++-
 5 files changed, 53 insertions(+), 45 deletions(-)
---
diff --git a/rsvg-base.c b/rsvg-base.c
index 98df788..c4b2027 100644
--- a/rsvg-base.c
+++ b/rsvg-base.c
@@ -1178,20 +1178,12 @@ rsvg_handle_close_impl (RsvgHandle * handle, GError ** error)
     return TRUE;
 }
 
-static void
-rsvg_state_free_func (gpointer data, gpointer user_data)
-{
-    rsvg_state_finalize ((RsvgState *) data);
-    g_slice_free (RsvgState, data);
-}
-
 void
 rsvg_drawing_ctx_free (RsvgDrawingCtx * handle)
 {
     rsvg_render_free (handle->render);
 
-    g_slist_foreach (handle->state, rsvg_state_free_func, (gpointer) handle);
-    g_slist_free (handle->state);
+    rsvg_state_free_all (handle->state);
 
 	/* the drawsub stack's nodes are owned by the ->defs */
 	g_slist_free (handle->drawsub_stack);
diff --git a/rsvg-marker.c b/rsvg-marker.c
index f66b8fc..8bf27bc 100644
--- a/rsvg-marker.c
+++ b/rsvg-marker.c
@@ -153,8 +153,7 @@ rsvg_marker_render (RsvgMarker * self, gdouble x, gdouble y, gdouble orient, gdo
     rsvg_state_push (ctx);
     state = rsvg_state_current (ctx);
 
-    rsvg_state_finalize (state);
-    rsvg_state_init (state);
+    rsvg_state_reinit (state);
 
     rsvg_state_reconstruct (state, &self->super);
 
diff --git a/rsvg-private.h b/rsvg-private.h
index 737ed13..04af5eb 100644
--- a/rsvg-private.h
+++ b/rsvg-private.h
@@ -180,7 +180,7 @@ typedef struct {
 
 struct RsvgDrawingCtx {
     RsvgRender *render;
-    GSList *state;
+    RsvgState *state;
     GError **error;
     RsvgDefs *defs;
     gchar *base_uri;
diff --git a/rsvg-styles.c b/rsvg-styles.c
index fab671c..25301db 100644
--- a/rsvg-styles.c
+++ b/rsvg-styles.c
@@ -80,6 +80,7 @@ rsvg_state_init (RsvgState * state)
 {
     memset (state, 0, sizeof (RsvgState));
 
+    state->parent = NULL;
     _rsvg_affine_identity (state->affine);
     _rsvg_affine_identity (state->personal_affine);
     state->mask = NULL;
@@ -164,16 +165,27 @@ rsvg_state_init (RsvgState * state)
                                            g_free, (GDestroyNotify) style_value_data_free);
 }
 
+void
+rsvg_state_reinit (RsvgState * state)
+{
+    RsvgState *parent = state->parent;
+    rsvg_state_finalize (state);
+    rsvg_state_init (state);
+    state->parent = parent;
+}
+
 typedef int (*InheritanceFunction) (int dst, int src);
 
 void
 rsvg_state_clone (RsvgState * dst, const RsvgState * src)
 {
     gint i;
+    RsvgState *parent = dst->parent;
 
     rsvg_state_finalize (dst);
 
     *dst = *src;
+    dst->parent = parent;
     dst->font_family = g_strdup (src->font_family);
     dst->lang = g_strdup (src->lang);
     rsvg_paint_server_ref (dst->fill);
@@ -1494,13 +1506,24 @@ rsvg_parse_style_attrs (RsvgHandle * ctx,
 RsvgState *
 rsvg_state_current (RsvgDrawingCtx * ctx)
 {
-    return g_slist_nth_data (ctx->state, 0);
+    return ctx->state;
 }
 
 RsvgState *
-rsvg_state_parent (RsvgDrawingCtx * ctx)
+rsvg_state_parent (RsvgState * state)
+{
+    return state->parent;
+}
+
+void
+rsvg_state_free_all (RsvgState * state)
 {
-    return g_slist_nth_data (ctx->state, 1);
+    while (state) {
+	RsvgState *parent = state->parent;
+	rsvg_state_finalize (state);
+	g_slice_free (RsvgState, state);
+	state = parent;
+    }
 }
 
 RsvgPropertyBag *
@@ -1556,29 +1579,27 @@ rsvg_state_push (RsvgDrawingCtx * ctx)
     RsvgState *data;
     RsvgState *baseon;
 
-    baseon = (RsvgState *) g_slist_nth_data (ctx->state, 0);
+    baseon = ctx->state;
     data = g_slice_new (RsvgState);
+    rsvg_state_init (data);
 
     if (baseon) {
         int i;
-        rsvg_state_init (data);
         rsvg_state_reinherit (data, baseon);
         for (i = 0; i < 6; i++)
             data->affine[i] = baseon->affine[i];
-    } else
-        rsvg_state_init (data);
+        data->parent = baseon;
+    }
 
-    ctx->state = g_slist_prepend (ctx->state, data);
+    ctx->state = data;
 }
 
 void
 rsvg_state_pop (RsvgDrawingCtx * ctx)
 {
-    GSList *link = g_slist_nth (ctx->state, 0);
-    RsvgState *dead_state = (RsvgState *) link->data;
-
+    RsvgState *dead_state = ctx->state;
+    ctx->state = dead_state->parent;
     rsvg_state_finalize (dead_state);
-    ctx->state = g_slist_delete_link (ctx->state, link);
     g_slice_free (RsvgState, dead_state);
 }
 
@@ -1599,34 +1620,27 @@ rsvg_state_pop (RsvgDrawingCtx * ctx)
 void
 rsvg_state_reinherit_top (RsvgDrawingCtx * ctx, RsvgState * state, int dominate)
 {
+    RsvgState *current;
+
     if (dominate == 3)
         return;
 
+    current = rsvg_state_current (ctx);
     /*This is a special domination mode for patterns, the transform
        is simply left as is, wheras the style is totally overridden */
     if (dominate == 2) {
-        rsvg_state_override (rsvg_state_current (ctx), state);
-    } else if (dominate) {
-        RsvgState *parent;
-        rsvg_state_clone (rsvg_state_current (ctx), state);
-
-        parent = rsvg_state_parent (ctx);
-        if (parent) {
-            rsvg_state_dominate (rsvg_state_current (ctx), rsvg_state_parent (ctx));
-            _rsvg_affine_multiply (rsvg_state_current (ctx)->affine,
-                                   rsvg_state_current (ctx)->affine,
-                                   rsvg_state_parent (ctx)->affine);
-        }
+        rsvg_state_override (current, state);
     } else {
-        RsvgState *parent;
-        rsvg_state_clone (rsvg_state_current (ctx), state);
-
-        parent = rsvg_state_parent (ctx);
+        RsvgState *parent= rsvg_state_parent (current);
+        rsvg_state_clone (current, state);
         if (parent) {
-            rsvg_state_reinherit (rsvg_state_current (ctx), rsvg_state_parent (ctx));
-            _rsvg_affine_multiply (rsvg_state_current (ctx)->affine,
-                                   rsvg_state_current (ctx)->affine,
-                                   rsvg_state_parent (ctx)->affine);
+            if (dominate)
+                rsvg_state_dominate (current, parent);
+	    else
+                rsvg_state_reinherit (current, parent);
+            _rsvg_affine_multiply (current->affine,
+                                   current->affine,
+                                   parent->affine);
         }
     }
 }
diff --git a/rsvg-styles.h b/rsvg-styles.h
index 08ec702..e8d32d6 100644
--- a/rsvg-styles.h
+++ b/rsvg-styles.h
@@ -132,6 +132,7 @@ struct _RsvgVpathDash {
 /* end libart theft... */
 
 struct _RsvgState {
+    RsvgState *parent;
     double affine[6];
     double personal_affine[6];
 
@@ -243,12 +244,14 @@ struct _RsvgState {
 RsvgState *rsvg_state_new (void);
 
 void rsvg_state_init        (RsvgState * state);
+void rsvg_state_reinit      (RsvgState * state);
 void rsvg_state_clone       (RsvgState * dst, const RsvgState * src);
 void rsvg_state_inherit     (RsvgState * dst, const RsvgState * src);
 void rsvg_state_reinherit   (RsvgState * dst, const RsvgState * src);
 void rsvg_state_dominate    (RsvgState * dst, const RsvgState * src);
 void rsvg_state_override    (RsvgState * dst, const RsvgState * src);
 void rsvg_state_finalize    (RsvgState * state);
+void rsvg_state_free_all    (RsvgState * state);
 
 void rsvg_parse_style_pairs (RsvgHandle * ctx, RsvgState * state, RsvgPropertyBag * atts);
 void rsvg_parse_style	    (RsvgHandle * ctx, RsvgState * state, const char *str);
@@ -262,7 +265,7 @@ gdouble rsvg_dpi_percentage      (RsvgHandle * ctx);
 
 gboolean rsvg_parse_transform   (double dst[6], const char *src);
 
-RsvgState *rsvg_state_parent    (RsvgDrawingCtx * ctx);
+RsvgState *rsvg_state_parent    (RsvgState * state);
 RsvgState *rsvg_state_current   (RsvgDrawingCtx * ctx);
 
 void rsvg_state_pop	 (RsvgDrawingCtx * ctx);



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]