[librsvg: 78/95] rsvg_node_component_transfer_function_set_atts(): Parse attributes with the PHF



commit 45c7d43847619980cdf55802f895be8c9154725b
Author: Federico Mena Quintero <federico gnome org>
Date:   Wed Feb 21 17:06:22 2018 -0600

    rsvg_node_component_transfer_function_set_atts(): Parse attributes with the PHF

 rsvg-filter.c | 103 +++++++++++++++++++++++++++++++++++-----------------------
 1 file changed, 62 insertions(+), 41 deletions(-)
---
diff --git a/rsvg-filter.c b/rsvg-filter.c
index 96a8240b..9e44b742 100644
--- a/rsvg-filter.c
+++ b/rsvg-filter.c
@@ -2984,53 +2984,74 @@ static void
 rsvg_node_component_transfer_function_set_atts (RsvgNode *node, gpointer impl, RsvgHandle *handle, 
RsvgPropertyBag atts)
 {
     RsvgNodeComponentTransferFunc *data = impl;
+    RsvgPropertyBagIter *iter;
+    const char *key;
+    RsvgAttribute attr;
     const char *value;
 
-    if ((value = rsvg_property_bag_lookup (atts, "type"))) {
-        if (!strcmp (value, "identity"))
-            data->function = identity_component_transfer_func;
-        else if (!strcmp (value, "table"))
-            data->function = table_component_transfer_func;
-        else if (!strcmp (value, "discrete"))
-            data->function = discrete_component_transfer_func;
-        else if (!strcmp (value, "linear"))
-            data->function = linear_component_transfer_func;
-        else if (!strcmp (value, "gamma"))
-            data->function = gamma_component_transfer_func;
-    }
+    iter = rsvg_property_bag_iter_begin (atts);
 
-    if ((value = rsvg_property_bag_lookup (atts, "tableValues"))) {
-        unsigned int i;
-        double *temp;
-        if (!rsvg_css_parse_number_list (value,
-                                         NUMBER_LIST_LENGTH_MAXIMUM,
-                                         256,
-                                         &temp,
-                                         &data->nbTableValues)) {
-            rsvg_node_set_attribute_parse_error (node, "tableValues", "invalid number list");
-            return;
+    while (rsvg_property_bag_iter_next (iter, &key, &attr, &value)) {
+        switch (attr) {
+        case RSVG_ATTRIBUTE_TYPE:
+            if (!strcmp (value, "identity"))
+                data->function = identity_component_transfer_func;
+            else if (!strcmp (value, "table"))
+                data->function = table_component_transfer_func;
+            else if (!strcmp (value, "discrete"))
+                data->function = discrete_component_transfer_func;
+            else if (!strcmp (value, "linear"))
+                data->function = linear_component_transfer_func;
+            else if (!strcmp (value, "gamma"))
+                data->function = gamma_component_transfer_func;
+            break;
+
+        case RSVG_ATTRIBUTE_TABLE_VALUES: {
+            unsigned int i;
+            double *temp;
+            if (!rsvg_css_parse_number_list (value,
+                                             NUMBER_LIST_LENGTH_MAXIMUM,
+                                             256,
+                                             &temp,
+                                             &data->nbTableValues)) {
+                rsvg_node_set_attribute_parse_error (node, "tableValues", "invalid number list");
+                goto out;
+            }
+
+            data->tableValues = g_new0 (gint, data->nbTableValues);
+            for (i = 0; i < data->nbTableValues; i++)
+                data->tableValues[i] = temp[i] * 255.;
+            g_free (temp);
+            break;
         }
 
-        data->tableValues = g_new0 (gint, data->nbTableValues);
-        for (i = 0; i < data->nbTableValues; i++)
-            data->tableValues[i] = temp[i] * 255.;
-        g_free (temp);
-    }
-    if ((value = rsvg_property_bag_lookup (atts, "slope"))) {
-        data->slope = g_ascii_strtod (value, NULL) * 255.;
-    }
-    if ((value = rsvg_property_bag_lookup (atts, "intercept"))) {
-        data->intercept = g_ascii_strtod (value, NULL) * 255.;
-    }
-    if ((value = rsvg_property_bag_lookup (atts, "amplitude"))) {
-        data->amplitude = g_ascii_strtod (value, NULL) * 255.;
-    }
-    if ((value = rsvg_property_bag_lookup (atts, "exponent"))) {
-        data->exponent = g_ascii_strtod (value, NULL);
-    }
-    if ((value = rsvg_property_bag_lookup (atts, "offset"))) {
-        data->offset = g_ascii_strtod (value, NULL) * 255.;
+        case RSVG_ATTRIBUTE_SLOPE:
+            data->slope = g_ascii_strtod (value, NULL) * 255.;
+            break;
+
+        case RSVG_ATTRIBUTE_INTERCEPT:
+            data->intercept = g_ascii_strtod (value, NULL) * 255.;
+            break;
+
+        case RSVG_ATTRIBUTE_AMPLITUDE:
+            data->amplitude = g_ascii_strtod (value, NULL) * 255.;
+            break;
+
+        case RSVG_ATTRIBUTE_EXPONENT:
+            data->exponent = g_ascii_strtod (value, NULL);
+            break;
+
+        case RSVG_ATTRIBUTE_OFFSET:
+            data->offset = g_ascii_strtod (value, NULL) * 255.;
+            break;
+
+        default:
+            break;
+        }
     }
+
+out:
+    rsvg_property_bag_iter_end (iter);
 }
 
 static void


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