summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorMichael Drake <tlsa@netsurf-browser.org>2010-12-05 00:05:01 +0000
committerMichael Drake <tlsa@netsurf-browser.org>2010-12-05 00:05:01 +0000
commitd810646b94eab2f00592bb4476b8f32937f7c2c5 (patch)
treee8a89840042821c3828d072be04b07c15a200321 /src
parent5ad2047d9280f16510e15782df76256e52b31e68 (diff)
downloadlibcss-d810646b94eab2f00592bb4476b8f32937f7c2c5.tar.gz
libcss-d810646b94eab2f00592bb4476b8f32937f7c2c5.tar.bz2
Add support for rgba() colours. Thanks jmb.
svn path=/trunk/libcss/; revision=10993
Diffstat (limited to 'src')
-rw-r--r--src/parse/properties/utils.c49
-rw-r--r--src/parse/propstrings.c1
-rw-r--r--src/parse/propstrings.h3
3 files changed, 42 insertions, 11 deletions
diff --git a/src/parse/properties/utils.c b/src/parse/properties/utils.c
index 7d0da45..c1c8b16 100644
--- a/src/parse/properties/utils.c
+++ b/src/parse/properties/utils.c
@@ -39,6 +39,7 @@ css_error parse_colour_specifier(css_language *c,
/* IDENT(<colour name>) | HASH(rgb | rrggbb) |
* FUNCTION(rgb) [ [ NUMBER | PERCENTAGE ] ',' ] {3} ')'
+ * FUNCTION(rgba) [ [ NUMBER | PERCENTAGE ] ',' ] {4} ')'
*
* For quirks, NUMBER | DIMENSION | IDENT, too
* I.E. "123456" -> NUMBER, "1234f0" -> DIMENSION, "f00000" -> IDENT
@@ -91,18 +92,31 @@ css_error parse_colour_specifier(css_language *c,
return error;
} else if (token->type == CSS_TOKEN_FUNCTION) {
+ int colour_channels = 0;
+
if ((lwc_string_caseless_isequal(
token->idata, c->strings[RGB],
&match) == lwc_error_ok && match)) {
+ colour_channels = 3;
+ } else if ((lwc_string_caseless_isequal(
+ token->idata, c->strings[RGBA],
+ &match) == lwc_error_ok && match)) {
+ colour_channels = 4;
+ }
+
+ if (colour_channels == 3 || colour_channels == 4) {
int i;
css_token_type valid = CSS_TOKEN_NUMBER;
+ uint8_t *components[4] = { &r, &g, &b, &a };
- for (i = 0; i < 3; i++) {
+ for (i = 0; i < colour_channels; i++) {
+ uint8_t *component;
css_fixed num;
size_t consumed = 0;
- uint8_t *component = i == 0 ? &r
- : i == 1 ? &g : &b;
int32_t intval;
+ bool int_only;
+
+ component = components[i];
consumeWhitespace(vector, ctx);
@@ -115,17 +129,29 @@ css_error parse_colour_specifier(css_language *c,
if (i == 0)
valid = token->type;
- else if (token->type != valid)
+ else if (i < 3 && token->type != valid)
goto invalid;
+ /* The alpha channel may be a float */
+ if (i < 3)
+ int_only = (valid == CSS_TOKEN_NUMBER);
+ else
+ int_only = false;
+
num = number_from_lwc_string(token->idata,
- valid == CSS_TOKEN_NUMBER,
- &consumed);
+ int_only, &consumed);
if (consumed != lwc_string_length(token->idata))
goto invalid;
if (valid == CSS_TOKEN_NUMBER) {
- intval = FIXTOINT(num);
+ if (i == 3) {
+ /* alpha channel */
+ intval = FIXTOINT(
+ FMULI(num, 255));
+ } else {
+ /* colour channels */
+ intval = FIXTOINT(num);
+ }
} else {
intval = FIXTOINT(
FDIVI(FMULI(num, 255), 100));
@@ -146,12 +172,15 @@ css_error parse_colour_specifier(css_language *c,
if (token == NULL)
goto invalid;
- if (i != 2 && tokenIsChar(token, ','))
+ if (i != (colour_channels - 1) &&
+ tokenIsChar(token, ',')) {
parserutils_vector_iterate(vector, ctx);
- else if (i == 2 && tokenIsChar(token, ')'))
+ } else if (i == (colour_channels - 1) &&
+ tokenIsChar(token, ')')) {
parserutils_vector_iterate(vector, ctx);
- else
+ } else {
goto invalid;
+ }
}
} else
goto invalid;
diff --git a/src/parse/propstrings.c b/src/parse/propstrings.c
index 699b750..ef71235 100644
--- a/src/parse/propstrings.c
+++ b/src/parse/propstrings.c
@@ -330,6 +330,7 @@ const stringmap_entry stringmap[LAST_KNOWN] = {
{ "line-through", SLEN("line-through") },
{ "blink", SLEN("blink") },
{ "rgb", SLEN("rgb") },
+ { "rgba", SLEN("rgba") },
{ "-libcss-left", SLEN("-libcss-left") },
{ "-libcss-center", SLEN("-libcss-center") },
{ "-libcss-right", SLEN("-libcss-right") },
diff --git a/src/parse/propstrings.h b/src/parse/propstrings.h
index f33fe78..ea16b44 100644
--- a/src/parse/propstrings.h
+++ b/src/parse/propstrings.h
@@ -84,7 +84,8 @@ enum {
NE_RESIZE, NW_RESIZE, N_RESIZE, SE_RESIZE, SW_RESIZE, S_RESIZE,
W_RESIZE, TEXT, WAIT, HELP, PROGRESS, SERIF, SANS_SERIF, CURSIVE,
FANTASY, MONOSPACE, MALE, FEMALE, CHILD, MIX, UNDERLINE, OVERLINE,
- LINE_THROUGH, BLINK, RGB, LIBCSS_LEFT, LIBCSS_CENTER, LIBCSS_RIGHT,
+ LINE_THROUGH, BLINK, RGB, RGBA, LIBCSS_LEFT, LIBCSS_CENTER,
+ LIBCSS_RIGHT,
/* Named colours */
FIRST_COLOUR,