From a4c5929a2fac1cb0c039b2d009d8093ac81a90d7 Mon Sep 17 00:00:00 2001 From: James Bursa Date: Sun, 9 Feb 2003 12:58:15 +0000 Subject: [project @ 2003-02-09 12:58:14 by bursa] Reorganization and rewrite of fetch, cache, and content handling. svn path=/import/netsurf/; revision=96 --- render/box.c | 26 ++++----- render/box.h | 8 +-- render/css.c | 16 +++--- render/html.c | 156 +++++++++++++++++++++++++++++++++++++++++++++++++++++ render/html.h | 17 ++++++ render/layout.c | 21 ++++---- render/textplain.c | 52 ++++++++++++++++++ render/textplain.h | 17 ++++++ 8 files changed, 278 insertions(+), 35 deletions(-) create mode 100644 render/html.c create mode 100644 render/html.h create mode 100644 render/textplain.c create mode 100644 render/textplain.h (limited to 'render') diff --git a/render/box.c b/render/box.c index a5a4b525d..1a07be7ba 100644 --- a/render/box.c +++ b/render/box.c @@ -1,5 +1,5 @@ /** - * $Id: box.c,v 1.32 2003/01/11 17:36:40 monkeyson Exp $ + * $Id: box.c,v 1.33 2003/02/09 12:58:15 bursa Exp $ */ #include @@ -12,7 +12,7 @@ #include "netsurf/render/css.h" #include "netsurf/riscos/font.h" #include "netsurf/render/box.h" -#include "netsurf/render/utils.h" +#include "netsurf/utils/utils.h" #include "netsurf/utils/log.h" #include "netsurf/desktop/gui.h" @@ -24,13 +24,13 @@ struct box* input(xmlNode * n, struct css_style* style, struct form* current_for void box_add_child(struct box * parent, struct box * child); struct box * box_create(xmlNode * node, box_type type, struct css_style * style, - const char *href); -char * tolat1(const xmlChar * s); + char *href); +char * tolat1(xmlChar * s); struct box * convert_xml_to_box(xmlNode * n, struct css_style * parent_style, struct css_stylesheet * stylesheet, struct css_selector ** selector, unsigned int depth, struct box * parent, struct box * inline_container, - const char *href, struct font_set *fonts, + char *href, struct font_set *fonts, struct gui_gadget* current_select, struct formoption* current_option, struct gui_gadget* current_textarea, struct form* current_form, struct page_elements* elements); @@ -43,7 +43,7 @@ void box_normalise_table_row(struct box *row); void box_normalise_inline_container(struct box *cont); void gadget_free(struct gui_gadget* g); void box_free_box(struct box *box); -struct box* box_image(xmlNode * n, struct css_style* style, const char* href); +struct box* box_image(xmlNode * n, struct css_style* style, char* href); struct box* box_textarea(xmlNode* n, struct css_style* style, struct form* current_form); struct box* box_select(xmlNode * n, struct css_style* style, struct form* current_form); struct formoption* box_option(xmlNode* n, struct css_style* style, struct gui_gadget* current_select); @@ -79,7 +79,7 @@ void box_add_child(struct box * parent, struct box * child) */ struct box * box_create(xmlNode * node, box_type type, struct css_style * style, - const char *href) + char *href) { struct box * box = xcalloc(1, sizeof(struct box)); box->type = type; @@ -106,14 +106,14 @@ struct box * box_create(xmlNode * node, box_type type, struct css_style * style, } -char * tolat1(const xmlChar * s) +char * tolat1(xmlChar * s) { - char *d = xcalloc(strlen((const char*)s) + 1, sizeof(char)); + char *d = xcalloc(strlen((char*) s) + 1, sizeof(char)); char *d0 = d; unsigned int u, chars; while (*s != 0) { - u = sgetu8((const unsigned char*)s, (int*) &chars); + u = sgetu8((unsigned char*) s, (int*) &chars); s += chars; if (u == 0x09 || u == 0x0a || u == 0x0d) *d = ' '; @@ -148,7 +148,7 @@ void xml_to_box(xmlNode * n, struct css_style * parent_style, struct css_stylesheet * stylesheet, struct css_selector ** selector, unsigned int depth, struct box * parent, struct box * inline_container, - const char *href, struct font_set *fonts, + char *href, struct font_set *fonts, struct gui_gadget* current_select, struct formoption* current_option, struct gui_gadget* current_textarea, struct form* current_form, struct page_elements* elements) @@ -165,7 +165,7 @@ struct box * convert_xml_to_box(xmlNode * n, struct css_style * parent_style, struct css_stylesheet * stylesheet, struct css_selector ** selector, unsigned int depth, struct box * parent, struct box * inline_container, - const char *href, struct font_set *fonts, + char *href, struct font_set *fonts, struct gui_gadget* current_select, struct formoption* current_option, struct gui_gadget* current_textarea, struct form* current_form, struct page_elements* elements) @@ -972,7 +972,7 @@ void box_free_box(struct box *box) } } -struct box* box_image(xmlNode * n, struct css_style* style, const char* href) +struct box* box_image(xmlNode * n, struct css_style* style, char* href) { struct box* box = 0; char* s; diff --git a/render/box.h b/render/box.h index aad278f44..78d78d456 100644 --- a/render/box.h +++ b/render/box.h @@ -1,5 +1,5 @@ /** - * $Id: box.h,v 1.18 2003/01/11 17:36:40 monkeyson Exp $ + * $Id: box.h,v 1.19 2003/02/09 12:58:15 bursa Exp $ */ #ifndef _NETSURF_RENDER_BOX_H_ @@ -85,9 +85,9 @@ struct box { struct css_style * style; unsigned long x, y, width, height; unsigned long min_width, max_width; - const char * text; + char * text; unsigned int space : 1; /* 1 <=> followed by a space */ - const char * href; + char * href; unsigned int length; unsigned int columns; struct box * next; @@ -136,7 +136,7 @@ struct page_elements void xml_to_box(xmlNode * n, struct css_style * parent_style, struct css_stylesheet * stylesheet, struct css_selector ** selector, unsigned int depth, struct box * parent, struct box * inline_container, - const char *href, struct font_set *fonts, + char *href, struct font_set *fonts, struct gui_gadget* current_select, struct formoption* current_option, struct gui_gadget* current_textarea, struct form* current_form, struct page_elements* elements); diff --git a/render/css.c b/render/css.c index 8cb983b78..e4a9002b5 100644 --- a/render/css.c +++ b/render/css.c @@ -1,12 +1,12 @@ /** - * $Id: css.c,v 1.12 2002/12/27 20:42:31 bursa Exp $ + * $Id: css.c,v 1.13 2003/02/09 12:58:15 bursa Exp $ */ #include #include #include -#include "css.h" -#include "utils.h" +#include "netsurf/render/css.h" +#include "netsurf/utils/utils.h" /** * internal structures @@ -704,9 +704,9 @@ int main(int argv, char *argc[]) css_parse_stylesheet(s, argc[1]); css_dump_stylesheet(s); -/* r->selectors = 1; */ -/* css_stylesheet_add_rule(s, r); */ -/* puts("********** finding h1:"); + r->selectors = 1; + css_stylesheet_add_rule(s, r); + puts("********** finding h1:"); r = find_rule(s, &sel, 1); if (r) dump_rule(r); @@ -719,9 +719,9 @@ int main(int argv, char *argc[]) css_dump_style(style); } -/* fprintf(stderr, "%x %x\n", r, r2); */ + fprintf(stderr, "%x %x\n", r, r2); -/* struct css_style *s; + struct css_style *s; struct css_selector *sel; s = parse_property_list(argc[1]); diff --git a/render/html.c b/render/html.c new file mode 100644 index 000000000..f500d3405 --- /dev/null +++ b/render/html.c @@ -0,0 +1,156 @@ +/** + * $Id: html.c,v 1.1 2003/02/09 12:58:15 bursa Exp $ + */ + +#include +#include +#include +#include "netsurf/desktop/gui.h" +#include "netsurf/render/html.h" +#include "netsurf/render/layout.h" +#include "netsurf/utils/utils.h" +#include "netsurf/utils/log.h" + + +static void html_title(struct content *c); + + +void html_create(struct content *c) +{ + c->data.html.parser = htmlCreatePushParserCtxt(0, 0, "", 0, 0, XML_CHAR_ENCODING_8859_1); + c->data.html.document = NULL; + c->data.html.markup = NULL; + c->data.html.layout = NULL; + c->data.html.stylesheet = NULL; + c->data.html.style = NULL; + c->data.html.fonts = NULL; +} + + +#define CHUNK 4096 + +void html_process_data(struct content *c, char *data, unsigned long size) +{ + unsigned long x; + for (x = 0; x < size; x += CHUNK) { + htmlParseChunk(c->data.html.parser, data + x, CHUNK, 0); + gui_multitask(); + } +} + + +int html_convert(struct content *c, unsigned int width, unsigned int height) +{ + char* file; + struct css_selector* selector = xcalloc(1, sizeof(struct css_selector)); + + htmlParseChunk(c->data.html.parser, "", 0, 1); + c->data.html.document = c->data.html.parser->myDoc; + /*xmlDebugDumpDocument(stderr, c->data.html.parser->myDoc);*/ + + LOG(("Skipping to html")); + if (c->data.html.document == NULL) { + LOG(("There is no document!")); + return 1; + } + for (c->data.html.markup = c->data.html.document->children; + c->data.html.markup != 0 && c->data.html.markup->type != XML_ELEMENT_NODE; + c->data.html.markup = c->data.html.markup->next) + ; + + if (c->data.html.markup == 0) { + LOG(("No markup")); + return 1; + } + if (stricmp((const char *) c->data.html.markup->name, "html")) { + LOG(("Not html")); + return 1; + } + + html_title(c); + + /* TODO: rewrite stylesheet handling */ + LOG(("Loading CSS")); + file = load(".Resources.CSS"); /*!!! not portable! !!!*/ + c->data.html.stylesheet = css_new_stylesheet(); + LOG(("Parsing stylesheet")); + css_parse_stylesheet(c->data.html.stylesheet, file); + + LOG(("Copying base style")); + c->data.html.style = xcalloc(1, sizeof(struct css_style)); + memcpy(c->data.html.style, &css_base_style, sizeof(struct css_style)); + + LOG(("Creating box")); + c->data.html.layout = xcalloc(1, sizeof(struct box)); + c->data.html.layout->type = BOX_BLOCK; + c->data.html.layout->node = c->data.html.markup; + + c->data.html.fonts = font_new_set(); + + LOG(("XML to box")); + xml_to_box(c->data.html.markup, c->data.html.style, c->data.html.stylesheet, + &selector, 0, c->data.html.layout, 0, 0, c->data.html.fonts, + 0, 0, 0, 0, &c->data.html.elements); + box_dump(c->data.html.layout->children, 0); + + LOG(("Layout document")); + layout_document(c->data.html.layout->children, width); + box_dump(c->data.html.layout->children, 0); + + return 0; +} + + +void html_title(struct content *c) +{ + xmlNode *node = c->data.html.markup; + + c->title = 0; + + while (node != 0) { + if (node->type == XML_ELEMENT_NODE) { + if (stricmp(node->name, "html") == 0) { + node = node->children; + continue; + } + if (stricmp(node->name, "head") == 0) { + node = node->children; + continue; + } + if (stricmp(node->name, "title") == 0) { + c->title = xmlNodeGetContent(node); + return; + } + } + node = node->next; + } +} + + +void html_revive(struct content *c, unsigned int width, unsigned int height) +{ + /* TODO: reload stylesheets and images and fix any pointers to them */ + layout_document(c->data.html.layout->children, width); +} + + +void html_reformat(struct content *c, unsigned int width, unsigned int height) +{ + layout_document(c->data.html.layout->children, width); +} + + +void html_destroy(struct content *c) +{ + LOG(("content %p", c)); + + htmlFreeParserCtxt(c->data.html.parser); + + if (c->data.html.document != 0) + xmlFreeDoc(c->data.html.document); + if (c->data.html.layout != 0) + box_free(c->data.html.layout); + if (c->data.html.fonts != 0) + font_free_set(c->data.html.fonts); + /* TODO: stylesheets */ +} diff --git a/render/html.h b/render/html.h new file mode 100644 index 000000000..1dd9e3a51 --- /dev/null +++ b/render/html.h @@ -0,0 +1,17 @@ +/** + * $Id: html.h,v 1.1 2003/02/09 12:58:15 bursa Exp $ + */ + +#ifndef _NETSURF_RENDER_HTML_H_ +#define _NETSURF_RENDER_HTML_H_ + +#include "netsurf/content/content.h" + +void html_create(struct content *c); +void html_process_data(struct content *c, char *data, unsigned long size); +int html_convert(struct content *c, unsigned int width, unsigned int height); +void html_revive(struct content *c, unsigned int width, unsigned int height); +void html_reformat(struct content *c, unsigned int width, unsigned int height); +void html_destroy(struct content *c); + +#endif diff --git a/render/layout.c b/render/layout.c index a27fdbb30..afc8c25df 100644 --- a/render/layout.c +++ b/render/layout.c @@ -1,5 +1,5 @@ /** - * $Id: layout.c,v 1.32 2003/01/06 23:53:40 bursa Exp $ + * $Id: layout.c,v 1.33 2003/02/09 12:58:15 bursa Exp $ */ #include @@ -8,11 +8,12 @@ #include #include #include "libxml/HTMLparser.h" -#include "netsurf/render/css.h" -#include "netsurf/riscos/font.h" +#include "netsurf/desktop/gui.h" #include "netsurf/render/box.h" -#include "netsurf/render/utils.h" +#include "netsurf/render/css.h" #include "netsurf/render/layout.h" +#include "netsurf/riscos/font.h" +#include "netsurf/utils/utils.h" #include "netsurf/utils/log.h" #define DEBUG_LAYOUT @@ -441,14 +442,14 @@ struct box * layout_line(struct box * first, unsigned long width, unsigned long if (x1 - x0 < x) { /* the last box went over the end */ char * space = 0; - unsigned long w; + unsigned int w; struct box * c2; x = x_previous; if (c->text != 0) space = strchr(c->text, ' '); - if (space != 0 && c->length <= space - c->text) + if (space != 0 && c->length <= (unsigned int) (space - c->text)) /* space after end of string */ space = 0; @@ -457,7 +458,7 @@ struct box * layout_line(struct box * first, unsigned long width, unsigned long if (space == 0) w = c->width; else - w = font_width(c->font, c->text, space - c->text); + w = font_width(c->font, c->text, (unsigned int) (space - c->text)); if (x1 - x0 < x + space_before + w && left == 0 && right == 0 && c == first) { /* first word doesn't fit, but no floats and first on line so force in */ @@ -488,8 +489,8 @@ struct box * layout_line(struct box * first, unsigned long width, unsigned long assert(space != 0); space = font_split(c->font, c->text, c->length, x1 - x0 - x - space_before, &w); - LOG(("'%.*s' %lu %lu (%c) %lu", c->length, c->text, - x1 - x0, space - c->text, *space, w)); + LOG(("'%.*s' %lu %u (%c) %u", (int) c->length, c->text, + (unsigned long) (x1 - x0), space - c->text, *space, w)); c2 = memcpy(xcalloc(1, sizeof(struct box)), c, sizeof(struct box)); c2->text = xstrdup(space + 1); c2->length = c->length - ((space + 1) - c->text); @@ -759,7 +760,7 @@ void calculate_inline_container_widths(struct box *box) word = space + 1, space = strchr(word, ' ')) { width = font_width(child->font, word, - space - word); + (unsigned int) (space - word)); if (min < width) min = width; } width = font_width(child->font, word, strlen(word)); diff --git a/render/textplain.c b/render/textplain.c new file mode 100644 index 000000000..c5407c6f5 --- /dev/null +++ b/render/textplain.c @@ -0,0 +1,52 @@ +/** + * $Id: textplain.c,v 1.1 2003/02/09 12:58:15 bursa Exp $ + */ + +#include +#include +#include +#include "libxml/HTMLparser.h" +#include "netsurf/render/html.h" +#include "netsurf/render/textplain.h" + + +static const char header[] = "
";
+static const char footer[] = "
"; + + +void textplain_create(struct content *c) +{ + html_create(c); + htmlParseChunk(c->data.html.parser, header, sizeof(header), 0); +} + + +void textplain_process_data(struct content *c, char *data, unsigned long size) +{ + html_process_data(c, data, size); +} + + +int textplain_convert(struct content *c, unsigned int width, unsigned int height) +{ + htmlParseChunk(c->data.html.parser, footer, sizeof(footer), 0); + return html_convert(c, width, height); +} + + +void textplain_revive(struct content *c, unsigned int width, unsigned int height) +{ + html_revive(c, width, height); +} + + +void textplain_reformat(struct content *c, unsigned int width, unsigned int height) +{ + html_reformat(c, width, height); +} + + +void textplain_destroy(struct content *c) +{ + html_destroy(c); +} diff --git a/render/textplain.h b/render/textplain.h new file mode 100644 index 000000000..7221ab0b8 --- /dev/null +++ b/render/textplain.h @@ -0,0 +1,17 @@ +/** + * $Id: textplain.h,v 1.1 2003/02/09 12:58:15 bursa Exp $ + */ + +#ifndef _NETSURF_RENDER_TEXTPLAIN_H_ +#define _NETSURF_RENDER_TEXTPLAIN_H_ + +#include "netsurf/content/content.h" + +void textplain_create(struct content *c); +void textplain_process_data(struct content *c, char *data, unsigned long size); +int textplain_convert(struct content *c, unsigned int width, unsigned int height); +void textplain_revive(struct content *c, unsigned int width, unsigned int height); +void textplain_reformat(struct content *c, unsigned int width, unsigned int height); +void textplain_destroy(struct content *c); + +#endif -- cgit v1.2.3