From ba64beed385fbfb09c61bdd0b80c3ec40f4dbf8d Mon Sep 17 00:00:00 2001 From: James Bursa Date: Tue, 30 Sep 2003 20:34:35 +0000 Subject: [project @ 2003-09-30 20:34:35 by bursa] Implement background and font properties. svn path=/import/netsurf/; revision=336 --- css/css.c | 20 ++++++++-------- css/css.h | 1 + css/ruleset.c | 73 +++++++++++++++++++++++++++++++++++++++++++++++++++++++---- 3 files changed, 80 insertions(+), 14 deletions(-) (limited to 'css') diff --git a/css/css.c b/css/css.c index 735412e0d..2030e86c5 100644 --- a/css/css.c +++ b/css/css.c @@ -577,7 +577,8 @@ void css_dump_style(const struct css_style * const style) fprintf(stderr, "color: #%lx; ", style->color); fprintf(stderr, "display: %s; ", css_display_name[style->display]); fprintf(stderr, "float: %s; ", css_float_name[style->float_]); - fprintf(stderr, "font-size: "); + fprintf(stderr, "font: %s %s ", css_font_style_name[style->font_style], + css_font_weight_name[style->font_weight]); switch (style->font_size.size) { case CSS_FONT_SIZE_ABSOLUTE: fprintf(stderr, "[%g]", style->font_size.value.absolute); break; case CSS_FONT_SIZE_LENGTH: dump_length(&style->font_size.value.length); break; @@ -585,15 +586,7 @@ void css_dump_style(const struct css_style * const style) case CSS_FONT_SIZE_INHERIT: fprintf(stderr, "inherit"); break; default: fprintf(stderr, "UNKNOWN"); break; } - fprintf(stderr, "; "); - fprintf(stderr, "height: "); - switch (style->height.height) { - case CSS_HEIGHT_AUTO: fprintf(stderr, "auto"); break; - case CSS_HEIGHT_LENGTH: dump_length(&style->height.length); break; - default: fprintf(stderr, "UNKNOWN"); break; - } - fprintf(stderr, "; "); - fprintf(stderr, "line-height: "); + fprintf(stderr, "/"); switch (style->line_height.size) { case CSS_LINE_HEIGHT_ABSOLUTE: fprintf(stderr, "[%g]", style->line_height.value.absolute); break; case CSS_LINE_HEIGHT_LENGTH: dump_length(&style->line_height.value.length); break; @@ -602,6 +595,13 @@ void css_dump_style(const struct css_style * const style) default: fprintf(stderr, "UNKNOWN"); break; } fprintf(stderr, "; "); + fprintf(stderr, "height: "); + switch (style->height.height) { + case CSS_HEIGHT_AUTO: fprintf(stderr, "auto"); break; + case CSS_HEIGHT_LENGTH: dump_length(&style->height.length); break; + default: fprintf(stderr, "UNKNOWN"); break; + } + fprintf(stderr, "; "); fprintf(stderr, "text-align: %s; ", css_text_align_name[style->text_align]); fprintf(stderr, "width: "); switch (style->width.width) { diff --git a/css/css.h b/css/css.h index 378dc5304..8b0c5b3b4 100644 --- a/css/css.h +++ b/css/css.h @@ -18,6 +18,7 @@ typedef unsigned long colour; /* 0xbbggrr */ #define TRANSPARENT 0x1000000 #define CSS_COLOR_INHERIT 0x2000000 +#define CSS_COLOR_NONE 0x3000000 struct css_length { float value; diff --git a/css/ruleset.c b/css/ruleset.c index 52403c241..f330bd535 100644 --- a/css/ruleset.c +++ b/css/ruleset.c @@ -37,11 +37,13 @@ static int compare_selectors(const struct node *n0, const struct node *n1); static int parse_length(struct css_length * const length, const struct node * const v, bool non_negative); static colour parse_colour(const struct node * const v); +static void parse_background(struct css_style * const s, const struct node * v); static void parse_background_color(struct css_style * const s, const struct node * const v); static void parse_clear(struct css_style * const s, const struct node * const v); static void parse_color(struct css_style * const s, const struct node * const v); static void parse_display(struct css_style * const s, const struct node * const v); static void parse_float(struct css_style * const s, const struct node * const v); +static void parse_font(struct css_style * const s, const struct node * v); static void parse_font_size(struct css_style * const s, const struct node * const v); static void parse_font_style(struct css_style * const s, const struct node * const v); static void parse_font_weight(struct css_style * const s, const struct node * const v); @@ -53,11 +55,13 @@ static void parse_width(struct css_style * const s, const struct node * const v) /* table of property parsers: MUST be sorted by property name */ static const struct property_entry property_table[] = { + { "background", parse_background }, { "background-color", parse_background_color }, { "clear", parse_clear }, { "color", parse_color }, { "display", parse_display }, { "float", parse_float }, + { "font", parse_font }, { "font-size", parse_font_size }, { "font-style", parse_font_style }, { "font-weight", parse_font_weight }, @@ -282,7 +286,7 @@ colour named_colour(const char *name) colour parse_colour(const struct node * const v) { - colour c = TRANSPARENT; + colour c = CSS_COLOR_NONE; int len; unsigned int r, g, b; struct colour_entry *col; @@ -319,9 +323,29 @@ colour parse_colour(const struct node * const v) } +void parse_background(struct css_style * const s, const struct node * v) +{ + colour c; + for (; v; v = v->next) { + switch (v->type) { + case NODE_HASH: + case NODE_FUNCTION: + case NODE_IDENT: + c = parse_colour(v); + if (c != CSS_COLOR_NONE) + s->background_color = c; + break; + default: + break; + } + } +} + void parse_background_color(struct css_style * const s, const struct node * const v) { - s->background_color = parse_colour(v); + colour c = parse_colour(v); + if (c != CSS_COLOR_NONE) + s->background_color = c; } void parse_clear(struct css_style * const s, const struct node * const v) @@ -336,7 +360,9 @@ void parse_clear(struct css_style * const s, const struct node * const v) void parse_color(struct css_style * const s, const struct node * const v) { - s->color = parse_colour(v); + colour c = parse_colour(v); + if (c != CSS_COLOR_NONE) + s->color = c; } void parse_display(struct css_style * const s, const struct node * const v) @@ -359,6 +385,45 @@ void parse_float(struct css_style * const s, const struct node * const v) s->float_ = z; } +void parse_font(struct css_style * const s, const struct node * v) +{ + css_font_style fs; + css_font_weight fw; + s->font_style = CSS_FONT_STYLE_NORMAL; + s->font_weight = CSS_FONT_WEIGHT_NORMAL; + s->line_height.size = CSS_LINE_HEIGHT_ABSOLUTE; + s->line_height.value.absolute = 1.3; + for (; v; v = v->next) { + switch (v->type) { + case NODE_IDENT: + /* font-style, font-variant, or font-weight */ + fs = css_font_style_parse(v->data); + if (fs != CSS_FONT_STYLE_UNKNOWN) { + s->font_style = fs; + break; + } + fw = css_font_weight_parse(v->data); + if (fw != CSS_FONT_WEIGHT_UNKNOWN) { + s->font_weight = fw; + break; + } + case NODE_PERCENTAGE: + case NODE_DIMENSION: + parse_font_size(s, v); + break; + case NODE_DELIM: + if (v->data[0] == '/' && v->data[1] == 0 && + v->next) { + v = v->next; + parse_line_height(s, v); + } + break; + default: + break; + } + } +} + void parse_font_size(struct css_style * const s, const struct node * const v) { struct font_size_entry *fs; @@ -426,7 +491,7 @@ void parse_line_height(struct css_style * const s, const struct node * const v) { if (v->type == NODE_IDENT && strcasecmp(v->data, "normal") == 0) { s->line_height.size = CSS_LINE_HEIGHT_ABSOLUTE; - s->line_height.value.absolute = 1.0; + s->line_height.value.absolute = 1.3; } else if (v->type == NODE_PERCENTAGE) { s->line_height.size = CSS_LINE_HEIGHT_PERCENT; s->line_height.value.percent = atof(v->data); -- cgit v1.2.3