[librsvg] support !important directive in style attributes.



commit d81104d5e3a5d48774479111034709fbc8cf40d1
Author: Hiroyuki Ikezoe <poincare ikezoe net>
Date:   Fri Apr 30 19:15:03 2010 +0900

    support !important directive in style attributes.

 rsvg-styles.c                       |   20 +++++++++++++-------
 tests/fixtures/styles/important.svg |    1 +
 tests/styles.c                      |    1 +
 3 files changed, 15 insertions(+), 7 deletions(-)
---
diff --git a/rsvg-styles.c b/rsvg-styles.c
index 3b3cf92..c87cffd 100644
--- a/rsvg-styles.c
+++ b/rsvg-styles.c
@@ -864,20 +864,22 @@ rsvg_parse_style_pairs (RsvgHandle * ctx, RsvgState * state, RsvgPropertyBag * a
 }
 
 static gboolean
-is_important (const gchar *value)
+parse_style_value (const gchar *string, gchar **value, gboolean *important)
 {
     gchar **strings;
-    gboolean important = FALSE;
 
-    strings = g_strsplit (value, "!", 2);
+    strings = g_strsplit (string, "!", 2);
     if (g_strv_length (strings) == 2 &&
         g_str_equal (g_strstrip (strings[1]), "important")) {
-        important = TRUE;
+        *important = TRUE;
+    } else {
+        *important = FALSE;
     }
+    *value = g_strdup (g_strstrip (strings[0]));
 
     g_strfreev (strings);
 
-    return important;
+    return TRUE;
 }
 
 /* Split a CSS2 style into individual style arguments, setting attributes
@@ -900,10 +902,14 @@ rsvg_parse_style (RsvgHandle * ctx, RsvgState * state, const char *str)
             continue;
 
         if (g_strv_length (values)  == 2) {
+            gboolean important;
+            gchar *style_value = NULL;
+            parse_style_value (values[1], &style_value, &important);
             rsvg_parse_style_pair (ctx, state,
                                    g_strstrip (values[0]),
-                                   g_strstrip (values[1]),
-                                   is_important (values[1]));
+                                   style_value,
+                                   important);
+            g_free (style_value);
         }
         g_strfreev (values);
     }
diff --git a/tests/fixtures/styles/important.svg b/tests/fixtures/styles/important.svg
index 0259295..ce68c80 100644
--- a/tests/fixtures/styles/important.svg
+++ b/tests/fixtures/styles/important.svg
@@ -10,4 +10,5 @@ rect {fill: white !important;}
   <rect class="blue" id="red" x="0" y="0" width="10" height="10"/>
   <rect class="blue" id="blue" x="20" y="20" width="10" height="10"/>
   <rect id="white" fill="black !important" x="40" y="40" width="10" height="10"/>
+  <rect id="pink" style="fill: pink !important;" x="60" y="60" width="10" height="10"/>
 </svg>
diff --git a/tests/styles.c b/tests/styles.c
index 11ad5f2..d4a2aef 100644
--- a/tests/styles.c
+++ b/tests/styles.c
@@ -102,6 +102,7 @@ static const FixtureData fixtures[] =
     {"/styles/!important/#id prior than class", NULL, "styles/important.svg", "#red", "fill", .expected.color = 0xff0000 },
     {"/styles/!important/class prior than type", NULL, "styles/important.svg", "#blue", "fill", .expected.color = 0x0000ff },
     {"/styles/!important/presentation attribute is invalid", NULL, "styles/important.svg", "#white", "fill", .expected.color = 0xffffff },
+    {"/styles/!important/style prior than class", NULL, "styles/important.svg", "#pink", "fill", .expected.color = 0xffc0cb },
     {"/styles/selectors/descendant", "338160", "styles/bug338160.svg", "#base_shadow", "stroke-width", .expected.length = {2., '\0'}},
 };
 static const gint n_fixtures = G_N_ELEMENTS (fixtures);



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