From ba3822abf4e7da6e41df81e7df3d1eda62c8f01b Mon Sep 17 00:00:00 2001 From: John Mark Bell Date: Mon, 12 Jan 2009 09:55:29 +0000 Subject: When parsing colours, it helps to remember that percentages aren't necessarily integers. svn path=/trunk/libcss/; revision=6045 --- src/parse/properties.c | 30 +++++++++++++----------------- 1 file 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); -- cgit v1.2.3