From 8e16babeaa4cad74ac7142e971223052cfaaa5dd Mon Sep 17 00:00:00 2001 From: John Mark Bell Date: Sun, 18 Apr 2004 21:10:02 +0000 Subject: [project @ 2004-04-18 21:10:02 by jmb] Work around the lack of a '#' at the start of a colour specified in #rrggbb format svn path=/import/netsurf/; revision=793 --- css/ruleset.c | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) (limited to 'css') diff --git a/css/ruleset.c b/css/ruleset.c index 381e1fea3..d898dbcab 100644 --- a/css/ruleset.c +++ b/css/ruleset.c @@ -367,11 +367,23 @@ int parse_length(struct css_length * const length, colour named_colour(const char *name) { struct colour_entry *col; + unsigned int r, g, b; + col = bsearch(name, colour_table, sizeof(colour_table) / sizeof(colour_table[0]), sizeof(colour_table[0]), (void*)strcasecmp); - if (col == 0) - return TRANSPARENT; + if (col == 0) { + /* A common error is the omission of the '#' from the + * start of a colour specified in #rrggbb format. + * This attempts to detect and recover from this. + */ + if (strlen(name) == 6 && + sscanf(name, "%2x%2x%2x", &r, &g, &b) == 3) { + return (b << 16) | (g << 8) | r; + } + else + return TRANSPARENT; + } return col->col; } -- cgit v1.2.3