Right now, we pass through to Pango unrecognized hexadecimal formats
when parsing colors from strings. Since we parse all possible formats
ourselves, we can do validation ourselves as well, and avoid the Pango
path.
* parsing the color ourselves, as we need the alpha channel that
* Pango can't retrieve.
*/
* parsing the color ourselves, as we need the alpha channel that
* Pango can't retrieve.
*/
+ if (str[0] == '#' && str[1] != '\0')
+ gsize length = strlen (str + 1);
- if (sscanf (str + 1, "%x", &result))
+ if (sscanf (str + 1, "%x", &result) == 1)
- gsize length = strlen (str);
-
color->red = (result >> 24) & 0xff;
color->green = (result >> 16) & 0xff;
color->blue = (result >> 8) & 0xff;
color->red = (result >> 24) & 0xff;
color->green = (result >> 16) & 0xff;
color->blue = (result >> 8) & 0xff;
color->red = (result >> 16) & 0xff;
color->green = (result >> 8) & 0xff;
color->blue = result & 0xff;
color->red = (result >> 16) & 0xff;
color->green = (result >> 8) & 0xff;
color->blue = result & 0xff;
color->red = ((result >> 12) & 0xf);
color->green = ((result >> 8) & 0xf);
color->blue = ((result >> 4) & 0xf);
color->red = ((result >> 12) & 0xf);
color->green = ((result >> 8) & 0xf);
color->blue = ((result >> 4) & 0xf);
color->red = ((result >> 8) & 0xf);
color->green = ((result >> 4) & 0xf);
color->blue = result & 0xf;
color->red = ((result >> 8) & 0xf);
color->green = ((result >> 4) & 0xf);
color->blue = result & 0xf;
- /* pass through to Pango */
- break;
- /* Fall back to pango for named colors */
+ /* fall back to pango for X11-style named colors; see:
+ *
+ * http://en.wikipedia.org/wiki/X11_color_names
+ *
+ * for a list. at some point we might even ship with our own list generated
+ * from X11/rgb.txt, like we generate the key symbols.
+ */
if (pango_color_parse (&pango_color, str))
{
color->red = pango_color.red;
if (pango_color_parse (&pango_color, str))
{
color->red = pango_color.red;