From 02674693069358fc9f59700ea150d3811281f296 Mon Sep 17 00:00:00 2001 From: James Bursa Date: Fri, 11 Apr 2003 21:06:51 +0000 Subject: [project @ 2003-04-11 21:06:51 by bursa] Memory usage and CSS fixes. svn path=/import/netsurf/; revision=122 --- render/box.c | 31 ++++--------------------------- render/html.c | 49 +++++++++++++++++++++++++++++++++---------------- 2 files changed, 37 insertions(+), 43 deletions(-) (limited to 'render') diff --git a/render/box.c b/render/box.c index ad139f7c2..a94088fa6 100644 --- a/render/box.c +++ b/render/box.c @@ -1,5 +1,5 @@ /** - * $Id: box.c,v 1.39 2003/04/10 21:44:45 bursa Exp $ + * $Id: box.c,v 1.40 2003/04/11 21:06:51 bursa Exp $ */ #include @@ -24,7 +24,6 @@ static void box_add_child(struct box * parent, struct box * child); static struct box * box_create(box_type type, struct css_style * style, char *href); -static char * tolat1(xmlChar * s); static struct box * convert_xml_to_box(xmlNode * n, struct css_style * parent_style, struct content ** stylesheet, unsigned int stylesheet_count, struct css_selector ** selector, unsigned int depth, @@ -105,28 +104,6 @@ struct box * box_create(box_type type, struct css_style * style, } -char * tolat1(xmlChar * s) -{ - char *d = xcalloc(strlen((char*) s) + 1, sizeof(char)); - char *d0 = d; - unsigned int u, chars; - - while (*s != 0) { - u = sgetu8((unsigned char*) s, (int*) &chars); - s += chars; - if (u == 0x09 || u == 0x0a || u == 0x0d) - *d = ' '; - else if ((0x20 <= u && u <= 0x7f) || (0xa0 <= u && u <= 0xff)) - *d = u; - else - *d = '?'; - d++; - } - *d = 0; - - return d0; -} - /** * make a box tree with style data from an xml tree * @@ -212,7 +189,7 @@ struct box * convert_xml_to_box(xmlNode * n, struct css_style * parent_style, add_img_element(elements, box->img);*/ if (style->display == CSS_DISPLAY_INLINE) { if ((s = (char *) xmlGetProp(n, (const xmlChar *) "alt"))) { - text = squash_whitespace(tolat1(s)); + text = squash_tolat1(s); xfree(s); } } @@ -220,7 +197,7 @@ struct box * convert_xml_to_box(xmlNode * n, struct css_style * parent_style, } else if (strcmp((const char *) n->name, "textarea") == 0) { char * content = xmlNodeGetContent(n); - char * thistext = squash_whitespace(tolat1(content)); /* squash ? */ + char * thistext = squash_tolat1(content); /* squash ? */ LOG(("textarea")); box = box_textarea(n, style, current_form); current_textarea = box->gadget; @@ -255,7 +232,7 @@ struct box * convert_xml_to_box(xmlNode * n, struct css_style * parent_style, style->display = CSS_DISPLAY_BLOCK; } else if (n->type == XML_TEXT_NODE) { - text = squash_whitespace(tolat1(n->content)); + text = squash_tolat1(n->content); } if (text != 0) { diff --git a/render/html.c b/render/html.c index c6b96719a..f3f547e88 100644 --- a/render/html.c +++ b/render/html.c @@ -1,5 +1,5 @@ /** - * $Id: html.c,v 1.12 2003/04/10 21:44:45 bursa Exp $ + * $Id: html.c,v 1.13 2003/04/11 21:06:51 bursa Exp $ */ #include @@ -82,13 +82,13 @@ int html_convert(struct content *c, unsigned int width, unsigned int height) head != 0 && head->type != XML_ELEMENT_NODE; head = head->next) ; - if (head == 0 || strcmp((const char *) head->name, "head") != 0) { + if (strcmp((const char *) head->name, "head") != 0) { + head = 0; LOG(("head element not found")); - xmlFreeDoc(document); - return 1; } - html_title(c, head); + if (head != 0) + html_title(c, head); /* get stylesheets */ html_find_stylesheets(c, head); @@ -137,8 +137,19 @@ int html_convert(struct content *c, unsigned int width, unsigned int height) &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);*/ + + /* XML tree and stylesheets not required past this point */ xmlFreeDoc(document); + cache_free(c->data.html.stylesheet_content[0]); + for (i = 1; i != c->data.html.stylesheet_count; i++) { + if (c->data.html.stylesheet_content[i] != 0) + cache_free(c->data.html.stylesheet_content[i]); + xfree(c->data.html.stylesheet_url[i]); + } + xfree(c->data.html.stylesheet_url); + xfree(c->data.html.stylesheet_content); + c->status_callback(c->status_p, "Formatting document"); LOG(("Layout document")); layout_document(c->data.html.layout->children, width); @@ -185,12 +196,15 @@ void html_convert_css_callback(fetchcache_msg msg, struct content *css, void html_title(struct content *c, xmlNode *head) { xmlNode *node; + xmlChar *title; c->title = 0; for (node = head->children; node != 0; node = node->next) { if (strcmp(node->name, "title") == 0) { - c->title = xmlNodeGetContent(node); + title = xmlNodeGetContent(node); + c->title = squash_tolat1(title); + free(title); return; } } @@ -207,6 +221,9 @@ void html_find_stylesheets(struct content *c, xmlNode *head) c->data.html.stylesheet_url[0] = "file:///%3CNetSurf$Dir%3E/Resources/CSS"; c->data.html.stylesheet_count = 1; + if (head == 0) + return; + for (node = head->children; node != 0; node = node->next) { if (strcmp(node->name, "link") == 0) { /* rel='stylesheet' */ @@ -218,18 +235,19 @@ void html_find_stylesheets(struct content *c, xmlNode *head) } free(rel); - /* type='text/css' */ - if (!(type = (char *) xmlGetProp(node, (const xmlChar *) "type"))) - continue; - if (strcmp(type, "text/css") != 0) { + /* type='text/css' or not present */ + if ((type = (char *) xmlGetProp(node, (const xmlChar *) "type"))) { + if (strcmp(type, "text/css") != 0) { + free(type); + continue; + } free(type); - continue; } - free(type); - /* media='screen' or not present */ + /* media contains 'screen' or 'all' or not present */ if ((media = (char *) xmlGetProp(node, (const xmlChar *) "media"))) { - if (strcasecmp(media, "screen") != 0) { + if (strstr(media, "screen") == 0 && + strstr(media, "all") == 0) { free(media); continue; } @@ -255,7 +273,7 @@ void html_find_stylesheets(struct content *c, xmlNode *head) void html_revive(struct content *c, unsigned int width, unsigned int height) { - /* TODO: reload stylesheets and images and fix any pointers to them */ + /* TODO: reload images and fix any pointers to them */ layout_document(c->data.html.layout->children, width); c->width = c->data.html.layout->children->width; c->height = c->data.html.layout->children->height; @@ -280,5 +298,4 @@ void html_destroy(struct content *c) font_free_set(c->data.html.fonts); if (c->title != 0) xfree(c->title); - /* TODO: stylesheets */ } -- cgit v1.2.3