diff options
Diffstat (limited to 'src/parse/font_face.c')
-rw-r--r-- | src/parse/font_face.c | 120 |
1 files changed, 60 insertions, 60 deletions
diff --git a/src/parse/font_face.c b/src/parse/font_face.c index 8eab006..f17d50e 100644 --- a/src/parse/font_face.c +++ b/src/parse/font_face.c @@ -15,22 +15,22 @@ #include "parse/properties/utils.h" #include "select/font_face.h" -static bool font_rule_font_family_reserved(css_language *c, +static bool font_rule_font_family_reserved(css_language *c, const css_token *ident) { bool match; return (lwc_string_caseless_isequal(ident->idata, c->strings[SERIF], &match) == lwc_error_ok && match) || - (lwc_string_caseless_isequal(ident->idata, - c->strings[SANS_SERIF], &match) == lwc_error_ok && + (lwc_string_caseless_isequal(ident->idata, + c->strings[SANS_SERIF], &match) == lwc_error_ok && match) || (lwc_string_caseless_isequal(ident->idata, c->strings[CURSIVE], &match) == lwc_error_ok && match) || (lwc_string_caseless_isequal(ident->idata, c->strings[FANTASY], &match) == lwc_error_ok && match) || - (lwc_string_caseless_isequal(ident->idata, - c->strings[MONOSPACE], &match) == lwc_error_ok && + (lwc_string_caseless_isequal(ident->idata, + c->strings[MONOSPACE], &match) == lwc_error_ok && match) || (lwc_string_caseless_isequal(ident->idata, c->strings[INHERIT], &match) == lwc_error_ok && match) || @@ -40,9 +40,9 @@ static bool font_rule_font_family_reserved(css_language *c, &match) == lwc_error_ok && match); } -static css_error font_face_parse_font_family(css_language *c, +static css_error font_face_parse_font_family(css_language *c, const parserutils_vector *vector, int *ctx, - css_font_face *font_face) + css_font_face *font_face) { css_error error; lwc_string *string; @@ -58,9 +58,9 @@ static css_error font_face_parse_font_family(css_language *c, return CSS_OK; } - -static css_error font_face_src_parse_format(css_language *c, - const parserutils_vector *vector, int *ctx, + +static css_error font_face_src_parse_format(css_language *c, + const parserutils_vector *vector, int *ctx, css_font_face_format *format) { bool match; @@ -68,8 +68,8 @@ static css_error font_face_src_parse_format(css_language *c, *format = CSS_FONT_FACE_FORMAT_UNSPECIFIED; - /* 'format(' STRING [ ',' STRING ]* ')' - * + /* 'format(' STRING [ ',' STRING ]* ')' + * * 'format(' already consumed */ @@ -80,27 +80,27 @@ static css_error font_face_src_parse_format(css_language *c, if (token == NULL || token->type != CSS_TOKEN_STRING) return CSS_INVALID; - if (lwc_string_isequal(token->idata, - c->strings[WOFF], &match) == lwc_error_ok && + if (lwc_string_isequal(token->idata, + c->strings[WOFF], &match) == lwc_error_ok && match) { *format |= CSS_FONT_FACE_FORMAT_WOFF; - } else if ((lwc_string_isequal(token->idata, + } else if ((lwc_string_isequal(token->idata, c->strings[TRUETYPE], &match) == lwc_error_ok && match) || - (lwc_string_isequal(token->idata, + (lwc_string_isequal(token->idata, c->strings[OPENTYPE], &match) == lwc_error_ok && match)) { *format |= CSS_FONT_FACE_FORMAT_OPENTYPE; - } else if (lwc_string_isequal(token->idata, - c->strings[EMBEDDED_OPENTYPE], + } else if (lwc_string_isequal(token->idata, + c->strings[EMBEDDED_OPENTYPE], &match) == lwc_error_ok && match) { *format |= CSS_FONT_FACE_FORMAT_EMBEDDED_OPENTYPE; - } else if (lwc_string_isequal(token->idata, - c->strings[SVG], &match) == lwc_error_ok && + } else if (lwc_string_isequal(token->idata, + c->strings[SVG], &match) == lwc_error_ok && match) { *format |= CSS_FONT_FACE_FORMAT_SVG; } else { - /* The spec gives a list of possible strings, which + /* The spec gives a list of possible strings, which * hints that unknown strings should be parse errors, * but it also talks about "unknown font formats", * so we treat any string we don't know not as a parse @@ -119,8 +119,8 @@ static css_error font_face_src_parse_format(css_language *c, return CSS_OK; } -static css_error font_face_src_parse_spec_or_name(css_language *c, - const parserutils_vector *vector, int *ctx, +static css_error font_face_src_parse_spec_or_name(css_language *c, + const parserutils_vector *vector, int *ctx, lwc_string **location, css_font_face_location_type *location_type, css_font_face_format *format) @@ -138,12 +138,12 @@ static css_error font_face_src_parse_spec_or_name(css_language *c, consumeWhitespace(vector, ctx); token = parserutils_vector_iterate(vector, ctx); - if (token == NULL) + if (token == NULL) return CSS_INVALID; if (token->type == CSS_TOKEN_URI) { error = c->sheet->resolve(c->sheet->resolve_pw, - c->sheet->url, token->idata, + c->sheet->url, token->idata, location); if (error != CSS_OK) return error; @@ -154,10 +154,10 @@ static css_error font_face_src_parse_spec_or_name(css_language *c, token = parserutils_vector_peek(vector, *ctx); if (token != NULL && token->type == CSS_TOKEN_FUNCTION && - lwc_string_caseless_isequal(token->idata, - c->strings[FORMAT], &match) == lwc_error_ok && + lwc_string_caseless_isequal(token->idata, + c->strings[FORMAT], &match) == lwc_error_ok && match) { - parserutils_vector_iterate(vector, ctx); + parserutils_vector_iterate(vector, ctx); error = font_face_src_parse_format(c, vector, ctx, format); @@ -167,8 +167,8 @@ static css_error font_face_src_parse_spec_or_name(css_language *c, } } } else if (token->type == CSS_TOKEN_FUNCTION && - lwc_string_caseless_isequal(token->idata, - c->strings[LOCAL], + lwc_string_caseless_isequal(token->idata, + c->strings[LOCAL], &match) == lwc_error_ok && match) { consumeWhitespace(vector, ctx); @@ -179,7 +179,7 @@ static css_error font_face_src_parse_spec_or_name(css_language *c, consumeWhitespace(vector, ctx); - token = parserutils_vector_iterate(vector, ctx); + token = parserutils_vector_iterate(vector, ctx); if (token == NULL || tokenIsChar(token, ')') == false) { lwc_string_unref(*location); return CSS_INVALID; @@ -193,8 +193,8 @@ static css_error font_face_src_parse_spec_or_name(css_language *c, return CSS_OK; } -static css_error font_face_parse_src(css_language *c, - const parserutils_vector *vector, int *ctx, +static css_error font_face_parse_src(css_language *c, + const parserutils_vector *vector, int *ctx, css_font_face *font_face) { int orig_ctx = *ctx; @@ -213,11 +213,11 @@ static css_error font_face_parse_src(css_language *c, /* Create one css_font_face_src for each consecutive location and * [potentially] type pair in the comma-separated list */ - do { + do { lwc_string *location; css_font_face_location_type location_type = CSS_FONT_FACE_LOCATION_TYPE_UNSPECIFIED; - css_font_face_format format = + css_font_face_format format = CSS_FONT_FACE_FORMAT_UNSPECIFIED; error = font_face_src_parse_spec_or_name(c, vector, ctx, @@ -225,10 +225,10 @@ static css_error font_face_parse_src(css_language *c, if (error != CSS_OK) goto cleanup; - /* This will be inefficient if there are a lot of locations - + /* This will be inefficient if there are a lot of locations - * probably not a problem in practice. */ - new_srcs = realloc(srcs, + new_srcs = realloc(srcs, (n_srcs + 1) * sizeof(css_font_face_src)); if (new_srcs == NULL) { error = CSS_NOMEM; @@ -240,7 +240,7 @@ static css_error font_face_parse_src(css_language *c, srcs[n_srcs].bits[0] = format << 2 | location_type; ++n_srcs; - + consumeWhitespace(vector, ctx); token = parserutils_vector_iterate(vector, ctx); } while (token != NULL && tokenIsChar(token, ',')); @@ -250,7 +250,7 @@ static css_error font_face_parse_src(css_language *c, cleanup: if (error != CSS_OK) { *ctx = orig_ctx; - if (srcs != NULL) + if (srcs != NULL) free(srcs); } @@ -273,16 +273,16 @@ static css_error font_face_parse_font_style(css_language *c, if ((token == NULL) || ((token->type != CSS_TOKEN_IDENT))) { *ctx = orig_ctx; return CSS_INVALID; - } - - if ((lwc_string_caseless_isequal(token->idata, + } + + if ((lwc_string_caseless_isequal(token->idata, c->strings[NORMAL], &match) == lwc_error_ok && match)) { style = CSS_FONT_STYLE_NORMAL; - } else if ((lwc_string_caseless_isequal(token->idata, + } else if ((lwc_string_caseless_isequal(token->idata, c->strings[ITALIC], &match) == lwc_error_ok && match)) { style = CSS_FONT_STYLE_ITALIC; - } else if ((lwc_string_caseless_isequal(token->idata, - c->strings[OBLIQUE], &match) == lwc_error_ok && + } else if ((lwc_string_caseless_isequal(token->idata, + c->strings[OBLIQUE], &match) == lwc_error_ok && match)) { style = CSS_FONT_STYLE_OBLIQUE; } else { @@ -294,12 +294,12 @@ static css_error font_face_parse_font_style(css_language *c, } else { *ctx = orig_ctx; } - + return error; } -static css_error font_face_parse_font_weight(css_language *c, - const parserutils_vector *vector, int *ctx, +static css_error font_face_parse_font_weight(css_language *c, + const parserutils_vector *vector, int *ctx, css_font_face *font_face) { int orig_ctx = *ctx; @@ -308,7 +308,7 @@ static css_error font_face_parse_font_weight(css_language *c, enum css_font_weight_e weight = 0; bool match; - /* NUMBER (100, 200, 300, 400, 500, 600, 700, 800, 900) | + /* NUMBER (100, 200, 300, 400, 500, 600, 700, 800, 900) | * IDENT (normal, bold) */ token = parserutils_vector_iterate(vector, ctx); if (token == NULL || (token->type != CSS_TOKEN_IDENT && @@ -319,7 +319,7 @@ static css_error font_face_parse_font_weight(css_language *c, if (token->type == CSS_TOKEN_NUMBER) { size_t consumed = 0; - css_fixed num = css__number_from_lwc_string(token->idata, + css_fixed num = css__number_from_lwc_string(token->idata, true, &consumed); /* Invalid if there are trailing characters */ if (consumed != lwc_string_length(token->idata)) { @@ -339,10 +339,10 @@ static css_error font_face_parse_font_weight(css_language *c, case 900: weight = CSS_FONT_WEIGHT_900; break; default: error = CSS_INVALID; } - } else if ((lwc_string_caseless_isequal(token->idata, + } else if ((lwc_string_caseless_isequal(token->idata, c->strings[NORMAL], &match) == lwc_error_ok && match)) { weight = CSS_FONT_WEIGHT_NORMAL; - } else if ((lwc_string_caseless_isequal(token->idata, + } else if ((lwc_string_caseless_isequal(token->idata, c->strings[BOLD], &match) == lwc_error_ok && match)) { weight = CSS_FONT_WEIGHT_BOLD; } else { @@ -350,7 +350,7 @@ static css_error font_face_parse_font_weight(css_language *c, } if (error == CSS_OK) { - font_face->bits[0] = (font_face->bits[0] & 0xc3) | + font_face->bits[0] = (font_face->bits[0] & 0xc3) | (weight << 2); } else { *ctx = orig_ctx; @@ -372,7 +372,7 @@ static css_error font_face_parse_font_weight(css_language *c, * CSS_INVALID on invalid syntax, * CSS_NOMEM on memory exhaustion */ -css_error css__parse_font_descriptor(css_language *c, +css_error css__parse_font_descriptor(css_language *c, const css_token *descriptor, const parserutils_vector *vector, int *ctx, css_rule_font_face *rule) { @@ -388,24 +388,24 @@ css_error css__parse_font_descriptor(css_language *c, rule->font_face = font_face; } - - if (lwc_string_caseless_isequal(descriptor->idata, - c->strings[FONT_FAMILY], &match) == lwc_error_ok && + + if (lwc_string_caseless_isequal(descriptor->idata, + c->strings[FONT_FAMILY], &match) == lwc_error_ok && match) { return font_face_parse_font_family(c, vector, ctx, font_face); } else if (lwc_string_caseless_isequal(descriptor->idata, c->strings[SRC], &match) == lwc_error_ok && match) { return font_face_parse_src(c, vector, ctx, font_face); } else if (lwc_string_caseless_isequal(descriptor->idata, - c->strings[FONT_STYLE], &match) == lwc_error_ok && + c->strings[FONT_STYLE], &match) == lwc_error_ok && match) { return font_face_parse_font_style(c, vector, ctx, font_face); } else if (lwc_string_caseless_isequal(descriptor->idata, - c->strings[FONT_WEIGHT], &match) == lwc_error_ok && + c->strings[FONT_WEIGHT], &match) == lwc_error_ok && match) { return font_face_parse_font_weight(c, vector, ctx, font_face); } - + return CSS_INVALID; } |