[librsvg: 89/95] rsvg_processing_instruction(): Parse attributes with the PHF



commit 3b5ab6c21b3f2a7cfab6ba68dc11cddd851463ac
Author: Federico Mena Quintero <federico gnome org>
Date:   Wed Feb 21 18:07:15 2018 -0600

    rsvg_processing_instruction(): Parse attributes with the PHF

 rsvg-base.c | 71 ++++++++++++++++++++++++++++++++++++++++---------------------
 1 file changed, 47 insertions(+), 24 deletions(-)
---
diff --git a/rsvg-base.c b/rsvg-base.c
index 6445863b..77fc55b6 100644
--- a/rsvg-base.c
+++ b/rsvg-base.c
@@ -1066,36 +1066,59 @@ rsvg_processing_instruction (void *user_data, const xmlChar * target, const xmlC
         xml_atts = rsvg_css_parse_xml_attribute_string ((const char *) data);
 
         if (xml_atts) {
+            const char *alternate = NULL;
+            const char *type = NULL;
+            const char *href = NULL;
+            RsvgPropertyBagIter *iter;
+            const char *key;
+            RsvgAttribute attr;
             const char *value;
 
             atts = rsvg_property_bag_new ((const char **) xml_atts);
-            value = rsvg_property_bag_lookup (atts, "alternate");
-            if (!value || !value[0] || (strcmp (value, "no") != 0)) {
-                value = rsvg_property_bag_lookup (atts, "type");
-                if (value && strcmp (value, "text/css") == 0) {
-                    value = rsvg_property_bag_lookup (atts, "href");
-                    if (value && value[0]) {
-                        char *style_data;
-                        gsize style_data_len;
-                        char *mime_type = NULL;
-
-                        style_data = _rsvg_handle_acquire_data (handle,
-                                                                value,
-                                                                &mime_type,
-                                                                &style_data_len,
-                                                                NULL);
-                        if (style_data &&
-                            mime_type &&
-                            strcmp (mime_type, "text/css") == 0) {
-                            rsvg_parse_cssbuffer (handle, style_data, style_data_len);
-                        }
-
-                        g_free (mime_type);
-                        g_free (style_data);
-                    }
+
+            iter = rsvg_property_bag_iter_begin (atts);
+
+            while (rsvg_property_bag_iter_next (iter, &key, &attr, &value)) {
+                switch (attr) {
+                case RSVG_ATTRIBUTE_ALTERNATE:
+                    alternate = value;
+                    break;
+
+                case RSVG_ATTRIBUTE_TYPE:
+                    type = value;
+                    break;
+
+                case RSVG_ATTRIBUTE_HREF:
+                    href = value;
+                    break;
+
+                default:
+                    break;
                 }
             }
 
+            if ((!alternate || strcmp (alternate, "no") != 0)
+                && type && strcmp (type, "text/css") == 0
+                && href) {
+                char *style_data;
+                gsize style_data_len;
+                char *mime_type = NULL;
+
+                style_data = _rsvg_handle_acquire_data (handle,
+                                                        href,
+                                                        &mime_type,
+                                                        &style_data_len,
+                                                        NULL);
+                if (style_data &&
+                    mime_type &&
+                    strcmp (mime_type, "text/css") == 0) {
+                    rsvg_parse_cssbuffer (handle, style_data, style_data_len);
+                }
+
+                g_free (mime_type);
+                g_free (style_data);
+            }
+
             rsvg_property_bag_free (atts);
             g_strfreev (xml_atts);
         }


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