diff options
Diffstat (limited to 'src/parse/properties/font.c')
-rw-r--r-- | src/parse/properties/font.c | 74 |
1 files changed, 63 insertions, 11 deletions
diff --git a/src/parse/properties/font.c b/src/parse/properties/font.c index 9903f75..16a6cc4 100644 --- a/src/parse/properties/font.c +++ b/src/parse/properties/font.c @@ -13,6 +13,42 @@ #include "parse/properties/properties.h" #include "parse/properties/utils.h" +/** + * Convert css_unit to a bytecode unit. + */ +static inline uint32_t css__to_parse_unit(css_unit u) +{ + switch (u) { + case CSS_UNIT_PX: return UNIT_PX; + case CSS_UNIT_EX: return UNIT_EX; + case CSS_UNIT_EM: return UNIT_EM; + case CSS_UNIT_IN: return UNIT_IN; + case CSS_UNIT_CM: return UNIT_CM; + case CSS_UNIT_MM: return UNIT_MM; + case CSS_UNIT_PT: return UNIT_PT; + case CSS_UNIT_PC: return UNIT_PC; + case CSS_UNIT_CH: return UNIT_CH; + case CSS_UNIT_REM: return UNIT_REM; + case CSS_UNIT_LH: return UNIT_LH; + case CSS_UNIT_VH: return UNIT_VH; + case CSS_UNIT_VW: return UNIT_VW; + case CSS_UNIT_VI: return UNIT_VI; + case CSS_UNIT_VB: return UNIT_VB; + case CSS_UNIT_VMIN: return UNIT_VMIN; + case CSS_UNIT_VMAX: return UNIT_VMAX; + case CSS_UNIT_Q: return UNIT_Q; + case CSS_UNIT_PCT: return UNIT_PCT; + case CSS_UNIT_DEG: return UNIT_DEG; + case CSS_UNIT_GRAD: return UNIT_GRAD; + case CSS_UNIT_RAD: return UNIT_RAD; + case CSS_UNIT_MS: return UNIT_MS; + case CSS_UNIT_S: return UNIT_S; + case CSS_UNIT_HZ: return UNIT_HZ; + case CSS_UNIT_KHZ: return UNIT_KHZ; + } + + return 0; +} static css_error parse_system_font(css_language *c, css_style *result, css_system_font *system_font) @@ -124,7 +160,9 @@ static css_error parse_system_font(css_language *c, if (error != CSS_OK) return error; - error = css__stylesheet_style_vappend(result, 2, system_font->size.size, system_font->size.unit); + error = css__stylesheet_style_vappend(result, 2, + system_font->size.size, + css__to_parse_unit(system_font->size.unit)); if (error != CSS_OK) return error; @@ -133,7 +171,9 @@ static css_error parse_system_font(css_language *c, if (error != CSS_OK) return error; - error = css__stylesheet_style_vappend(result, 2, system_font->line_height.size, system_font->line_height.unit); + error = css__stylesheet_style_vappend(result, 2, + system_font->line_height.size, + css__to_parse_unit(system_font->line_height.unit)); if (error != CSS_OK) return error; @@ -184,12 +224,12 @@ static css_error parse_system_font(css_language *c, * If the input is invalid, then \a *ctx remains unchanged. */ css_error css__parse_font(css_language *c, - const parserutils_vector *vector, int *ctx, + const parserutils_vector *vector, int32_t *ctx, css_style *result) { const css_token *token; css_error error; - int orig_ctx = *ctx; + int32_t orig_ctx = *ctx; int prev_ctx; css_system_font system_font; @@ -203,6 +243,7 @@ css_error css__parse_font(css_language *c, css_style *size_style; css_style *line_height_style; css_style *family_style; + enum flag_value flag_value; int svw; /* Firstly, handle inherit */ @@ -210,28 +251,36 @@ css_error css__parse_font(css_language *c, if (token == NULL) return CSS_INVALID; - if (is_css_inherit(c, token)) { - error = css_stylesheet_style_inherit(result, CSS_PROP_FONT_STYLE); + flag_value = get_css_flag_value(c, token); + + if (flag_value != FLAG_VALUE__NONE) { + error = css_stylesheet_style_flag_value(result, flag_value, + CSS_PROP_FONT_STYLE); if (error != CSS_OK) return error; - error = css_stylesheet_style_inherit(result, CSS_PROP_FONT_VARIANT); + error = css_stylesheet_style_flag_value(result, flag_value, + CSS_PROP_FONT_VARIANT); if (error != CSS_OK) return error; - error = css_stylesheet_style_inherit(result, CSS_PROP_FONT_WEIGHT); + error = css_stylesheet_style_flag_value(result, flag_value, + CSS_PROP_FONT_WEIGHT); if (error != CSS_OK) return error; - error = css_stylesheet_style_inherit(result, CSS_PROP_FONT_SIZE); + error = css_stylesheet_style_flag_value(result, flag_value, + CSS_PROP_FONT_SIZE); if (error != CSS_OK) return error; - error = css_stylesheet_style_inherit(result, CSS_PROP_LINE_HEIGHT); + error = css_stylesheet_style_flag_value(result, flag_value, + CSS_PROP_LINE_HEIGHT); if (error != CSS_OK) return error; - error = css_stylesheet_style_inherit(result, CSS_PROP_FONT_FAMILY); + error = css_stylesheet_style_flag_value(result, flag_value, + CSS_PROP_FONT_FAMILY); if (error == CSS_OK) parserutils_vector_iterate(vector, ctx); @@ -247,6 +296,9 @@ css_error css__parse_font(css_language *c, error = parse_system_font(c, result, &system_font); + lwc_string_unref(system_font.family); + system_font.family = NULL; + if (error == CSS_OK) parserutils_vector_iterate(vector, ctx); |