diff options
Diffstat (limited to 'src/parse/properties/font_family.c')
-rw-r--r-- | src/parse/properties/font_family.c | 70 |
1 files changed, 11 insertions, 59 deletions
diff --git a/src/parse/properties/font_family.c b/src/parse/properties/font_family.c index d551e5d..a2e9511 100644 --- a/src/parse/properties/font_family.c +++ b/src/parse/properties/font_family.c @@ -46,9 +46,10 @@ static bool font_family_reserved(css_language *c, const css_token *ident) * * \param c Parsing context * \param token Token to consider + * \param first Whether the token is the first * \return Bytecode value */ -static uint16_t font_family_value(css_language *c, const css_token *token) +static css_code_t font_family_value(css_language *c, const css_token *token, bool first) { uint16_t value; bool match; @@ -80,7 +81,7 @@ static uint16_t font_family_value(css_language *c, const css_token *token) value = FONT_FAMILY_STRING; } - return value; + return first ? buildOPV(CSS_PROP_FONT_FAMILY, 0, value) : value; } /** @@ -99,17 +100,11 @@ static uint16_t font_family_value(css_language *c, const css_token *token) */ css_error parse_font_family(css_language *c, const parserutils_vector *vector, int *ctx, - css_style **result) + css_style *result) { int orig_ctx = *ctx; css_error error; const css_token *token; - uint8_t flags = 0; - uint16_t value = 0; - uint32_t opv; - uint32_t required_size = sizeof(opv); - int temp_ctx = *ctx; - uint8_t *ptr; bool match; /* [ IDENT+ | STRING ] [ ',' [ IDENT+ | STRING ] ]* | IDENT(inherit) @@ -121,8 +116,7 @@ css_error parse_font_family(css_language *c, * Perhaps this is a quirk we should inherit? */ - /* Pass 1: validate input and calculate space */ - token = parserutils_vector_iterate(vector, &temp_ctx); + token = parserutils_vector_iterate(vector, ctx); if (token == NULL || (token->type != CSS_TOKEN_IDENT && token->type != CSS_TOKEN_STRING)) { *ctx = orig_ctx; @@ -133,67 +127,25 @@ css_error parse_font_family(css_language *c, (lwc_string_caseless_isequal( token->idata, c->strings[INHERIT], &match) == lwc_error_ok && match)) { - flags = FLAG_INHERIT; + error = css_stylesheet_style_inherit(result, CSS_PROP_FONT_FAMILY); } else { - uint32_t list_size; - - value = font_family_value(c, token); + *ctx = orig_ctx; - error = comma_list_length(c, vector, &temp_ctx, - token, font_family_reserved, &list_size); + error = comma_list_to_style(c, vector, ctx, + font_family_reserved, font_family_value, + result); if (error != CSS_OK) { *ctx = orig_ctx; return error; } - required_size += list_size; + error = css_stylesheet_style_append(result, FONT_FAMILY_END); } - opv = buildOPV(CSS_PROP_FONT_FAMILY, flags, value); - - /* Allocate result */ - error = css_stylesheet_style_create(c->sheet, required_size, result); if (error != CSS_OK) { *ctx = orig_ctx; return error; } - /* Copy OPV to bytecode */ - ptr = (*result)->bytecode; - memcpy(ptr, &opv, sizeof(opv)); - ptr += sizeof(opv); - - /* Pass 2: populate bytecode */ - token = parserutils_vector_iterate(vector, ctx); - if (token == NULL || (token->type != CSS_TOKEN_IDENT && - token->type != CSS_TOKEN_STRING)) { - css_stylesheet_style_destroy(c->sheet, *result, false); - *result = NULL; - *ctx = orig_ctx; - return CSS_INVALID; - } - - if (token->type == CSS_TOKEN_IDENT && - (lwc_string_caseless_isequal( - token->idata, c->strings[INHERIT], - &match) == lwc_error_ok && match)) { - /* Nothing to do */ - } else { - error = comma_list_to_bytecode(c, vector, ctx, token, - font_family_reserved, font_family_value, - &ptr); - if (error != CSS_OK) { - css_stylesheet_style_destroy(c->sheet, *result, false); - *result = NULL; - *ctx = orig_ctx; - return error; - } - - /* Write terminator */ - opv = FONT_FAMILY_END; - memcpy(ptr, &opv, sizeof(opv)); - ptr += sizeof(opv); - } - return CSS_OK; } |