mirror of
https://github.com/netsurf-browser/netsurf
synced 2024-12-22 04:02:34 +03:00
[project @ 2004-02-17 12:41:38 by jmb]
Begin save complete support. Fix memory leak when using Select PNG renderer. (commented out lines can probably removed) svn path=/import/netsurf/; revision=556
This commit is contained in:
parent
8cece1f41f
commit
6839622183
@ -889,7 +889,7 @@ INCLUDE_FILE_PATTERNS =
|
||||
# or name=definition (no spaces). If the definition and the = are
|
||||
# omitted =1 is assumed.
|
||||
|
||||
PREDEFINED = riscos CSS_INTERNALS WITH_POST WITH_DRAW WITH_GIF WITH_JPEG WITH_PNG WITH_SPRITE WITH_PLUGIN WITH_FRAMES WITH_AUTH WITH_COOKIES WITH_ABOUT WITH_URI WITH_URL WITH_DRAW_EXPORT
|
||||
PREDEFINED = riscos CSS_INTERNALS WITH_POST WITH_DRAW WITH_GIF WITH_JPEG WITH_PNG WITH_SPRITE WITH_PLUGIN WITH_FRAMES WITH_AUTH WITH_COOKIES WITH_ABOUT WITH_URI WITH_URL WITH_DRAW_EXPORT WITH_SAVE_COMPLETE
|
||||
|
||||
# If the MACRO_EXPANSION and EXPAND_ONLY_PREDEF tags are set to YES then
|
||||
# this tag can be used to specify a list of macro names that should be expanded.
|
||||
|
2
makefile
2
makefile
@ -18,7 +18,7 @@ OBJECTS = $(OBJECTS_COMMON) \
|
||||
textselection.o theme.o window.o \
|
||||
draw.o gif.o jpeg.o plugin.o png.o sprite.o \
|
||||
about.o filetype.o font.o uri.o url.o history.o \
|
||||
version.o save_draw.o
|
||||
version.o save_draw.o save_complete.o
|
||||
OBJECTS_DEBUG = $(OBJECTS_COMMON) \
|
||||
netsurfd.o \
|
||||
options.o filetyped.o fontd.o
|
||||
|
@ -128,19 +128,9 @@ int html_convert(struct content *c, unsigned int width, unsigned int height)
|
||||
xml_to_box(html, c);
|
||||
/*box_dump(c->data.html.layout->children, 0);*/
|
||||
|
||||
/* XML tree and stylesheets not required past this point */
|
||||
/* XML tree not required past this point */
|
||||
xmlFreeDoc(document);
|
||||
|
||||
content_remove_user(c->data.html.stylesheet_content[0],
|
||||
html_convert_css_callback, c, 0);
|
||||
if (c->data.html.stylesheet_content[1] != 0)
|
||||
content_destroy(c->data.html.stylesheet_content[1]);
|
||||
for (i = 2; i != c->data.html.stylesheet_count; i++)
|
||||
if (c->data.html.stylesheet_content[i] != 0)
|
||||
content_remove_user(c->data.html.stylesheet_content[i],
|
||||
html_convert_css_callback, c, (void*)i);
|
||||
xfree(c->data.html.stylesheet_content);
|
||||
|
||||
/* layout the box tree */
|
||||
sprintf(c->status_message, "Formatting document");
|
||||
content_broadcast(c, CONTENT_MSG_STATUS, 0);
|
||||
@ -660,6 +650,18 @@ void html_destroy(struct content *c)
|
||||
unsigned int i;
|
||||
LOG(("content %p", c));
|
||||
|
||||
/* Remove stylesheets */
|
||||
content_remove_user(c->data.html.stylesheet_content[0],
|
||||
html_convert_css_callback, c, 0);
|
||||
if (c->data.html.stylesheet_content[1] != 0)
|
||||
content_destroy(c->data.html.stylesheet_content[1]);
|
||||
for (i = 2; i != c->data.html.stylesheet_count; i++)
|
||||
if (c->data.html.stylesheet_content[i] != 0)
|
||||
content_remove_user(c->data.html.stylesheet_content[i],
|
||||
html_convert_css_callback, c, (void*)i);
|
||||
xfree(c->data.html.stylesheet_content);
|
||||
|
||||
/* and objects */
|
||||
for (i = 0; i != c->data.html.object_count; i++) {
|
||||
LOG(("object %i %p", i, c->data.html.object[i].content));
|
||||
if (c->data.html.object[i].content != 0)
|
||||
|
19
riscos/png.c
19
riscos/png.c
@ -69,11 +69,11 @@ void nspng_init(void)
|
||||
void nspng_create(struct content *c, const char *params[])
|
||||
{
|
||||
#ifndef NO_IFC
|
||||
if (imagefileconvert) {
|
||||
// if (imagefileconvert) {
|
||||
c->data.other.data = xcalloc(0, 1);
|
||||
c->data.other.length = 0;
|
||||
return;
|
||||
}
|
||||
// return;
|
||||
// }
|
||||
#endif
|
||||
|
||||
c->data.png.sprite_area = 0;
|
||||
@ -97,14 +97,14 @@ void nspng_create(struct content *c, const char *params[])
|
||||
void nspng_process_data(struct content *c, char *data, unsigned long size)
|
||||
{
|
||||
#ifndef NO_IFC
|
||||
if (imagefileconvert) {
|
||||
// if (imagefileconvert) {
|
||||
c->data.png.data = xrealloc(c->data.png.data,
|
||||
c->data.png.length + size);
|
||||
memcpy(c->data.png.data + c->data.png.length, data, size);
|
||||
c->data.png.length += size;
|
||||
c->size += size;
|
||||
return;
|
||||
}
|
||||
// c->size += size;
|
||||
// return;
|
||||
// }
|
||||
#endif
|
||||
|
||||
if (setjmp(png_jmpbuf(c->data.png.png))) {
|
||||
@ -366,6 +366,11 @@ void nspng_destroy(struct content *c)
|
||||
{
|
||||
xfree(c->title);
|
||||
xfree(c->data.png.sprite_area);
|
||||
#ifndef NO_IFC
|
||||
// if (imagefileconvert) {
|
||||
xfree(c->data.png.data);
|
||||
// }
|
||||
#endif
|
||||
}
|
||||
|
||||
|
||||
|
174
riscos/save_complete.c
Normal file
174
riscos/save_complete.c
Normal file
@ -0,0 +1,174 @@
|
||||
/*
|
||||
* This file is part of NetSurf, http://netsurf.sourceforge.net/
|
||||
* Licensed under the GNU General Public License,
|
||||
* http://www.opensource.org/licenses/gpl-license
|
||||
* Copyright 2004 John M Bell <jmb202@ecs.soton.ac.uk>
|
||||
*/
|
||||
|
||||
#include <string.h>
|
||||
|
||||
#include <unixlib/local.h> /* for __riscosify */
|
||||
|
||||
#include <uri.h> /* possibly just have accessor methods in utils.c */
|
||||
|
||||
#include "oslib/osfile.h"
|
||||
|
||||
#include "netsurf/utils/config.h"
|
||||
#include "netsurf/content/content.h"
|
||||
#include "netsurf/css/css.h"
|
||||
#include "netsurf/render/form.h"
|
||||
#include "netsurf/render/layout.h"
|
||||
#include "netsurf/riscos/save_complete.h"
|
||||
#include "netsurf/utils/log.h"
|
||||
#include "netsurf/utils/utils.h"
|
||||
|
||||
/** \todo Save out CSS. */
|
||||
|
||||
#ifdef WITH_SAVE_COMPLETE
|
||||
|
||||
char* get_filename(char * url);
|
||||
|
||||
/* this is temporary. */
|
||||
const char * const SAVE_PATH = "<NetSurf$Dir>.savetest.";
|
||||
const char * const OBJ_DIR = "_files";
|
||||
|
||||
/** \todo this will probably want to take a filename */
|
||||
void save_complete(struct content *c) {
|
||||
|
||||
struct box *box;
|
||||
char *fname = 0, *spath, *ofname;
|
||||
unsigned int i;
|
||||
|
||||
if (c->type != CONTENT_HTML) {
|
||||
return;
|
||||
}
|
||||
|
||||
fname = get_filename(c->data.html.base_url);
|
||||
|
||||
if (!fname) { /* no path -> exit */
|
||||
return;
|
||||
}
|
||||
|
||||
spath = xcalloc(strlen(SAVE_PATH)+strlen(OBJ_DIR)+strlen(fname)+50,
|
||||
sizeof(char));
|
||||
|
||||
sprintf(spath, "%s%s%s", SAVE_PATH, fname, OBJ_DIR);
|
||||
xosfile_create_dir(spath, 77);
|
||||
|
||||
/* save stylesheets, ignoring the base sheet and <style> elements */
|
||||
LOG(("%d", c->data.html.stylesheet_count));
|
||||
for (i=2; i!=c->data.html.stylesheet_count; i++) {
|
||||
if (c->data.html.stylesheet_content[i] == 0) {
|
||||
continue;
|
||||
}
|
||||
|
||||
LOG(("'%s'", c->data.html.stylesheet_content[i]->url));
|
||||
/* TODO - the rest of this ;) */
|
||||
|
||||
// ofname = get_filename(c->data.html.stylesheet_content[i]->url);
|
||||
// sprintf(spath, "%s%s%s.%s", SAVE_PATH, fname, OBJ_DIR, ofname);
|
||||
LOG(("'%s'", spath));
|
||||
// xosfile_save_stamped(spath, 0xf79, c->data.html.stylesheet_content[i]->data.css.data, c->data.html.stylesheet_content[i]->data.css.data + c->data.html.stylesheet_content[i]->data.css.length);
|
||||
|
||||
// xfree(ofname);
|
||||
}
|
||||
|
||||
/* save objects */
|
||||
for (i=0; i!=c->data.html.object_count; i++) {
|
||||
|
||||
/* skip difficult content types */
|
||||
if (c->data.html.object[i].content->type >= CONTENT_PLUGIN) {
|
||||
continue;
|
||||
}
|
||||
|
||||
ofname = get_filename(c->data.html.object[i].url);
|
||||
sprintf(spath, "%s%s%s.%s", SAVE_PATH, fname, OBJ_DIR, ofname);
|
||||
|
||||
switch(c->data.html.object[i].content->type) {
|
||||
case CONTENT_HTML:
|
||||
xosfile_save_stamped(spath, 0xfaf, c->data.html.object[i].content->data.html.source, c->data.html.object[i].content->data.html.source + c->data.html.object[i].content->data.html.length);
|
||||
break;
|
||||
/*
|
||||
case CONTENT_TEXTPLAIN:
|
||||
break;
|
||||
case CONTENT_CSS:
|
||||
xosfile_save_stamped(spath, 0xf79, c->data.html.object[i].content->data.css.data, c->data.html.object[i].content->data.css.data + c->data.html.object[i].content->data.css.length);
|
||||
break;
|
||||
*/
|
||||
case CONTENT_JPEG:
|
||||
xosfile_save_stamped(spath, 0xc85, c->data.html.object[i].content->data.jpeg.data, (char*)c->data.html.object[i].content->data.jpeg.data + c->data.html.object[i].content->data.jpeg.length);
|
||||
break;
|
||||
case CONTENT_PNG:
|
||||
xosfile_save_stamped(spath, 0xb60, c->data.html.object[i].content->data.png.data, c->data.html.object[i].content->data.png.data + c->data.html.object[i].content->data.png.length);
|
||||
break;
|
||||
case CONTENT_GIF:
|
||||
xosfile_save_stamped(spath, 0x695, c->data.html.object[i].content->data.gif.data, c->data.html.object[i].content->data.gif.data + c->data.html.object[i].content->data.gif.length);
|
||||
break;
|
||||
case CONTENT_SPRITE:
|
||||
xosfile_save_stamped(spath, 0xff9, c->data.html.object[i].content->data.sprite.data, (char*)c->data.html.object[i].content->data.sprite.data + c->data.html.object[i].content->data.sprite.length);
|
||||
break;
|
||||
case CONTENT_DRAW:
|
||||
xosfile_save_stamped(spath, 0xaff, c->data.html.object[i].content->data.draw.data, (char*)c->data.html.object[i].content->data.draw.data + c->data.html.object[i].content->data.draw.length);
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
xfree(ofname);
|
||||
}
|
||||
|
||||
/** \todo URL rewriting */
|
||||
|
||||
/* save the html file out last of all (allows url rewriting first) */
|
||||
sprintf(spath, "%s%s", SAVE_PATH, fname);
|
||||
xosfile_save_stamped(spath, 0xfaf,
|
||||
c->data.html.source,
|
||||
c->data.html.source + c->data.html.length);
|
||||
|
||||
xfree(spath);
|
||||
xfree(fname);
|
||||
}
|
||||
|
||||
char* get_filename(char * url) {
|
||||
|
||||
char *ret = 0, *offs;
|
||||
uri_t *uri;
|
||||
|
||||
uri = uri_alloc(url, (int)strlen(url));
|
||||
|
||||
if (!uri) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
if (uri->path) {
|
||||
/* Two possible cases here:
|
||||
* a) no page name given (eg http://www.blah.com/) -> index.html
|
||||
* b) page name given
|
||||
*/
|
||||
/* case a */
|
||||
if (strlen(uri->path) == 0) {
|
||||
ret = xstrdup("index.html");
|
||||
}
|
||||
/* case b */
|
||||
else {
|
||||
offs = strrchr(uri->path, '/');
|
||||
if (!offs) {
|
||||
ret = xstrdup(uri->path);
|
||||
}
|
||||
else {
|
||||
ret = xstrdup(offs+1);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
uri_free(uri);
|
||||
|
||||
offs = xcalloc(strlen(ret)+1, sizeof(char));
|
||||
|
||||
__riscosify(ret, 0, 0, offs, strlen(ret)+1, 0);
|
||||
|
||||
xfree(ret);
|
||||
|
||||
return offs;
|
||||
}
|
||||
#endif
|
15
riscos/save_complete.h
Normal file
15
riscos/save_complete.h
Normal file
@ -0,0 +1,15 @@
|
||||
/*
|
||||
* This file is part of NetSurf, http://netsurf.sourceforge.net/
|
||||
* Licensed under the GNU General Public License,
|
||||
* http://www.opensource.org/licenses/gpl-license
|
||||
* Copyright 2004 John M Bell <jmb202@ecs.soton.ac.uk>
|
||||
*/
|
||||
|
||||
#ifndef _NETSURF_RISCOS_SAVE_COMPLETE_H_
|
||||
#define _NETSURF_RISCOS_SAVE_COMPLETE_H_
|
||||
|
||||
struct content;
|
||||
|
||||
void save_complete(struct content *c);
|
||||
|
||||
#endif
|
@ -20,6 +20,7 @@
|
||||
#include "netsurf/utils/config.h"
|
||||
#include "netsurf/riscos/constdata.h"
|
||||
#include "netsurf/riscos/gui.h"
|
||||
#include "netsurf/riscos/save_complete.h"
|
||||
#include "netsurf/riscos/save_draw.h"
|
||||
#include "netsurf/riscos/theme.h"
|
||||
#include "netsurf/utils/log.h"
|
||||
@ -742,10 +743,16 @@ bool ro_gui_window_keypress(gui_window *g, int key, bool toolbar)
|
||||
clean_cookiejar();
|
||||
#endif
|
||||
return true;
|
||||
|
||||
#ifdef WITH_SAVE_COMPLETE
|
||||
case wimp_KEY_SHIFT + wimp_KEY_F3:
|
||||
save_complete(g->data.browser.bw->current_content);
|
||||
return true;
|
||||
#endif
|
||||
#ifdef WITH_DRAW_EXPORT
|
||||
case wimp_KEY_SHIFT + wimp_KEY_CONTROL + wimp_KEY_F3:
|
||||
save_as_draw(g->data.browser.bw->current_content);
|
||||
return true;
|
||||
#endif
|
||||
|
||||
case wimp_KEY_RETURN:
|
||||
if (!toolbar)
|
||||
|
@ -46,6 +46,7 @@
|
||||
#define WITH_URL
|
||||
|
||||
/* Export modules */
|
||||
#define WITH_SAVE_COMPLETE
|
||||
#define WITH_DRAW_EXPORT
|
||||
|
||||
#endif
|
||||
|
Loading…
Reference in New Issue
Block a user