diff options
-rw-r--r-- | render/box.c | 12 | ||||
-rw-r--r-- | render/css.c | 39 | ||||
-rw-r--r-- | render/css.h | 25 | ||||
-rw-r--r-- | render/css_enums | 4 | ||||
-rw-r--r-- | render/render.c | 3 | ||||
-rw-r--r-- | render/test/test1.css | 2 | ||||
-rw-r--r-- | render/test/test1.html | 4 |
7 files changed, 51 insertions, 38 deletions
diff --git a/render/box.c b/render/box.c index dd3796e3d..2966e70af 100644 --- a/render/box.c +++ b/render/box.c @@ -1,5 +1,5 @@ /** - * $Id: box.c,v 1.1 2002/05/04 19:57:18 bursa Exp $ + * $Id: box.c,v 1.2 2002/05/04 21:17:06 bursa Exp $ */ #include <assert.h> @@ -60,6 +60,7 @@ struct box * xml_to_box(xmlNode * n, struct css_style * parent_style, struct css struct box * inline_container_c; struct css_style * style; xmlNode * c; + xmlChar * s; if (n->type == XML_ELEMENT_NODE) { /* work out the style for this element */ @@ -71,6 +72,15 @@ struct box * xml_to_box(xmlNode * n, struct css_style * parent_style, struct css memcpy(style, parent_style, sizeof(struct css_style)); css_get_style(stylesheet, *selector, depth + 1, style); + if (s = xmlGetProp(n, "style")) { + struct css_style * astyle = xcalloc(1, sizeof(struct css_style)); + memcpy(astyle, &css_empty_style, sizeof(struct css_style)); + css_parse_property_list(astyle, s); + css_cascade(style, astyle); + free(astyle); + free(s); + } + switch (style->display) { case CSS_DISPLAY_BLOCK: /* blocks get a node in the box tree */ box = xcalloc(1, sizeof(struct box)); diff --git a/render/css.c b/render/css.c index 45ed2d9bd..256dc4168 100644 --- a/render/css.c +++ b/render/css.c @@ -1,5 +1,5 @@ /** - * $Id: css.c,v 1.1.1.1 2002/04/22 09:24:34 bursa Exp $ + * $Id: css.c,v 1.2 2002/05/04 21:17:06 bursa Exp $ */ #include <string.h> @@ -36,7 +36,6 @@ static void parse_float(struct css_style * const style, const char * const value static void parse_font_size(struct css_style * const style, const char * const value); static void parse_height(struct css_style * const style, const char * const value); static void parse_width(struct css_style * const style, const char * const value); -static void parse_property_list(struct css_style * style, char * str); static void parse_selector(struct css_selector * sel, char * const str); static unsigned int hash_str(const char * str); static int seleq(const struct css_selector * const s1, const struct css_selector * const s2); @@ -51,6 +50,23 @@ static void dump_selector(const struct css_selector * const sel); static void dump_rule(const struct rule * rule); static void css_dump_stylesheet(const struct css_stylesheet * stylesheet); +const struct css_style css_base_style = { + CSS_DISPLAY_BLOCK, + CSS_FLOAT_NONE, + { CSS_FONT_SIZE_ABSOLUTE, 10.0 }, + { CSS_HEIGHT_AUTO }, + { CSS_WIDTH_AUTO } +}; + +const struct css_style css_empty_style = { + CSS_DISPLAY_INHERIT, + CSS_FLOAT_INHERIT, + { CSS_FONT_SIZE_INHERIT }, + { CSS_HEIGHT_AUTO }, + { CSS_WIDTH_AUTO } +}; + + /** * property parsers */ @@ -145,7 +161,7 @@ static struct property { * parse a property list */ -static void parse_property_list(struct css_style * style, char * str) +void css_parse_property_list(struct css_style * style, char * str) { char * end; for (; str != 0; str = end) { @@ -158,7 +174,7 @@ static void parse_property_list(struct css_style * style, char * str) *value = 0; value++; prop = strip(str); value = strip(value); - printf("css_parse: '%s' => '%s'\n", prop, value); + /*printf("css_parse: '%s' => '%s'\n", prop, value);*/ for (i = 0; i < sizeof(property) / sizeof(struct property); i++) { if (strcmp(prop, property[i].name) == 0) { @@ -310,17 +326,18 @@ static void update_style(struct css_stylesheet * stylesheet, struct css_selector struct rule * rule = find_rule(stylesheet, selector, selectors); if (rule == 0) { unsigned int h = hash_str(selector[selectors - 1].element); - printf("update_style: not present - adding\n"); + /*printf("update_style: not present - adding\n");*/ rule = xcalloc(1, sizeof(struct rule)); rule->selector = selector; rule->selectors = selectors; rule->style = xcalloc(1, sizeof(struct css_style)); - parse_property_list(rule->style, str); + memcpy(rule->style, &css_empty_style, sizeof(struct css_style)); + css_parse_property_list(rule->style, str); rule->next = stylesheet->hash[h]; stylesheet->hash[h] = rule; } else { - printf("update_style: already present - updating\n"); - parse_property_list(rule->style, str); + /*printf("update_style: already present - updating\n");*/ + css_parse_property_list(rule->style, str); free(selector); } } @@ -361,7 +378,7 @@ void css_parse_stylesheet(struct css_stylesheet * stylesheet, char * str) if (comma != 0) *comma = 0; sel_str = strip(sels_str); - printf("css_parse_stylesheet: %s\n", sel_str); + /*printf("css_parse_stylesheet: %s\n", sel_str);*/ do { space = strchr(sel_str, ' '); if (space != 0) *space = 0; @@ -459,8 +476,8 @@ static void css_dump_stylesheet(const struct css_stylesheet * stylesheet) void css_cascade(struct css_style * const style, const struct css_style * const apply) { float f; - style->display = apply->display; - style->float_ = apply->float_; + if (apply->display != CSS_DISPLAY_INHERIT) style->display = apply->display; + if (apply->float_ != CSS_FLOAT_INHERIT) style->float_ = apply->float_; style->height = apply->height; style->width = apply->width; diff --git a/render/css.h b/render/css.h index 3e465fde1..425db27f4 100644 --- a/render/css.h +++ b/render/css.h @@ -1,5 +1,5 @@ /** - * $Id: css.h,v 1.1.1.1 2002/04/22 09:24:34 bursa Exp $ + * $Id: css.h,v 1.2 2002/05/04 21:17:06 bursa Exp $ */ #include "css_enum.h" @@ -47,24 +47,6 @@ struct css_style { float percent; } value; } width; - - - enum { BACKGROUND_SCROLL = 1, BACKGROUND_FIXED } background_attachment; - colour background_color; - /* char background_image[100]; */ - /* background-position */ - enum { BACKGROUND_REPEAT = 1, BACKGROUND_REPEAT_X, - BACKGROUND_REPEAT_Y, BACKGROUND_NO_REPEAT } background_repeat; - /* borders */ - enum { CLEAR_NONE = 1, CLEAR_BOTH, CLEAR_LEFT, CLEAR_RIGHT } clear; - colour color; - /* font-family */ - enum { FONT_STRAIGHT, FONT_OBLIQUE, FONT_ITALIC } font_style; - enum { FONT_NORMAL, FONT_SMALLCAPS } font_variant; - struct { - enum { WEIGHT_ABSOLUTE, WEIGHT_BOLDER, WEIGHT_LIGHTER } weight; - unsigned int value; - } font_weight; }; struct css_stylesheet; @@ -75,6 +57,9 @@ struct css_selector { char * id; }; +extern const struct css_style css_base_style; +extern const struct css_style css_empty_style; + /** * interface */ @@ -85,3 +70,5 @@ void css_get_style(struct css_stylesheet * stylesheet, struct css_selector * sel void css_parse_stylesheet(struct css_stylesheet * stylesheet, char * str); void css_dump_style(const struct css_style * const style); void css_cascade(struct css_style * const style, const struct css_style * const apply); +void css_parse_property_list(struct css_style * style, char * str); + diff --git a/render/css_enums b/render/css_enums index 96ce8ef56..4f8a3f8b0 100644 --- a/render/css_enums +++ b/render/css_enums @@ -5,8 +5,8 @@ css_background_repeat inherit repeat repeat_x repeat_y no_repeat css_border_width inherit medium thin thick length css_border_style inherit none dashed dotted double groove inset outset ridge solid css_clear none both left right -css_display inline block list-item run-in compact marker 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 none left right +css_display inherit inline block list-item run-in compact marker 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_style normal italic oblique css_font_variant normal smallcaps css_font_weight normal bold bolder lighter 100 200 300 400 500 600 700 800 900 diff --git a/render/render.c b/render/render.c index d9e470b37..6ada1da3e 100644 --- a/render/render.c +++ b/render/render.c @@ -1,5 +1,5 @@ /** - * $Id: render.c,v 1.7 2002/05/04 19:57:18 bursa Exp $ + * $Id: render.c,v 1.8 2002/05/04 21:17:06 bursa Exp $ */ #include <assert.h> @@ -110,6 +110,7 @@ int main(int argc, char *argv[]) stylesheet = css_new_stylesheet(); css_parse_stylesheet(stylesheet, load(argv[2])); + memcpy(style, &css_base_style, sizeof(struct css_style)); doc_box->type = BOX_BLOCK; doc_box->node = c; xml_to_box(c, style, stylesheet, &selector, 0, doc_box, 0); diff --git a/render/test/test1.css b/render/test/test1.css index 023a36ed7..dbff4a8b9 100644 --- a/render/test/test1.css +++ b/render/test/test1.css @@ -22,5 +22,3 @@ caption { display: table-caption } div { float: left; width: 90%; } -td { width: 40%; } - diff --git a/render/test/test1.html b/render/test/test1.html index 50e98cc3b..757c51cb6 100644 --- a/render/test/test1.html +++ b/render/test/test1.html @@ -5,11 +5,11 @@ <body> -<h1>Heading</h1> +<h1 style="width: 80%">Heading</h1> <p>Vestibulum ante ipsum primis in faucibus orci luctus et ultrices posuere cubilia Curae; Pellentesque <b>habitant <i>Morbi</i></b> tristique Senectus et Metus et malesuada Fames ac turpis Egestas. (This paragraph has no closing tag.)<p>Vestibulum ante ipsum primis in faucibus orci luctus et ultrices posuere cubilia Curae; <b>Pellentesque</b> habitant Morbi tristique Senectus et Metus et malesuada Fames ac turpis Egestas.</p> -<table><tr><td>Cell 1</td><td>Cell 2<p>More cell 2</p></td></tr> +<table><tr><td style="width: 30%; height: 1em">Cell 1</td><td style="width: 50%;">Cell 2<p>More cell 2</p></td></tr> <tr><td>Cell 3</td><td>Cell 4</td></tr></table> <p>Inline text <div>containing a block</div> and more text.</p> |