diff options
Diffstat (limited to 'css')
-rw-r--r-- | css/css.c | 34 | ||||
-rw-r--r-- | css/css.h | 10 | ||||
-rw-r--r-- | css/css_enums | 1 | ||||
-rw-r--r-- | css/ruleset.c | 27 |
4 files changed, 61 insertions, 11 deletions
@@ -83,7 +83,7 @@ const struct css_style css_blank_style = { { CSS_HEIGHT_AUTO, { 1, CSS_UNIT_EM } }, { CSS_LINE_HEIGHT_INHERIT, { 1.3 } }, CSS_TEXT_ALIGN_INHERIT, - CSS_TEXT_DECORATION_NONE, + CSS_TEXT_DECORATION_INHERIT, CSS_VISIBILITY_INHERIT, { CSS_WIDTH_AUTO, { { 1, CSS_UNIT_EM } } }, CSS_WHITE_SPACE_INHERIT @@ -601,7 +601,7 @@ void css_parse_property_list(struct css_style * style, char * str) static void dump_length(const struct css_length * const length) { fprintf(stderr, "%g%s", length->value, - css_unit_name[length->unit]); + css_unit_name[length->unit]); } void css_dump_style(const struct css_style * const style) @@ -638,7 +638,21 @@ void css_dump_style(const struct css_style * const style) } fprintf(stderr, "; "); fprintf(stderr, "text-align: %s; ", css_text_align_name[style->text_align]); - fprintf(stderr, "text-decoration: %s; ", css_text_decoration_name[style->text_decoration]); + fprintf(stderr, "text-decoration:"); + switch (style->text_decoration) { + case CSS_TEXT_DECORATION_NONE: fprintf(stderr, " none"); break; + case CSS_TEXT_DECORATION_INHERIT: fprintf(stderr, " inherit"); break; + default: + if (style->text_decoration & CSS_TEXT_DECORATION_UNDERLINE) + fprintf(stderr, " underline"); + if (style->text_decoration & CSS_TEXT_DECORATION_OVERLINE) + fprintf(stderr, " overline"); + if (style->text_decoration & CSS_TEXT_DECORATION_LINE_THROUGH) + fprintf(stderr, " line-through"); + if (style->text_decoration & CSS_TEXT_DECORATION_BLINK) + fprintf(stderr, " blink"); + } + fprintf(stderr, "; "); fprintf(stderr, "visibility: %s; ", css_visibility_name[style->visibility]); fprintf(stderr, "width: "); switch (style->width.width) { @@ -693,6 +707,12 @@ void css_cascade(struct css_style * const style, const struct css_style * const { float f; + /* text-decoration: approximate CSS 2.1 by inheriting into inline elements */ + if (apply->text_decoration != CSS_TEXT_DECORATION_INHERIT) + style->text_decoration = apply->text_decoration; +/* if (style->display == CSS_DISPLAY_INLINE && apply->display != CSS_DISPLAY_INLINE) + style->text_decoration = CSS_TEXT_DECORATION_NONE;*/ + if (apply->background_color != CSS_COLOR_INHERIT) style->background_color = apply->background_color; if (apply->clear != CSS_CLEAR_INHERIT) @@ -713,10 +733,8 @@ void css_cascade(struct css_style * const style, const struct css_style * const style->line_height = apply->line_height; if (apply->text_align != CSS_TEXT_ALIGN_INHERIT) style->text_align = apply->text_align; - if (apply->text_decoration != CSS_TEXT_DECORATION_INHERIT) - style->text_decoration = apply->text_decoration; if (apply->visibility != CSS_VISIBILITY_INHERIT) - style->visibility = apply->visibility; + style->visibility = apply->visibility; if (apply->width.width != CSS_WIDTH_INHERIT) style->width = apply->width; if (apply->white_space != CSS_WHITE_SPACE_INHERIT) @@ -786,9 +804,9 @@ void css_merge(struct css_style * const style, const struct css_style * const ap style->line_height = apply->line_height; if (apply->text_align != CSS_TEXT_ALIGN_INHERIT) style->text_align = apply->text_align; - if (apply->text_decoration != CSS_TEXT_DECORATION_INHERIT) + if (apply->text_decoration != CSS_TEXT_DECORATION_INHERIT) style->text_decoration = apply->text_decoration; - if (apply->visibility != CSS_VISIBILITY_INHERIT) + if (apply->visibility != CSS_VISIBILITY_INHERIT) style->visibility = apply->visibility; if (apply->width.width != CSS_WIDTH_INHERIT) style->width = apply->width; @@ -26,6 +26,16 @@ struct css_length { css_unit unit; }; +typedef enum { + CSS_TEXT_DECORATION_NONE = 0x0, + CSS_TEXT_DECORATION_INHERIT = 0x1, + CSS_TEXT_DECORATION_UNDERLINE = 0x2, + CSS_TEXT_DECORATION_BLINK = 0x4, + CSS_TEXT_DECORATION_LINE_THROUGH = 0x8, + CSS_TEXT_DECORATION_OVERLINE = 0x10, + CSS_TEXT_DECORATION_UNKNOWN = 0x1000 +} css_text_decoration; + struct css_style { colour background_color; css_clear clear; diff --git a/css/css_enums b/css/css_enums index 9ea8e021e..d5ab54f04 100644 --- a/css/css_enums +++ b/css/css_enums @@ -15,7 +15,6 @@ css_list_style_position outside inside css_list_style_type disc circle square decimal lower_alpha lower_roman upper_alpha upper_roman none css_margin auto length percent css_text_align inherit left right center justify -css_text_decoration inherit none blink line-through overline underline css_text_transform none capitalize lowercase uppercase css_vertical_align baseline bottom middle sub super text_bottom text_top top percent css_visibility inherit visible hidden diff --git a/css/ruleset.c b/css/ruleset.c index c2e84f1d1..f2994b31f 100644 --- a/css/ruleset.c +++ b/css/ruleset.c @@ -54,6 +54,7 @@ static void parse_text_decoration(struct css_style * const s, const struct css_n static void parse_visibility(struct css_style * const s, const struct css_node * const v); static void parse_width(struct css_style * const s, const struct css_node * const v); static void parse_white_space(struct css_style * const s, const struct css_node * const v); +static css_text_decoration css_text_decoration_parse(const char * const s); /* table of property parsers: MUST be sorted by property name */ @@ -90,6 +91,7 @@ static const struct colour_entry colour_table[] = { { "maroon", 0x000080 }, { "navy", 0x800000 }, { "olive", 0x008080 }, + { "orange", 0xffa500 }, { "purple", 0x800080 }, { "red", 0x0000ff }, { "silver", 0xc0c0c0 }, @@ -523,11 +525,21 @@ void parse_text_align(struct css_style * const s, const struct css_node * const void parse_text_decoration(struct css_style * const s, const struct css_node * const v) { css_text_decoration z; - if (v->type != CSS_NODE_IDENT || v->next != 0) + if (v->type != CSS_NODE_IDENT) return; z = css_text_decoration_parse(v->data); - if (z != CSS_TEXT_DECORATION_UNKNOWN) + if (z == CSS_TEXT_DECORATION_INHERIT || z == CSS_TEXT_DECORATION_NONE) { + if (v->next != 0) + return; s->text_decoration = z; + } + if (z != CSS_TEXT_DECORATION_UNKNOWN) + s->text_decoration |= z; + for (v = v->next; v; v = v->next) { + z = css_text_decoration_parse(v->data); + if (z != CSS_TEXT_DECORATION_UNKNOWN) + s->text_decoration |= z; + } } void parse_visibility(struct css_style * const s, const struct css_node * const v) @@ -561,3 +573,14 @@ void parse_white_space(struct css_style * const s, const struct css_node * const if (z != CSS_WHITE_SPACE_UNKNOWN) s->white_space = z; } + +css_text_decoration css_text_decoration_parse(const char * const s) +{ + if (strcasecmp(s, "inherit") == 0) return CSS_TEXT_DECORATION_INHERIT; + if (strcasecmp(s, "none") == 0) return CSS_TEXT_DECORATION_NONE; + if (strcasecmp(s, "blink") == 0) return CSS_TEXT_DECORATION_BLINK; + if (strcasecmp(s, "line-through") == 0) return CSS_TEXT_DECORATION_LINE_THROUGH; + if (strcasecmp(s, "overline") == 0) return CSS_TEXT_DECORATION_OVERLINE; + if (strcasecmp(s, "underline") == 0) return CSS_TEXT_DECORATION_UNDERLINE; + return CSS_TEXT_DECORATION_UNKNOWN; +} |