color: Support the CSS hsl() notation
Since we support the rgb() and rgba() notations we might as well also support the hsl() one.
This commit is contained in:
@ -534,6 +534,69 @@ parse_rgba (ClutterColor *color,
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
static gboolean
|
||||
parse_hsl (ClutterColor *color,
|
||||
gchar *str)
|
||||
{
|
||||
gdouble number;
|
||||
gdouble h, l, s;
|
||||
|
||||
skip_whitespace (&str);
|
||||
|
||||
if (*str != '(')
|
||||
return FALSE;
|
||||
|
||||
str += 1;
|
||||
|
||||
/* hue */
|
||||
skip_whitespace (&str);
|
||||
/* we don't do any angle normalization here because
|
||||
* clutter_color_from_hls() will do it for us
|
||||
*/
|
||||
number = g_ascii_strtod (str, &str);
|
||||
skip_whitespace (&str);
|
||||
if (*str != ',')
|
||||
return FALSE;
|
||||
|
||||
h = number;
|
||||
|
||||
str += 1;
|
||||
|
||||
/* saturation */
|
||||
skip_whitespace (&str);
|
||||
number = g_ascii_strtod (str, &str);
|
||||
skip_whitespace (&str);
|
||||
if (*str != '%')
|
||||
return FALSE;
|
||||
|
||||
str += 1;
|
||||
|
||||
s = CLAMP (number / 100.0, 0.0, 1.0);
|
||||
skip_whitespace (&str);
|
||||
if (*str != ',')
|
||||
return FALSE;
|
||||
|
||||
str += 1;
|
||||
|
||||
/* luminance */
|
||||
skip_whitespace (&str);
|
||||
number = g_ascii_strtod (str, &str);
|
||||
skip_whitespace (&str);
|
||||
if (*str != '%')
|
||||
return FALSE;
|
||||
|
||||
str += 1;
|
||||
|
||||
l = CLAMP (number / 100.0, 0.0, 1.0);
|
||||
skip_whitespace (&str);
|
||||
if (*str != ')')
|
||||
return FALSE;
|
||||
|
||||
clutter_color_from_hls (color, h, l, s);
|
||||
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
/**
|
||||
* clutter_color_from_string:
|
||||
* @color: (out caller-allocates): return location for a #ClutterColor
|
||||
@ -595,6 +658,13 @@ clutter_color_from_string (ClutterColor *color,
|
||||
return res;
|
||||
}
|
||||
|
||||
if (strncmp (str, "hsl", 3) == 0)
|
||||
{
|
||||
gchar *s = (gchar *) str;
|
||||
|
||||
return parse_hsl (color, s + 3);
|
||||
}
|
||||
|
||||
/* if the string contains a color encoded using the hexadecimal
|
||||
* notations (#rrggbbaa or #rgba) we attempt a rough pass at
|
||||
* parsing the color ourselves, as we need the alpha channel that
|
||||
|
Reference in New Issue
Block a user