[gtk+/gtk-style-context: 354/490] GtkCssProvider: allow color names from rgb.txt when parsing colors.



commit 647c295bc866b3800c88725430ac4a12e135d074
Author: Carlos Garnacho <carlosg gnome org>
Date:   Fri Nov 12 22:59:21 2010 +0100

    GtkCssProvider: allow color names from rgb.txt when parsing colors.

 gtk/gtkcssprovider.c |   76 ++++++++++++++++++++++++++++---------------------
 1 files changed, 43 insertions(+), 33 deletions(-)
---
diff --git a/gtk/gtkcssprovider.c b/gtk/gtkcssprovider.c
index 26d598c..08157e9 100644
--- a/gtk/gtkcssprovider.c
+++ b/gtk/gtkcssprovider.c
@@ -1564,39 +1564,7 @@ symbolic_color_parse_str (const gchar  *string,
   str = (gchar *) string;
   *end_ptr = str;
 
-  if (str[0] == '#' || str[0] == 'r')
-    {
-      GdkRGBA color;
-      gchar *color_str;
-      const gchar *end;
-
-      end = str + 1;
-
-      if (str[0] == '#')
-        while (g_ascii_isxdigit (*end))
-          end++;
-      else
-        {
-          while (*end != ')' && *end != '\0')
-            end++;
-
-          if (*end == ')')
-            end++;
-        }
-
-      color_str = g_strndup (str, end - str);
-      *end_ptr = (gchar *) end;
-
-      if (!gdk_rgba_parse (color_str, &color))
-        {
-          g_free (color_str);
-          return NULL;
-        }
-
-      symbolic_color = gtk_symbolic_color_new_literal (&color);
-      g_free (color_str);
-    }
-  else if (str[0] == '@')
+  if (str[0] == '@')
     {
       const gchar *end;
       gchar *name;
@@ -1747,6 +1715,48 @@ symbolic_color_parse_str (const gchar  *string,
       gtk_symbolic_color_unref (color2);
       (*end_ptr)++;
     }
+  else
+    {
+      GdkRGBA color;
+      gchar *color_str;
+      const gchar *end;
+
+      end = str + 1;
+
+      if (str[0] == '#')
+        {
+          /* Color in hex format */
+          while (g_ascii_isxdigit (*end))
+            end++;
+        }
+      else if (g_str_has_prefix (str, "rgb"))
+        {
+          /* color in rgb/rgba format */
+          while (*end != ')' && *end != '\0')
+            end++;
+
+          if (*end == ')')
+            end++;
+        }
+      else
+        {
+          /* color name? parse until first whitespace */
+          while (*end != ' ' && *end != '\0')
+            end++;
+        }
+
+      color_str = g_strndup (str, end - str);
+      *end_ptr = (gchar *) end;
+
+      if (!gdk_rgba_parse (color_str, &color))
+        {
+          g_free (color_str);
+          return NULL;
+        }
+
+      symbolic_color = gtk_symbolic_color_new_literal (&color);
+      g_free (color_str);
+    }
 
   return symbolic_color;
 }



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