From ae4cb4c56dd865654a718c80693d8ac046126ace Mon Sep 17 00:00:00 2001 From: James Bursa Date: Wed, 28 Jan 2004 23:08:28 +0000 Subject: [project @ 2004-01-28 23:08:28 by bursa] Improve font-family. svn path=/import/netsurf/; revision=515 --- css/css.h | 10 ---------- css/css_enums | 1 + css/ruleset.c | 51 ++++++++++++++++----------------------------------- riscos/font.c | 7 +------ 4 files changed, 18 insertions(+), 51 deletions(-) diff --git a/css/css.h b/css/css.h index 3271ab4bd..3c27b0182 100644 --- a/css/css.h +++ b/css/css.h @@ -52,16 +52,6 @@ typedef enum { CSS_TEXT_DECORATION_UNKNOWN = 0x1000 } css_text_decoration; -typedef enum { - CSS_FONT_FAMILY_INHERIT = 0x1, - CSS_FONT_FAMILY_SANS_SERIF = 0x2, - CSS_FONT_FAMILY_SERIF = 0x4, - CSS_FONT_FAMILY_MONOSPACE = 0x8, - CSS_FONT_FAMILY_CURSIVE = 0x10, - CSS_FONT_FAMILY_FANTASY = 0x20, - CSS_FONT_FAMILY_UNKNOWN = 0x1000 -} css_font_family; - /** Representation of a complete CSS 2 style. */ struct css_style { colour background_color; diff --git a/css/css_enums b/css/css_enums index d5ab54f04..9dd77c9c3 100644 --- a/css/css_enums +++ b/css/css_enums @@ -7,6 +7,7 @@ css_border_style inherit none dashed dotted double groove inset outset ridge sol css_clear inherit none both left right css_display inherit inline block list-item run-in inline-block table inline-table table-row-group table-header-group table-footer-group table-row table-column-group table-column table-cell table-caption none css_float inherit none left right +css_font_family inherit sans-serif serif monospace cursive fantasy css_font_style inherit normal italic oblique css_font_variant normal smallcaps css_font_weight inherit normal bold bolder lighter 100 200 300 400 500 600 700 800 900 diff --git a/css/ruleset.c b/css/ruleset.c index 00b536aba..578704af6 100644 --- a/css/ruleset.c +++ b/css/ruleset.c @@ -44,7 +44,7 @@ static void parse_color(struct css_style * const s, const struct css_node * cons static void parse_display(struct css_style * const s, const struct css_node * const v); static void parse_float(struct css_style * const s, const struct css_node * const v); static void parse_font(struct css_style * const s, const struct css_node * v); -static void parse_font_family(struct css_style * const s, const struct css_node * const v); +static void parse_font_family(struct css_style * const s, const struct css_node * v); static void parse_font_size(struct css_style * const s, const struct css_node * const v); static void parse_font_style(struct css_style * const s, const struct css_node * const v); static void parse_font_weight(struct css_style * const s, const struct css_node * const v); @@ -56,7 +56,6 @@ static void parse_visibility(struct css_style * const s, const struct css_node * 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); -static css_font_family css_font_family_parse(const char * const s); /* table of property parsers: MUST be sorted by property name */ @@ -398,7 +397,7 @@ void parse_float(struct css_style * const s, const struct css_node * const v) void parse_font(struct css_style * const s, const struct css_node * v) { - css_font_family ff; + css_font_family ff; css_font_style fs; css_font_weight fw; s->font_family = CSS_FONT_FAMILY_SANS_SERIF; @@ -444,30 +443,22 @@ void parse_font(struct css_style * const s, const struct css_node * v) } } -void parse_font_family(struct css_style * const s, const struct css_node * const v) +void parse_font_family(struct css_style * const s, const struct css_node * v) { - /* TODO - font-family values are found in a comma separated list. - * Each list element should be considered in turn. - * The first match should be used. - * White space in a quoted string should be left alone, - * other white space should be reduced to a single space.*/ - struct css_node *temp; css_font_family z; - if (v->type != CSS_NODE_IDENT) - return; - z = css_font_family_parse(v->data); - if (z == CSS_FONT_FAMILY_INHERIT) { - if (v->next != 0) - return; - s->font_family = z; + for (; v; v = v->next) { + switch (v->type) { + case CSS_NODE_IDENT: + z = css_font_family_parse(v->data); + if (z != CSS_FONT_FAMILY_UNKNOWN) { + s->font_family = z; + return; + } + break; + default: + break; + } } - if (z != CSS_FONT_FAMILY_UNKNOWN) - s->font_family = z; - /* for now, take the first item */ - /*for (temp = v->next; temp; temp=temp->next) { - z = css_font_family_parse(temp->data); - s->font_family |= z; - }*/ } void parse_font_size(struct css_style * const s, const struct css_node * const v) @@ -519,7 +510,7 @@ void parse_font_style(struct css_style * const s, const struct css_node * const void parse_font_weight(struct css_style * const s, const struct css_node * const v) { css_font_weight z; - if (v->type != CSS_NODE_IDENT || v->next != 0) + if ((v->type != CSS_NODE_IDENT && v->type != CSS_NODE_NUMBER) || v->next != 0) return; z = css_font_weight_parse(v->data); if (z != CSS_FONT_WEIGHT_UNKNOWN) @@ -624,13 +615,3 @@ css_text_decoration css_text_decoration_parse(const char * const s) return CSS_TEXT_DECORATION_UNKNOWN; } -css_font_family css_font_family_parse(const char * const s) -{ - if (strcasecmp(s, "inherit") == 0) return CSS_FONT_FAMILY_INHERIT; - if (strcasecmp(s, "sans-serif") == 0) return CSS_FONT_FAMILY_SANS_SERIF; - if (strcasecmp(s, "serif") == 0) return CSS_FONT_FAMILY_SERIF; - if (strcasecmp(s, "monospace") == 0) return CSS_FONT_FAMILY_MONOSPACE; - if (strcasecmp(s, "cursive") == 0) return CSS_FONT_FAMILY_CURSIVE; - if (strcasecmp(s, "fantasy") == 0) return CSS_FONT_FAMILY_FANTASY; - return CSS_TEXT_DECORATION_UNKNOWN; -} diff --git a/riscos/font.c b/riscos/font.c index 37fc8f7f2..9833871c3 100644 --- a/riscos/font.c +++ b/riscos/font.c @@ -112,7 +112,6 @@ struct font_data *font_open(struct font_set *set, struct css_style *style) unsigned int f = 0; font_f handle; os_error *error; - bool bold=false, italic=false; assert(set); assert(style); @@ -147,7 +146,6 @@ struct font_data *font_open(struct font_set *set, struct css_style *style) case CSS_FONT_WEIGHT_800: case CSS_FONT_WEIGHT_900: f += FONT_BOLD; - bold = true; break; default: break; @@ -157,7 +155,6 @@ struct font_data *font_open(struct font_set *set, struct css_style *style) case CSS_FONT_STYLE_ITALIC: case CSS_FONT_STYLE_OBLIQUE: f += FONT_SLANTED; - italic = true; break; default: break; @@ -174,9 +171,7 @@ struct font_data *font_open(struct font_set *set, struct css_style *style) if (error) { /* fall back to Homerton */ LOG(("font_find_font failed; falling back to Homerton")); - f = 0 + (bold ? FONT_BOLD : 0) + (italic ? FONT_SLANTED: 0); - - error = xfont_find_font(font_table[f], (int)size, (int)size, + error = xfont_find_font(font_table[f % 4], (int)size, (int)size, 0, 0, &handle, 0, 0); if (error) { LOG(("%i: %s\n", error->errnum, error->errmess)); -- cgit v1.2.3