diff options
author | John Mark Bell <jmb@netsurf-browser.org> | 2009-01-12 09:55:29 +0000 |
---|---|---|
committer | John Mark Bell <jmb@netsurf-browser.org> | 2009-01-12 09:55:29 +0000 |
commit | ba3822abf4e7da6e41df81e7df3d1eda62c8f01b (patch) | |
tree | 943dd096078f618db893f9b649c39dd542535b5b /src | |
parent | f63a7e87fb73f540b7713fff1b20251896d8b16e (diff) | |
download | libcss-ba3822abf4e7da6e41df81e7df3d1eda62c8f01b.tar.gz libcss-ba3822abf4e7da6e41df81e7df3d1eda62c8f01b.tar.bz2 |
When parsing colours, it helps to remember that percentages aren't necessarily integers.
svn path=/trunk/libcss/; revision=6045
Diffstat (limited to 'src')
-rw-r--r-- | src/parse/properties.c | 30 |
1 files changed, 13 insertions, 17 deletions
diff --git a/src/parse/properties.c b/src/parse/properties.c index adf3aa7..34873cc 100644 --- a/src/parse/properties.c +++ b/src/parse/properties.c @@ -6431,6 +6431,7 @@ css_error parse_colour_specifier(css_language *c, size_t consumed = 0; uint8_t *component = i == 0 ? &r : i == 1 ? &b : &g; + int32_t intval; consumeWhitespace(vector, ctx); @@ -6449,30 +6450,25 @@ css_error parse_colour_specifier(css_language *c, tmp.len = token->idata->len; tmp.data = (uint8_t *) token->idata->data; num = number_from_css_string(&tmp, - true, &consumed); + valid == CSS_TOKEN_NUMBER, + &consumed); if (consumed != token->idata->len) return CSS_INVALID; if (valid == CSS_TOKEN_NUMBER) { - int32_t intval = FIXTOINT(num); - - if (intval > 255) - *component = 255; - else if (intval < 0) - *component = 0; - else - *component = intval; + intval = FIXTOINT(num); } else { - int32_t intval = FIXTOINT(num); - - if (intval > 100) - *component = 255; - else if (intval < 0) - *component = 0; - else - *component = intval * 255 / 100; + intval = FIXTOINT( + FDIVI(FMULI(num, 255), 100)); } + if (intval > 255) + *component = 255; + else if (intval < 0) + *component = 0; + else + *component = intval; + parserutils_vector_iterate(vector, ctx); consumeWhitespace(vector, ctx); |