[librsvg/rustification] node_set_atts(): Call rsvg_parse_style_attrs() here, not in every node implementation



commit 54dc79f6609e53fa956f53d9fbb80c687075ee92
Author: Federico Mena Quintero <federico gnome org>
Date:   Fri Nov 18 15:45:48 2016 -0600

    node_set_atts(): Call rsvg_parse_style_attrs() here, not in every node implementation
    
    This shrinks the ::set_atts() methods by a good bit, and only leaves
    element-specific attributes in those methods.  The general "class" and
    "id" attributes are dealt with here.

 rsvg-base.c         |   36 +++++++++++++++++++++++++++---------
 rsvg-filter.c       |    7 +------
 rsvg-image.c        |    8 +-------
 rsvg-marker.c       |    8 ++------
 rsvg-mask.c         |   19 +++----------------
 rsvg-paint-server.c |    2 --
 rsvg-shapes.c       |   51 ++++++---------------------------------------------
 rsvg-structure.c    |   34 ++--------------------------------
 rsvg-text.c         |   16 ----------------
 9 files changed, 42 insertions(+), 139 deletions(-)
---
diff --git a/rsvg-base.c b/rsvg-base.c
index 6f6979a..ae65311 100644
--- a/rsvg-base.c
+++ b/rsvg-base.c
@@ -239,14 +239,6 @@ free_element_name_stack (RsvgHandle *ctx)
     ctx->priv->element_name_stack = NULL;
 }
 
-static void
-node_set_atts (RsvgNode * node, RsvgHandle * ctx, RsvgPropertyBag * atts)
-{
-    if (rsvg_property_bag_size (atts) > 0) {
-        node->set_atts (node, ctx, atts);
-    }
-}
-
 typedef RsvgNode *(* CreateNodeFn) (const char *element_name);
 
 typedef struct {
@@ -384,6 +376,32 @@ get_node_creator_for_element_name (const char *name)
 }
 
 static void
+node_set_atts (RsvgNode * node, RsvgHandle * ctx, const NodeCreator *creator, RsvgPropertyBag * atts)
+{
+    if (rsvg_property_bag_size (atts) > 0) {
+        const char *id;
+        const char *klazz;
+
+        node->set_atts (node, ctx, atts);
+
+        /* The "svg" node is special; it will load its id/class
+         * attributes until the end, when rsvg_end_element() calls
+         * _rsvg_node_svg_apply_atts()
+         */
+        if (RSVG_NODE_TYPE (node) != RSVG_NODE_TYPE_SVG) {
+            id = rsvg_property_bag_lookup (atts, "id");
+
+            if (creator->supports_class_attribute)
+                klazz = rsvg_property_bag_lookup (atts, "class");
+            else
+                klazz = NULL;
+
+            rsvg_parse_style_attrs (ctx, node->state, creator->element_name, klazz, id, atts);
+        }
+    }
+}
+
+static void
 rsvg_standard_element_start (RsvgHandle * ctx, const char *name, RsvgPropertyBag * atts)
 {
     /*replace this stuff with a hash for fast reading! */
@@ -403,7 +421,7 @@ rsvg_standard_element_start (RsvgHandle * ctx, const char *name, RsvgPropertyBag
 
         add_node_to_handle (ctx, newnode);
         register_node_in_defs (ctx, newnode, atts);
-        node_set_atts (newnode, ctx, atts);
+        node_set_atts (newnode, ctx, creator, atts);
 
         if (ctx->priv->currentnode) {
             rsvg_node_group_pack (ctx->priv->currentnode, newnode);
diff --git a/rsvg-filter.c b/rsvg-filter.c
index 6fed120..4ba66d3 100644
--- a/rsvg-filter.c
+++ b/rsvg-filter.c
@@ -3168,18 +3168,13 @@ rsvg_filter_primitive_flood_render (RsvgFilterPrimitive * self, RsvgFilterContex
 static void
 rsvg_filter_primitive_flood_set_atts (RsvgNode * self, RsvgHandle * ctx, RsvgPropertyBag * atts)
 {
-    const char *value, *id = NULL;
     RsvgFilterPrimitive *filter = (RsvgFilterPrimitive *) self;
+    const char *value;
 
     if ((value = rsvg_property_bag_lookup (atts, "result")))
         g_string_assign (filter->result, value);
 
     filter_primitive_set_x_y_width_height_atts ((RsvgFilterPrimitive *) filter, atts);
-        
-    if ((value = rsvg_property_bag_lookup (atts, "id")))
-        id = value;
-
-    rsvg_parse_style_attrs (ctx, self->state, "feFlood", NULL, id, atts);
 }
 
 RsvgNode *
diff --git a/rsvg-image.c b/rsvg-image.c
index d76dd4e..2692a6b 100644
--- a/rsvg-image.c
+++ b/rsvg-image.c
@@ -198,8 +198,8 @@ rsvg_node_image_draw (RsvgNode * self, RsvgDrawingCtx * ctx, int dominate)
 static void
 rsvg_node_image_set_atts (RsvgNode * self, RsvgHandle * ctx, RsvgPropertyBag * atts)
 {
-    const char *klazz = NULL, *id = NULL, *value;
     RsvgNodeImage *image = (RsvgNodeImage *) self;
+    const char *value;
 
     if ((value = rsvg_property_bag_lookup (atts, "x")))
         image->x = rsvg_length_parse (value, LENGTH_DIR_HORIZONTAL);
@@ -222,15 +222,9 @@ rsvg_node_image_set_atts (RsvgNode * self, RsvgHandle * ctx, RsvgPropertyBag * a
 #endif
         }
     }
-    if ((value = rsvg_property_bag_lookup (atts, "class")))
-        klazz = value;
-    if ((value = rsvg_property_bag_lookup (atts, "id")))
-        id = value;
 
     if ((value = rsvg_property_bag_lookup (atts, "preserveAspectRatio")))
         image->preserve_aspect_ratio = rsvg_css_parse_aspect_ratio (value);
-
-    rsvg_parse_style_attrs (ctx, image->super.state, "image", klazz, id, atts);
 }
 
 RsvgNode *
diff --git a/rsvg-marker.c b/rsvg-marker.c
index 3116258..01dc507 100644
--- a/rsvg-marker.c
+++ b/rsvg-marker.c
@@ -55,14 +55,11 @@ struct _RsvgMarker {
 static void
 rsvg_node_marker_set_atts (RsvgNode * self, RsvgHandle * ctx, RsvgPropertyBag * atts)
 {
-    const char *klazz = NULL, *id = NULL, *value;
     RsvgMarker *marker;
+    const char *value;
+
     marker = (RsvgMarker *) self;
 
-    if ((value = rsvg_property_bag_lookup (atts, "id")))
-        id = value;
-    if ((value = rsvg_property_bag_lookup (atts, "class")))
-        klazz = value;
     if ((value = rsvg_property_bag_lookup (atts, "viewBox")))
         marker->vbox = rsvg_css_parse_vbox (value);
     if ((value = rsvg_property_bag_lookup (atts, "refX")))
@@ -87,7 +84,6 @@ rsvg_node_marker_set_atts (RsvgNode * self, RsvgHandle * ctx, RsvgPropertyBag *
     }
     if ((value = rsvg_property_bag_lookup (atts, "preserveAspectRatio")))
         marker->preserve_aspect_ratio = rsvg_css_parse_aspect_ratio (value);
-    rsvg_parse_style_attrs (ctx, self->state, "marker", klazz, id, atts);
 }
 
 RsvgNode *
diff --git a/rsvg-mask.c b/rsvg-mask.c
index 30ec090..d145cd6 100644
--- a/rsvg-mask.c
+++ b/rsvg-mask.c
@@ -32,8 +32,9 @@
 static void
 rsvg_mask_set_atts (RsvgNode * self, RsvgHandle * ctx, RsvgPropertyBag * atts)
 {
-    const char *id = NULL, *klazz = NULL, *value;
     RsvgMask *mask;
+    const char *value;
+
     mask = (RsvgMask *) self;
 
     if ((value = rsvg_property_bag_lookup (atts, "maskUnits"))) {
@@ -56,13 +57,6 @@ rsvg_mask_set_atts (RsvgNode * self, RsvgHandle * ctx, RsvgPropertyBag * atts)
         mask->width = rsvg_length_parse (value, LENGTH_DIR_HORIZONTAL);
     if ((value = rsvg_property_bag_lookup (atts, "height")))
         mask->height = rsvg_length_parse (value, LENGTH_DIR_VERTICAL);
-    if ((value = rsvg_property_bag_lookup (atts, "id")))
-        id = value;
-
-    if ((value = rsvg_property_bag_lookup (atts, "class")))
-        klazz = value;
-
-    rsvg_parse_style_attrs (ctx, mask->super.state, "mask", klazz, id, atts);
 }
 
 RsvgNode *
@@ -102,8 +96,8 @@ rsvg_get_url_string (const char *str)
 static void
 rsvg_clip_path_set_atts (RsvgNode * self, RsvgHandle * ctx, RsvgPropertyBag * atts)
 {
-    const char *id = NULL, *klazz = NULL, *value = NULL;
     RsvgClipPath *clip_path;
+    const char *value;
 
     clip_path = (RsvgClipPath *) self;
 
@@ -113,13 +107,6 @@ rsvg_clip_path_set_atts (RsvgNode * self, RsvgHandle * ctx, RsvgPropertyBag * at
         else
             clip_path->units = userSpaceOnUse;
     }
-    if ((value = rsvg_property_bag_lookup (atts, "id")))
-        id = value;
-
-    if ((value = rsvg_property_bag_lookup (atts, "class")))
-        klazz = value;
-
-    rsvg_parse_style_attrs (ctx, clip_path->super.state, "clipPath", klazz, id, atts);
 }
 
 RsvgNode *
diff --git a/rsvg-paint-server.c b/rsvg-paint-server.c
index 289bfe9..d956170 100644
--- a/rsvg-paint-server.c
+++ b/rsvg-paint-server.c
@@ -280,7 +280,6 @@ rsvg_linear_gradient_set_atts (RsvgNode * self, RsvgHandle * ctx, RsvgPropertyBa
             grad->obj_bbox = TRUE;
         grad->hasbbox = TRUE;
     }
-    rsvg_parse_style_attrs (ctx, self->state, "linearGradient", NULL, NULL, atts);
 }
 
 static void
@@ -363,7 +362,6 @@ rsvg_radial_gradient_set_atts (RsvgNode * self, RsvgHandle * ctx, RsvgPropertyBa
             grad->obj_bbox = TRUE;
         grad->hasbbox = TRUE;
     }
-    rsvg_parse_style_attrs (ctx, self->state, "radialGradient", NULL, NULL, atts);
 }
 
 static void
diff --git a/rsvg-shapes.c b/rsvg-shapes.c
index 74b4b6c..4419cf0 100644
--- a/rsvg-shapes.c
+++ b/rsvg-shapes.c
@@ -73,20 +73,14 @@ rsvg_node_path_draw (RsvgNode * self, RsvgDrawingCtx * ctx, int dominate)
 static void
 rsvg_node_path_set_atts (RsvgNode * self, RsvgHandle * ctx, RsvgPropertyBag * atts)
 {
-    const char *klazz = NULL, *id = NULL, *value;
     RsvgNodePath *path = (RsvgNodePath *) self;
+    const char *value;
 
     if ((value = rsvg_property_bag_lookup (atts, "d"))) {
         if (path->builder)
             rsvg_path_builder_destroy (path->builder);
         path->builder = rsvg_path_parser_from_str_into_builder (value);
     }
-    if ((value = rsvg_property_bag_lookup (atts, "class")))
-        klazz = value;
-    if ((value = rsvg_property_bag_lookup (atts, "id")))
-        id = value;
-
-    rsvg_parse_style_attrs (ctx, self->state, "path", klazz, id, atts);
 }
 
 RsvgNode *
@@ -118,7 +112,7 @@ static void
 _rsvg_node_poly_set_atts (RsvgNode * self, RsvgHandle * ctx, RsvgPropertyBag * atts)
 {
     RsvgNodePoly *poly = (RsvgNodePoly *) self;
-    const char *klazz = NULL, *id = NULL, *value;
+    const char *value;
 
     /* support for svg < 1.0 which used verts */
     if ((value = rsvg_property_bag_lookup (atts, "verts"))
@@ -128,15 +122,6 @@ _rsvg_node_poly_set_atts (RsvgNode * self, RsvgHandle * ctx, RsvgPropertyBag * a
         poly->builder = _rsvg_node_poly_create_builder (value,
                                                         RSVG_NODE_TYPE (self) == RSVG_NODE_TYPE_POLYGON);
     }
-    if ((value = rsvg_property_bag_lookup (atts, "class")))
-        klazz = value;
-    if ((value = rsvg_property_bag_lookup (atts, "id")))
-        id = value;
-
-    rsvg_parse_style_attrs (ctx, self->state,
-                            RSVG_NODE_TYPE (self) == RSVG_NODE_TYPE_POLYLINE ? "polyline" : "polygon",
-                            klazz, id, atts);
-
 }
 
 static RsvgPathBuilder *
@@ -244,8 +229,8 @@ typedef struct _RsvgNodeLine RsvgNodeLine;
 static void
 _rsvg_node_line_set_atts (RsvgNode * self, RsvgHandle * ctx, RsvgPropertyBag * atts)
 {
-    const char *klazz = NULL, *id = NULL, *value;
     RsvgNodeLine *line = (RsvgNodeLine *) self;
+    const char *value;
 
     if ((value = rsvg_property_bag_lookup (atts, "x1")))
         line->x1 = rsvg_length_parse (value, LENGTH_DIR_HORIZONTAL);
@@ -255,12 +240,6 @@ _rsvg_node_line_set_atts (RsvgNode * self, RsvgHandle * ctx, RsvgPropertyBag * a
         line->x2 = rsvg_length_parse (value, LENGTH_DIR_HORIZONTAL);
     if ((value = rsvg_property_bag_lookup (atts, "y2")))
         line->y2 = rsvg_length_parse (value, LENGTH_DIR_VERTICAL);
-    if ((value = rsvg_property_bag_lookup (atts, "class")))
-        klazz = value;
-    if ((value = rsvg_property_bag_lookup (atts, "id")))
-        id = value;
-
-    rsvg_parse_style_attrs (ctx, self->state, "line", klazz, id, atts);
 }
 
 static void
@@ -310,8 +289,8 @@ typedef struct _RsvgNodeRect RsvgNodeRect;
 static void
 _rsvg_node_rect_set_atts (RsvgNode * self, RsvgHandle * ctx, RsvgPropertyBag * atts)
 {
-    const char *klazz = NULL, *id = NULL, *value;
     RsvgNodeRect *rect = (RsvgNodeRect *) self;
+    const char *value;
 
     /* FIXME: negative w/h/rx/ry is an error, per http://www.w3.org/TR/SVG11/shapes.html#RectElement */
     if ((value = rsvg_property_bag_lookup (atts, "x")))
@@ -330,12 +309,6 @@ _rsvg_node_rect_set_atts (RsvgNode * self, RsvgHandle * ctx, RsvgPropertyBag * a
         rect->ry = rsvg_length_parse (value, LENGTH_DIR_VERTICAL);
         rect->got_ry = TRUE;
     }
-    if ((value = rsvg_property_bag_lookup (atts, "class")))
-        klazz = value;
-    if ((value = rsvg_property_bag_lookup (atts, "id")))
-        id = value;
-
-    rsvg_parse_style_attrs (ctx, self->state, "rect", klazz, id, atts);
 }
 
 static void
@@ -500,8 +473,8 @@ typedef struct _RsvgNodeCircle RsvgNodeCircle;
 static void
 _rsvg_node_circle_set_atts (RsvgNode * self, RsvgHandle * ctx, RsvgPropertyBag * atts)
 {
-    const char *klazz = NULL, *id = NULL, *value;
     RsvgNodeCircle *circle = (RsvgNodeCircle *) self;
+    const char *value;
 
     if ((value = rsvg_property_bag_lookup (atts, "cx")))
         circle->cx = rsvg_length_parse (value, LENGTH_DIR_HORIZONTAL);
@@ -509,12 +482,6 @@ _rsvg_node_circle_set_atts (RsvgNode * self, RsvgHandle * ctx, RsvgPropertyBag *
         circle->cy = rsvg_length_parse (value, LENGTH_DIR_VERTICAL);
     if ((value = rsvg_property_bag_lookup (atts, "r")))
         circle->r = rsvg_length_parse (value, LENGTH_DIR_BOTH);
-    if ((value = rsvg_property_bag_lookup (atts, "class")))
-        klazz = value;
-    if ((value = rsvg_property_bag_lookup (atts, "id")))
-        id = value;
-
-    rsvg_parse_style_attrs (ctx, self->state, "circle", klazz, id, atts);
 }
 
 static void
@@ -588,8 +555,8 @@ typedef struct _RsvgNodeEllipse RsvgNodeEllipse;
 static void
 _rsvg_node_ellipse_set_atts (RsvgNode * self, RsvgHandle * ctx, RsvgPropertyBag * atts)
 {
-    const char *klazz = NULL, *id = NULL, *value;
     RsvgNodeEllipse *ellipse = (RsvgNodeEllipse *) self;
+    const char *value;
 
     if ((value = rsvg_property_bag_lookup (atts, "cx")))
         ellipse->cx = rsvg_length_parse (value, LENGTH_DIR_HORIZONTAL);
@@ -599,12 +566,6 @@ _rsvg_node_ellipse_set_atts (RsvgNode * self, RsvgHandle * ctx, RsvgPropertyBag
         ellipse->rx = rsvg_length_parse (value, LENGTH_DIR_HORIZONTAL);
     if ((value = rsvg_property_bag_lookup (atts, "ry")))
         ellipse->ry = rsvg_length_parse (value, LENGTH_DIR_VERTICAL);
-    if ((value = rsvg_property_bag_lookup (atts, "class")))
-        klazz = value;
-    if ((value = rsvg_property_bag_lookup (atts, "id")))
-        id = value;
-
-    rsvg_parse_style_attrs (ctx, self->state, "ellipse", klazz, id, atts);
 }
 
 static void
diff --git a/rsvg-structure.c b/rsvg-structure.c
index 475eb7e..fcf020a 100644
--- a/rsvg-structure.c
+++ b/rsvg-structure.c
@@ -118,19 +118,6 @@ _rsvg_node_free (RsvgNode * self)
     g_free (self);
 }
 
-static void
-rsvg_node_group_set_atts (RsvgNode * self, RsvgHandle * ctx, RsvgPropertyBag * atts)
-{
-    const char *klazz = NULL, *id = NULL, *value;
-
-    if ((value = rsvg_property_bag_lookup (atts, "class")))
-        klazz = value;
-    if ((value = rsvg_property_bag_lookup (atts, "id")))
-        id = value;
-
-    rsvg_parse_style_attrs (ctx, self->state, "g", klazz, id, atts);
-}
-
 RsvgNode *
 rsvg_new_group (const char *element_name)
 {
@@ -138,7 +125,6 @@ rsvg_new_group (const char *element_name)
     group = g_new (RsvgNodeGroup, 1);
     _rsvg_node_init (&group->super, RSVG_NODE_TYPE_GROUP);
     group->super.draw = _rsvg_node_draw_children;
-    group->super.set_atts = rsvg_node_group_set_atts;
     return &group->super;
 }
 
@@ -391,8 +377,8 @@ rsvg_node_use_free (RsvgNode * node)
 static void
 rsvg_node_use_set_atts (RsvgNode * self, RsvgHandle * ctx, RsvgPropertyBag * atts)
 {
-    const char *value = NULL, *klazz = NULL, *id = NULL;
     RsvgNodeUse *use;
+    const char *value;
 
     use = (RsvgNodeUse *) self;
 
@@ -404,17 +390,11 @@ rsvg_node_use_set_atts (RsvgNode * self, RsvgHandle * ctx, RsvgPropertyBag * att
         use->w = rsvg_length_parse (value, LENGTH_DIR_HORIZONTAL);
     if ((value = rsvg_property_bag_lookup (atts, "height")))
         use->h = rsvg_length_parse (value, LENGTH_DIR_VERTICAL);
-    if ((value = rsvg_property_bag_lookup (atts, "class")))
-        klazz = value;
-    if ((value = rsvg_property_bag_lookup (atts, "id")))
-        id = value;
 
     if ((value = rsvg_property_bag_lookup (atts, "xlink:href"))) {
         g_free (use->link);
         use->link = g_strdup (value);
     }
-    rsvg_parse_style_attrs (ctx, self->state, "use", klazz, id, atts);
-
 }
 
 RsvgNode *
@@ -438,20 +418,12 @@ static void
 rsvg_node_symbol_set_atts (RsvgNode * self, RsvgHandle * ctx, RsvgPropertyBag * atts)
 {
     RsvgNodeSymbol *symbol = (RsvgNodeSymbol *) self;
-
-    const char *klazz = NULL, *value, *id = NULL;
-
-    if ((value = rsvg_property_bag_lookup (atts, "class")))
-        klazz = value;
-    if ((value = rsvg_property_bag_lookup (atts, "id")))
-        id = value;
+    const char *value;
 
     if ((value = rsvg_property_bag_lookup (atts, "viewBox")))
         symbol->vbox = rsvg_css_parse_vbox (value);
     if ((value = rsvg_property_bag_lookup (atts, "preserveAspectRatio")))
         symbol->preserve_aspect_ratio = rsvg_css_parse_aspect_ratio (value);
-
-    rsvg_parse_style_attrs (ctx, self->state, "symbol", klazz, id, atts);
 }
 
 
@@ -475,7 +447,6 @@ rsvg_new_defs (const char *element_name)
     group = g_new (RsvgNodeGroup, 1);
     _rsvg_node_init (&group->super, RSVG_NODE_TYPE_DEFS);
     group->super.draw = _rsvg_node_draw_nothing;
-    group->super.set_atts = rsvg_node_group_set_atts;
     return &group->super;
 }
 
@@ -510,6 +481,5 @@ rsvg_new_switch (const char *element_name)
     group = g_new (RsvgNodeGroup, 1);
     _rsvg_node_init (&group->super, RSVG_NODE_TYPE_SWITCH);
     group->super.draw = _rsvg_node_switch_draw;
-    group->super.set_atts = rsvg_node_group_set_atts;
     return &group->super;
 }
diff --git a/rsvg-text.c b/rsvg-text.c
index f7bd7b6..7d8a98d 100644
--- a/rsvg-text.c
+++ b/rsvg-text.c
@@ -148,17 +148,9 @@ set_text_common_atts (RsvgNodeText *text, RsvgPropertyBag * atts)
 static void
 _rsvg_node_text_set_atts (RsvgNode * self, RsvgHandle * ctx, RsvgPropertyBag * atts)
 {
-    const char *klazz = NULL, *id = NULL, *value;
     RsvgNodeText *text = (RsvgNodeText *) self;
 
     set_text_common_atts (text, atts);
-
-    if ((value = rsvg_property_bag_lookup (atts, "class")))
-        klazz = value;
-    if ((value = rsvg_property_bag_lookup (atts, "id")))
-        id = value;
-
-    rsvg_parse_style_attrs (ctx, self->state, "text", klazz, id, atts);
 }
 
 static void
@@ -388,17 +380,9 @@ _rsvg_node_text_length_tspan (RsvgNodeText * self,
 static void
 _rsvg_node_tspan_set_atts (RsvgNode * self, RsvgHandle * ctx, RsvgPropertyBag * atts)
 {
-    const char *klazz = NULL, *id = NULL, *value;
     RsvgNodeText *text = (RsvgNodeText *) self;
 
     set_text_common_atts (text, atts);
-
-    if ((value = rsvg_property_bag_lookup (atts, "class")))
-        klazz = value;
-    if ((value = rsvg_property_bag_lookup (atts, "id")))
-        id = value;
-
-    rsvg_parse_style_attrs (ctx, self->state, "tspan", klazz, id, atts);
 }
 
 RsvgNode *


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