summaryrefslogtreecommitdiff
path: root/gtksourceview
diff options
context:
space:
mode:
authorPaolo Borelli <pborelli@gnome.org>2015-08-16 18:28:25 +0200
committerPaolo Borelli <pborelli@gnome.org>2015-08-16 18:29:51 +0200
commita622c34673f629a8281faf471397edcd6cd7baa6 (patch)
treed2108940ddb9adc5a0d26f0c17a308932cf82cdd /gtksourceview
parent5dd77428e3bf5295b95b73428ba9cda6b57f1450 (diff)
downloadgtksourceview-a622c34673f629a8281faf471397edcd6cd7baa6.tar.gz
Allow #rgba() colors in named colors
Fix bug https://bugzilla.gnome.org/show_bug.cgi?id=740910 and add a unit test
Diffstat (limited to 'gtksourceview')
-rw-r--r--gtksourceview/gtksourcestylescheme.c37
1 files changed, 27 insertions, 10 deletions
diff --git a/gtksourceview/gtksourcestylescheme.c b/gtksourceview/gtksourcestylescheme.c
index a40c68ea..544ed800 100644
--- a/gtksourceview/gtksourcestylescheme.c
+++ b/gtksourceview/gtksourcestylescheme.c
@@ -373,6 +373,29 @@ gtk_source_style_scheme_get_filename (GtkSourceStyleScheme *scheme)
}
/*
+ * Try to parse a color string.
+ * If the color can be parsed, return the offset in the string
+ * with the real start of the color (either the string itself, or after
+ * the initial '#' character).
+ */
+static const gchar *
+color_parse (const gchar *color,
+ GdkRGBA *rgba)
+{
+ if ((*color == '#') && gdk_rgba_parse (rgba, color + 1))
+ {
+ return color + 1;
+ }
+
+ if (gdk_rgba_parse (rgba, color))
+ {
+ return color;
+ }
+
+ return NULL;
+}
+
+/*
* get_color_by_name:
* @scheme: a #GtkSourceStyleScheme.
* @name: color name to find.
@@ -396,15 +419,9 @@ get_color_by_name (GtkSourceStyleScheme *scheme,
{
GdkRGBA dummy;
- if (gdk_rgba_parse (&dummy, name + 1))
- {
- color = name + 1;
- }
- else if (gdk_rgba_parse (&dummy, name))
- {
- color = name;
- }
- else
+ color = color_parse (name, &dummy);
+
+ if (color == NULL)
{
g_warning ("could not parse color '%s'", name);
}
@@ -582,7 +599,7 @@ get_color (GtkSourceStyle *style,
if (style->mask & mask)
{
- if (color == NULL || !gdk_rgba_parse (dest, color))
+ if (color == NULL || !color_parse (color, dest))
{
g_warning ("%s: invalid color '%s'", G_STRLOC,
color != NULL ? color : "(null)");