summaryrefslogtreecommitdiff
path: root/css
diff options
context:
space:
mode:
Diffstat (limited to 'css')
-rw-r--r--css/css.c7
-rw-r--r--css/css.h11
-rw-r--r--css/ruleset.c49
3 files changed, 67 insertions, 0 deletions
diff --git a/css/css.c b/css/css.c
index 154a85d6f..97f33934e 100644
--- a/css/css.c
+++ b/css/css.c
@@ -43,6 +43,7 @@ const struct css_style css_base_style = {
CSS_DISPLAY_BLOCK,
CSS_FLOAT_NONE,
{ CSS_FONT_SIZE_LENGTH, { { 10, CSS_UNIT_PT } } },
+ CSS_FONT_FAMILY_SANS_SERIF,
CSS_FONT_WEIGHT_NORMAL,
CSS_FONT_STYLE_NORMAL,
{ CSS_HEIGHT_AUTO, { 1, CSS_UNIT_EM } },
@@ -61,6 +62,7 @@ const struct css_style css_empty_style = {
CSS_DISPLAY_INHERIT,
CSS_FLOAT_INHERIT,
{ CSS_FONT_SIZE_INHERIT, { { 1, CSS_UNIT_EM } } },
+ CSS_FONT_FAMILY_INHERIT,
CSS_FONT_WEIGHT_INHERIT,
CSS_FONT_STYLE_INHERIT,
{ CSS_HEIGHT_INHERIT, { 1, CSS_UNIT_EM } },
@@ -79,6 +81,7 @@ const struct css_style css_blank_style = {
CSS_DISPLAY_INLINE,
CSS_FLOAT_NONE,
{ CSS_FONT_SIZE_INHERIT, { { 1, CSS_UNIT_EM } } },
+ CSS_FONT_FAMILY_INHERIT,
CSS_FONT_WEIGHT_INHERIT,
CSS_FONT_STYLE_INHERIT,
{ CSS_HEIGHT_AUTO, { 1, CSS_UNIT_EM } },
@@ -748,6 +751,8 @@ void css_cascade(struct css_style * const style, const struct css_style * const
style->display = apply->display;
if (apply->float_ != CSS_FLOAT_INHERIT)
style->float_ = apply->float_;
+ if (apply->font_family != CSS_FONT_FAMILY_INHERIT)
+ style->font_family = apply->font_family;
if (apply->font_style != CSS_FONT_STYLE_INHERIT)
style->font_style = apply->font_style;
if (apply->font_weight != CSS_FONT_WEIGHT_INHERIT)
@@ -817,6 +822,8 @@ void css_merge(struct css_style * const style, const struct css_style * const ap
style->display = apply->display;
if (apply->float_ != CSS_FLOAT_INHERIT)
style->float_ = apply->float_;
+ if (apply->font_family != CSS_FONT_FAMILY_INHERIT)
+ style->font_family = apply->font_family;
if (apply->font_size.size != CSS_FONT_SIZE_INHERIT)
style->font_size = apply->font_size;
if (apply->font_style != CSS_FONT_STYLE_INHERIT)
diff --git a/css/css.h b/css/css.h
index 640c0c041..3271ab4bd 100644
--- a/css/css.h
+++ b/css/css.h
@@ -52,6 +52,16 @@ 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;
@@ -72,6 +82,7 @@ struct css_style {
} value;
} font_size;
+ css_font_family font_family;
css_font_weight font_weight;
css_font_style font_style;
diff --git a/css/ruleset.c b/css/ruleset.c
index 0675d0d1e..00b536aba 100644
--- a/css/ruleset.c
+++ b/css/ruleset.c
@@ -44,6 +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_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);
@@ -55,6 +56,7 @@ 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 */
@@ -66,6 +68,7 @@ static const struct property_entry property_table[] = {
{ "display", parse_display },
{ "float", parse_float },
{ "font", parse_font },
+ { "font-family", parse_font_family },
{ "font-size", parse_font_size },
{ "font-style", parse_font_style },
{ "font-weight", parse_font_weight },
@@ -395,8 +398,10 @@ 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_style fs;
css_font_weight fw;
+ s->font_family = CSS_FONT_FAMILY_SANS_SERIF;
s->font_style = CSS_FONT_STYLE_NORMAL;
s->font_weight = CSS_FONT_WEIGHT_NORMAL;
s->line_height.size = CSS_LINE_HEIGHT_ABSOLUTE;
@@ -404,6 +409,13 @@ void parse_font(struct css_style * const s, const struct css_node * v)
for (; v; v = v->next) {
switch (v->type) {
case CSS_NODE_IDENT:
+ /* font-family */
+ ff = css_font_family_parse(v->data);
+ if (ff != CSS_FONT_FAMILY_UNKNOWN) {
+ s->font_family = ff;
+ break;
+ }
+
/* font-style, font-variant, or font-weight */
fs = css_font_style_parse(v->data);
if (fs != CSS_FONT_STYLE_UNKNOWN) {
@@ -432,6 +444,32 @@ 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)
+{
+ /* 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;
+ }
+ 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)
{
struct font_size_entry *fs;
@@ -585,3 +623,14 @@ css_text_decoration css_text_decoration_parse(const char * const s)
if (strcasecmp(s, "underline") == 0) return CSS_TEXT_DECORATION_UNDERLINE;
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;
+}