mirror of
https://github.com/netsurf-browser/netsurf
synced 2025-01-22 02:12:10 +03:00
[project @ 2004-03-24 23:51:08 by jmb]
Text Export support. svn path=/import/netsurf/; revision=665
This commit is contained in:
parent
b23bc94cb9
commit
7d0b144391
@ -13,6 +13,7 @@ Save:Save
|
||||
Export:Export
|
||||
ExportAs:Export as
|
||||
Draw:Draw
|
||||
Text:Text
|
||||
Print:Print...
|
||||
Selection:Selection
|
||||
Copy:Copy to clipboard
|
||||
@ -77,3 +78,4 @@ SelectMenu:Select
|
||||
|
||||
SaveSource:Source
|
||||
SaveDraw:Webpage
|
||||
SaveText:Webpage
|
||||
|
@ -13,6 +13,7 @@ Save:Sauver
|
||||
Export:Exporter
|
||||
ExportAs:Exporter sous
|
||||
Draw:Draw
|
||||
Text:Text
|
||||
Print:Imprimer...
|
||||
Selection:Sélection
|
||||
Copy:Copier vers le presse papier
|
||||
@ -77,3 +78,4 @@ SelectMenu:S
|
||||
|
||||
SaveSource:Source
|
||||
SaveDraw:PageWeb
|
||||
SaveText:PageWeb
|
||||
|
2
makefile
2
makefile
@ -19,7 +19,7 @@ OBJECTS = $(OBJECTS_COMMON) \
|
||||
draw.o gif.o jpeg.o plugin.o png.o sprite.o \
|
||||
about.o filetype.o font.o uri.o url_protocol.o history.o \
|
||||
version.o thumbnail.o \
|
||||
save.o save_complete.o save_draw.o schedule.o
|
||||
save.o save_complete.o save_draw.o save_text.o schedule.o
|
||||
OBJECTS_DEBUG = $(OBJECTS_COMMON) \
|
||||
netsurfd.o \
|
||||
options.o filetyped.o fontd.o
|
||||
|
@ -31,7 +31,7 @@ extern bool gui_redraw_debug;
|
||||
extern gui_window *current_gui;
|
||||
|
||||
typedef enum { GUI_BROWSER_WINDOW, GUI_DOWNLOAD_WINDOW } gui_window_type;
|
||||
typedef enum { GUI_SAVE_SOURCE, GUI_SAVE_DRAW } gui_save_type;
|
||||
typedef enum { GUI_SAVE_SOURCE, GUI_SAVE_DRAW, GUI_SAVE_TEXT } gui_save_type;
|
||||
extern gui_save_type gui_current_save_type;
|
||||
typedef enum { GUI_DRAG_SELECTION, GUI_DRAG_DOWNLOAD_SAVE,
|
||||
GUI_DRAG_SAVE } gui_drag_type;
|
||||
|
@ -48,10 +48,11 @@ wimp_menu *iconbar_menu = (wimp_menu *) & (wimp_MENU(4)) {
|
||||
int iconbar_menu_height = 4 * 44;
|
||||
|
||||
/* browser window menu structure - based on Style Guide */
|
||||
static wimp_MENU(1) export_menu = {
|
||||
static wimp_MENU(2) export_menu = {
|
||||
{ "ExportAs" }, 7,2,7,0, 200, 44, 0,
|
||||
{
|
||||
{ wimp_MENU_LAST | wimp_MENU_GIVE_WARNING, wimp_NO_SUB_MENU, DEFAULT_FLAGS, { "Draw" } }
|
||||
{ wimp_MENU_GIVE_WARNING, wimp_NO_SUB_MENU, DEFAULT_FLAGS, { "Draw" } },
|
||||
{ wimp_MENU_LAST | wimp_MENU_GIVE_WARNING, wimp_NO_SUB_MENU, DEFAULT_FLAGS, { "Text" } }
|
||||
}
|
||||
};
|
||||
static wimp_menu *browser_export_menu = (wimp_menu *) &export_menu;
|
||||
@ -125,6 +126,7 @@ void ro_gui_menus_init(void)
|
||||
iconbar_menu->entries[0].sub_menu = (wimp_menu *) dialog_info;
|
||||
browser_page_menu->entries[1].sub_menu = (wimp_menu *) dialog_saveas;
|
||||
browser_export_menu->entries[0].sub_menu = (wimp_menu *) dialog_saveas;
|
||||
browser_export_menu->entries[1].sub_menu = (wimp_menu *) dialog_saveas;
|
||||
browser_view_menu->entries[0].sub_menu = (wimp_menu *) dialog_zoom;
|
||||
}
|
||||
|
||||
@ -302,6 +304,14 @@ void ro_gui_menu_warning(wimp_message_menu_warning *warning)
|
||||
ICON_SAVE_PATH,
|
||||
messages_get("SaveDraw"));
|
||||
break;
|
||||
case 1: /* Export as -> Text */
|
||||
gui_current_save_type = GUI_SAVE_TEXT;
|
||||
ro_gui_set_icon_string(dialog_saveas,
|
||||
ICON_SAVE_ICON, "file_fff");
|
||||
ro_gui_set_icon_string(dialog_saveas,
|
||||
ICON_SAVE_PATH,
|
||||
messages_get("SaveText"));
|
||||
break;
|
||||
|
||||
case -1:
|
||||
default: /* Save */
|
||||
|
@ -15,6 +15,7 @@
|
||||
#include "oslib/wimp.h"
|
||||
#include "netsurf/riscos/gui.h"
|
||||
#include "netsurf/riscos/save_draw.h"
|
||||
#include "netsurf/riscos/save_text.h"
|
||||
#include "netsurf/utils/log.h"
|
||||
#include "netsurf/utils/messages.h"
|
||||
#include "netsurf/utils/utils.h"
|
||||
@ -124,6 +125,12 @@ void ro_gui_save_datasave_ack(wimp_message *message)
|
||||
return;
|
||||
save_as_draw(c, path);
|
||||
break;
|
||||
|
||||
case GUI_SAVE_TEXT:
|
||||
if (!c)
|
||||
return;
|
||||
save_as_text(c, path);
|
||||
break;
|
||||
}
|
||||
|
||||
wimp_create_menu(wimp_CLOSE_MENU, 0, 0);
|
||||
|
130
riscos/save_text.c
Normal file
130
riscos/save_text.c
Normal file
@ -0,0 +1,130 @@
|
||||
/*
|
||||
* 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 <stdbool.h>
|
||||
#include <string.h>
|
||||
|
||||
#include "libxml/HTMLtree.h"
|
||||
|
||||
#include "oslib/osfile.h"
|
||||
|
||||
#include "netsurf/utils/config.h"
|
||||
#include "netsurf/content/content.h"
|
||||
#include "netsurf/riscos/save_text.h"
|
||||
#include "netsurf/utils/log.h"
|
||||
#include "netsurf/utils/utils.h"
|
||||
|
||||
#ifdef WITH_TEXT_EXPORT
|
||||
|
||||
static void extract_text(xmlDoc *doc);
|
||||
static void extract_text_from_tree(xmlNode *n);
|
||||
|
||||
static char *buffer = 0;
|
||||
static int output_size = 0;
|
||||
|
||||
void save_as_text(struct content *c, char *path) {
|
||||
|
||||
htmlParserCtxtPtr toSave;
|
||||
|
||||
if (c->type != CONTENT_HTML) {
|
||||
return;
|
||||
}
|
||||
|
||||
/* allocate a buffer the same size as the source
|
||||
* the output is guaranteed to be less than this
|
||||
*/
|
||||
buffer = xcalloc(c->source_size, sizeof(char));
|
||||
|
||||
toSave = htmlCreateMemoryParserCtxt(c->source_data, c->source_size);
|
||||
htmlParseDocument(toSave);
|
||||
|
||||
extract_text(toSave->myDoc);
|
||||
|
||||
if (output_size > 0) {
|
||||
xosfile_save_stamped(path, 0xfff, (byte*)buffer,
|
||||
(byte*)buffer+output_size);
|
||||
}
|
||||
|
||||
xmlFreeDoc(toSave->myDoc);
|
||||
htmlFreeParserCtxt(toSave);
|
||||
xfree(buffer);
|
||||
}
|
||||
|
||||
void extract_text(xmlDoc *doc)
|
||||
{
|
||||
xmlNode *html;
|
||||
|
||||
/* find the html element */
|
||||
for (html = doc->children;
|
||||
html!=0 && html->type != XML_ELEMENT_NODE;
|
||||
html = html->next)
|
||||
;
|
||||
if (html == 0 || strcmp((const char*)html->name, "html") != 0) {
|
||||
return;
|
||||
}
|
||||
|
||||
extract_text_from_tree(html);
|
||||
}
|
||||
|
||||
void extract_text_from_tree(xmlNode *n)
|
||||
{
|
||||
xmlNode *this;
|
||||
char *text;
|
||||
int len = 0;
|
||||
int need_nl = 0;
|
||||
|
||||
if (n->type == XML_ELEMENT_NODE) {
|
||||
if (strcmp(n->name, "dl") == 0 ||
|
||||
strcmp(n->name, "h1") == 0 ||
|
||||
strcmp(n->name, "h2") == 0 ||
|
||||
strcmp(n->name, "h3") == 0 ||
|
||||
strcmp(n->name, "ol") == 0 ||
|
||||
strcmp(n->name, "title") == 0 ||
|
||||
strcmp(n->name, "ul") == 0) {
|
||||
need_nl = 2;
|
||||
}
|
||||
else if (strcmp(n->name, "applet") == 0 ||
|
||||
strcmp(n->name, "br") == 0 ||
|
||||
strcmp(n->name, "div") == 0 ||
|
||||
strcmp(n->name, "dt") == 0 ||
|
||||
strcmp(n->name, "h4") == 0 ||
|
||||
strcmp(n->name, "h5") == 0 ||
|
||||
strcmp(n->name, "h6") == 0 ||
|
||||
strcmp(n->name, "li") == 0 ||
|
||||
strcmp(n->name, "object") == 0 ||
|
||||
strcmp(n->name, "p") == 0 ||
|
||||
strcmp(n->name, "tr") == 0) {
|
||||
need_nl = 1;
|
||||
}
|
||||
/* do nothing, we just recurse through these nodes */
|
||||
}
|
||||
else if (n->type == XML_TEXT_NODE) {
|
||||
text = squash_tolat1(n->content);
|
||||
len = strlen(text);
|
||||
strcat(buffer, text);
|
||||
output_size += len;
|
||||
xfree(text);
|
||||
return;
|
||||
}
|
||||
else {
|
||||
return;
|
||||
}
|
||||
|
||||
/* now recurse */
|
||||
for (this = n->children; this != 0; this = this->next) {
|
||||
extract_text_from_tree(this);
|
||||
}
|
||||
|
||||
if (need_nl) {
|
||||
for (len = 0; len != need_nl; len++) {
|
||||
strcat(buffer, "\n");
|
||||
output_size += 1;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#endif
|
15
riscos/save_text.h
Normal file
15
riscos/save_text.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_TEXT_H_
|
||||
#define _NETSURF_RISCOS_SAVE_TEXT_H_
|
||||
|
||||
struct content;
|
||||
|
||||
void save_as_text(struct content *c, char *path);
|
||||
|
||||
#endif
|
@ -24,6 +24,7 @@
|
||||
#include "netsurf/riscos/options.h"
|
||||
#include "netsurf/riscos/save_complete.h"
|
||||
#include "netsurf/riscos/save_draw.h"
|
||||
#include "netsurf/riscos/save_text.h"
|
||||
#include "netsurf/riscos/theme.h"
|
||||
#include "netsurf/riscos/thumbnail.h"
|
||||
#include "netsurf/utils/log.h"
|
||||
@ -785,6 +786,11 @@ bool ro_gui_window_keypress(gui_window *g, int key, bool toolbar)
|
||||
#endif
|
||||
);
|
||||
return true;
|
||||
#ifdef WITH_TEXT_EXPORT
|
||||
case wimp_KEY_CONTROL + wimp_KEY_F3:
|
||||
/* save_as_text(g->data.browser.bw->current_content);*/
|
||||
return true;
|
||||
#endif
|
||||
#ifdef WITH_SAVE_COMPLETE
|
||||
case wimp_KEY_SHIFT + wimp_KEY_F3:
|
||||
save_complete(g->data.browser.bw->current_content);
|
||||
|
@ -48,6 +48,7 @@
|
||||
/* Export modules */
|
||||
#define WITH_SAVE_COMPLETE
|
||||
#define WITH_DRAW_EXPORT
|
||||
#define WITH_TEXT_EXPORT
|
||||
|
||||
#endif
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user