libgimpcolor: fix CSS parsing.

- "transparent" is now recognized. It was forgotten (probably because on the
  GimpRGB interface, we separated the API in a _rgb_ and a _rgba_ variant).
- rgba() and hsla() formats are now fixed (implementation was there but the
  function names were not recognized.
- Adding some comment about limitations of the hexadecimal notation (we don't
  support the alpha channel which is now in the CSS specs, while we also support
  some non-specified variant with every channel on 3 or 4 digits) for future
  work.
This commit is contained in:
Jehan 2024-04-20 02:58:14 +02:00
parent 685fe6c0c5
commit 9f205ca63e

View file

@ -233,7 +233,10 @@ gimp_color_parse_css (const gchar *css,
tmp = gimp_color_parse_strip (css, len);
color = gimp_color_parse_css_internal (tmp);
if (g_strcmp0 (tmp, "transparent") == 0)
color = gegl_color_new ("transparent");
else
color = gimp_color_parse_css_internal (tmp);
g_free (tmp);
@ -344,6 +347,14 @@ gimp_color_parse_hex_internal (const gchar *hex)
hex++;
len = strlen (hex);
/* TODO: current implementation has 2 issues:
* 1. It doesn't support the alpha channel, even though CSS spec now has
* support for it with either 8 or 4 digits.
* 2. The spec has nothing about channels on 3 or 4 digits, which we support
* here (for higher precision?). Is this format really supported somewhere?
* Do we want to keep this?
* See: https://drafts.csswg.org/css-color/#hex-notation
*/
if (len % 3 || len < 3 || len > 12)
return NULL;
@ -463,8 +474,10 @@ gimp_color_parse_css_internal (const gchar *css)
{
return gimp_color_parse_hex_internal (css);
}
else if (strncmp (css, "rgb(", 4) == 0 ||
strncmp (css, "hsl(", 4) == 0)
else if (strncmp (css, "rgb(", 4) == 0 ||
strncmp (css, "hsl(", 4) == 0 ||
strncmp (css, "rgba(", 5) == 0 ||
strncmp (css, "hsla(", 5) == 0)
{
return gimp_color_parse_css_numeric (css);
}