2003-06-30 16:44:03 +04:00
|
|
|
/*
|
2006-02-13 02:07:28 +03:00
|
|
|
* Copyright 2006 James Bursa <bursa@users.sourceforge.net>
|
2006-02-16 02:09:55 +03:00
|
|
|
* Copyright 2006 Adrian Lees <adrianl@users.sourceforge.net>
|
2007-08-08 20:16:03 +04:00
|
|
|
*
|
|
|
|
* This file is part of NetSurf, http://www.netsurf-browser.org/
|
|
|
|
*
|
|
|
|
* NetSurf is free software; you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
* the Free Software Foundation; version 2 of the License.
|
|
|
|
*
|
|
|
|
* NetSurf is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
2003-02-09 15:58:15 +03:00
|
|
|
*/
|
|
|
|
|
2006-02-13 02:07:28 +03:00
|
|
|
/** \file
|
|
|
|
* Content for text/plain (implementation).
|
|
|
|
*/
|
|
|
|
|
2006-02-16 02:09:55 +03:00
|
|
|
#include <assert.h>
|
2006-02-13 02:07:28 +03:00
|
|
|
#include <errno.h>
|
2006-02-13 03:17:44 +03:00
|
|
|
#include <stddef.h>
|
2008-07-29 00:32:51 +04:00
|
|
|
#include <string.h>
|
2008-08-11 20:44:12 +04:00
|
|
|
#include <strings.h>
|
2008-07-29 00:32:51 +04:00
|
|
|
#include <math.h>
|
2010-09-14 02:18:51 +04:00
|
|
|
|
|
|
|
#include <parserutils/input/inputstream.h>
|
|
|
|
|
2010-03-28 16:56:39 +04:00
|
|
|
#include "content/content_protected.h"
|
|
|
|
#include "content/hlcache.h"
|
2007-05-31 02:39:54 +04:00
|
|
|
#include "css/css.h"
|
2009-07-24 03:05:34 +04:00
|
|
|
#include "css/utils.h"
|
2010-06-04 13:35:08 +04:00
|
|
|
#include "desktop/browser.h"
|
2007-05-31 02:39:54 +04:00
|
|
|
#include "desktop/gui.h"
|
2009-07-27 14:00:31 +04:00
|
|
|
#include "desktop/options.h"
|
2007-05-31 02:39:54 +04:00
|
|
|
#include "desktop/plotters.h"
|
2009-12-18 02:55:02 +03:00
|
|
|
#include "desktop/search.h"
|
2007-05-31 02:39:54 +04:00
|
|
|
#include "desktop/selection.h"
|
|
|
|
#include "render/box.h"
|
|
|
|
#include "render/font.h"
|
2011-08-24 16:29:30 +04:00
|
|
|
#include "render/search.h"
|
2007-05-31 02:39:54 +04:00
|
|
|
#include "render/textplain.h"
|
2010-03-28 16:56:39 +04:00
|
|
|
#include "utils/http.h"
|
2007-05-31 02:39:54 +04:00
|
|
|
#include "utils/log.h"
|
|
|
|
#include "utils/messages.h"
|
|
|
|
#include "utils/talloc.h"
|
|
|
|
#include "utils/utils.h"
|
|
|
|
#include "utils/utf8.h"
|
2006-02-13 02:07:28 +03:00
|
|
|
|
2011-05-07 00:40:09 +04:00
|
|
|
struct textplain_line {
|
|
|
|
size_t start;
|
|
|
|
size_t length;
|
|
|
|
};
|
|
|
|
|
|
|
|
typedef struct textplain_content {
|
|
|
|
struct content base;
|
|
|
|
|
2011-07-08 12:38:17 +04:00
|
|
|
lwc_string *encoding;
|
2011-05-07 00:40:09 +04:00
|
|
|
void *inputstream;
|
|
|
|
char *utf8_data;
|
|
|
|
size_t utf8_data_size;
|
|
|
|
size_t utf8_data_allocated;
|
|
|
|
unsigned long physical_line_count;
|
|
|
|
struct textplain_line *physical_line;
|
|
|
|
int formatted_width;
|
2011-06-30 22:27:24 +04:00
|
|
|
struct browser_window *bw;
|
2011-07-13 17:20:26 +04:00
|
|
|
|
|
|
|
struct selection sel; /** Selection state */
|
2011-08-24 16:29:30 +04:00
|
|
|
|
|
|
|
/** Context for free text search, or NULL if none */
|
|
|
|
struct search_context *search;
|
2011-05-07 00:40:09 +04:00
|
|
|
} textplain_content;
|
|
|
|
|
2003-02-09 15:58:15 +03:00
|
|
|
|
2010-10-23 22:43:48 +04:00
|
|
|
#define CHUNK 32768 /* Must be a power of 2 */
|
2006-02-13 02:07:28 +03:00
|
|
|
#define MARGIN 4
|
2003-02-09 15:58:15 +03:00
|
|
|
|
2006-03-25 11:53:32 +03:00
|
|
|
|
|
|
|
#define TAB_WIDTH 8 /* must be power of 2 currently */
|
2011-03-15 18:10:10 +03:00
|
|
|
#define TEXT_SIZE 10 * FONT_SIZE_SCALE /* Unscaled text size in pt */
|
2006-03-25 11:53:32 +03:00
|
|
|
|
2009-07-21 14:59:53 +04:00
|
|
|
static plot_font_style_t textplain_style = {
|
|
|
|
.family = PLOT_FONT_FAMILY_MONOSPACE,
|
2011-03-15 18:10:10 +03:00
|
|
|
.size = TEXT_SIZE,
|
2009-07-21 14:59:53 +04:00
|
|
|
.weight = 400,
|
|
|
|
.flags = FONTF_NONE,
|
|
|
|
.background = 0xffffff,
|
|
|
|
.foreground = 0x000000,
|
|
|
|
};
|
|
|
|
|
2006-03-25 11:53:32 +03:00
|
|
|
static int textplain_tab_width = 256; /* try for a sensible default */
|
2003-02-09 15:58:15 +03:00
|
|
|
|
2011-05-07 00:40:09 +04:00
|
|
|
static nserror textplain_create(const content_handler *handler,
|
|
|
|
lwc_string *imime_type, const http_parameter *params,
|
|
|
|
llcache_handle *llcache, const char *fallback_charset,
|
|
|
|
bool quirks, struct content **c);
|
|
|
|
static nserror textplain_create_internal(textplain_content *c,
|
2011-07-08 12:38:17 +04:00
|
|
|
lwc_string *charset);
|
2011-05-07 00:40:09 +04:00
|
|
|
static bool textplain_process_data(struct content *c,
|
|
|
|
const char *data, unsigned int size);
|
|
|
|
static bool textplain_convert(struct content *c);
|
|
|
|
static void textplain_mouse_track(struct content *c, struct browser_window *bw,
|
|
|
|
browser_mouse_state mouse, int x, int y);
|
|
|
|
static void textplain_mouse_action(struct content *c, struct browser_window *bw,
|
|
|
|
browser_mouse_state mouse, int x, int y);
|
|
|
|
static void textplain_reformat(struct content *c, int width, int height);
|
|
|
|
static void textplain_destroy(struct content *c);
|
2011-06-29 00:17:39 +04:00
|
|
|
static bool textplain_redraw(struct content *c, struct content_redraw_data *data,
|
2011-06-30 19:48:07 +04:00
|
|
|
const struct rect *clip, const struct redraw_context *ctx);
|
2011-06-30 22:27:24 +04:00
|
|
|
static void textplain_open(struct content *c, struct browser_window *bw,
|
|
|
|
struct content *page, struct box *box,
|
|
|
|
struct object_params *params);
|
2011-07-01 15:16:43 +04:00
|
|
|
void textplain_close(struct content *c);
|
2011-07-13 17:20:26 +04:00
|
|
|
struct selection *textplain_get_selection(struct content *c);
|
2011-08-24 16:29:30 +04:00
|
|
|
struct search_context *textplain_get_search(struct content *c);
|
2011-05-07 00:40:09 +04:00
|
|
|
static nserror textplain_clone(const struct content *old,
|
|
|
|
struct content **newc);
|
2011-09-03 13:27:42 +04:00
|
|
|
static content_type textplain_content_type(void);
|
2011-05-07 00:40:09 +04:00
|
|
|
|
2010-09-14 02:18:51 +04:00
|
|
|
static parserutils_error textplain_charset_hack(const uint8_t *data, size_t len,
|
|
|
|
uint16_t *mibenum, uint32_t *source);
|
2011-05-07 00:40:09 +04:00
|
|
|
static bool textplain_drain_input(textplain_content *c,
|
2010-09-14 02:18:51 +04:00
|
|
|
parserutils_inputstream *stream, parserutils_error terminator);
|
2011-05-07 00:40:09 +04:00
|
|
|
static bool textplain_copy_utf8_data(textplain_content *c,
|
2010-10-23 22:43:48 +04:00
|
|
|
const uint8_t *buf, size_t len);
|
2006-03-26 08:48:45 +04:00
|
|
|
static int textplain_coord_from_offset(const char *text, size_t offset,
|
|
|
|
size_t length);
|
2009-07-21 14:59:53 +04:00
|
|
|
static float textplain_line_height(void);
|
2006-03-26 08:48:45 +04:00
|
|
|
|
2011-05-07 00:40:09 +04:00
|
|
|
static const content_handler textplain_content_handler = {
|
2011-05-09 19:32:34 +04:00
|
|
|
.create = textplain_create,
|
|
|
|
.process_data = textplain_process_data,
|
|
|
|
.data_complete = textplain_convert,
|
|
|
|
.reformat = textplain_reformat,
|
|
|
|
.destroy = textplain_destroy,
|
|
|
|
.mouse_track = textplain_mouse_track,
|
|
|
|
.mouse_action = textplain_mouse_action,
|
|
|
|
.redraw = textplain_redraw,
|
2011-06-30 22:27:24 +04:00
|
|
|
.open = textplain_open,
|
2011-07-01 15:16:43 +04:00
|
|
|
.close = textplain_close,
|
2011-07-13 17:20:26 +04:00
|
|
|
.get_selection = textplain_get_selection,
|
2011-05-09 19:32:34 +04:00
|
|
|
.clone = textplain_clone,
|
|
|
|
.type = textplain_content_type,
|
|
|
|
.no_share = true,
|
2011-05-07 00:40:09 +04:00
|
|
|
};
|
|
|
|
|
|
|
|
static lwc_string *textplain_mime_type;
|
2011-07-08 12:38:17 +04:00
|
|
|
static lwc_string *textplain_charset;
|
|
|
|
static lwc_string *textplain_default_charset;
|
2011-05-07 00:40:09 +04:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Initialise the text content handler
|
|
|
|
*/
|
|
|
|
nserror textplain_init(void)
|
|
|
|
{
|
|
|
|
lwc_error lerror;
|
|
|
|
nserror error;
|
|
|
|
|
|
|
|
lerror = lwc_intern_string("text/plain", SLEN("text/plain"),
|
|
|
|
&textplain_mime_type);
|
|
|
|
if (lerror != lwc_error_ok)
|
|
|
|
return NSERROR_NOMEM;
|
|
|
|
|
2011-07-08 12:38:17 +04:00
|
|
|
lerror = lwc_intern_string("charset", SLEN("charset"),
|
|
|
|
&textplain_charset);
|
|
|
|
if (lerror != lwc_error_ok) {
|
|
|
|
lwc_string_unref(textplain_mime_type);
|
|
|
|
return NSERROR_NOMEM;
|
|
|
|
}
|
|
|
|
|
|
|
|
lerror = lwc_intern_string("Windows-1252", SLEN("Windows-1252"),
|
|
|
|
&textplain_default_charset);
|
|
|
|
if (lerror != lwc_error_ok) {
|
|
|
|
lwc_string_unref(textplain_charset);
|
|
|
|
lwc_string_unref(textplain_mime_type);
|
|
|
|
return NSERROR_NOMEM;
|
|
|
|
}
|
|
|
|
|
2011-05-07 00:40:09 +04:00
|
|
|
error = content_factory_register_handler(textplain_mime_type,
|
|
|
|
&textplain_content_handler);
|
2011-07-08 12:38:17 +04:00
|
|
|
if (error != NSERROR_OK) {
|
|
|
|
lwc_string_unref(textplain_default_charset);
|
|
|
|
lwc_string_unref(textplain_charset);
|
2011-05-07 00:40:09 +04:00
|
|
|
lwc_string_unref(textplain_mime_type);
|
2011-07-08 12:38:17 +04:00
|
|
|
}
|
2011-05-07 00:40:09 +04:00
|
|
|
|
|
|
|
return error;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Clean up after the text content handler
|
|
|
|
*/
|
|
|
|
void textplain_fini(void)
|
|
|
|
{
|
2011-07-08 12:38:17 +04:00
|
|
|
lwc_string_unref(textplain_default_charset);
|
|
|
|
lwc_string_unref(textplain_charset);
|
2011-05-07 00:40:09 +04:00
|
|
|
lwc_string_unref(textplain_mime_type);
|
|
|
|
}
|
2003-02-09 15:58:15 +03:00
|
|
|
|
2006-02-13 02:07:28 +03:00
|
|
|
/**
|
|
|
|
* Create a CONTENT_TEXTPLAIN.
|
|
|
|
*/
|
|
|
|
|
2011-05-07 00:40:09 +04:00
|
|
|
nserror textplain_create(const content_handler *handler,
|
|
|
|
lwc_string *imime_type, const http_parameter *params,
|
|
|
|
llcache_handle *llcache, const char *fallback_charset,
|
|
|
|
bool quirks, struct content **c)
|
2003-02-09 15:58:15 +03:00
|
|
|
{
|
2011-05-07 00:40:09 +04:00
|
|
|
textplain_content *text;
|
2010-03-28 16:56:39 +04:00
|
|
|
nserror error;
|
2011-07-08 12:38:17 +04:00
|
|
|
lwc_string *encoding;
|
2006-02-13 02:07:28 +03:00
|
|
|
|
2011-05-07 00:40:09 +04:00
|
|
|
text = talloc_zero(0, textplain_content);
|
|
|
|
if (text == NULL)
|
|
|
|
return NSERROR_NOMEM;
|
|
|
|
|
|
|
|
error = content__init(&text->base, handler, imime_type, params,
|
|
|
|
llcache, fallback_charset, quirks);
|
|
|
|
if (error != NSERROR_OK) {
|
|
|
|
talloc_free(text);
|
|
|
|
return error;
|
|
|
|
}
|
2009-07-27 14:00:31 +04:00
|
|
|
|
2011-07-08 12:38:17 +04:00
|
|
|
error = http_parameter_list_find_item(params, textplain_charset,
|
|
|
|
&encoding);
|
2010-03-28 16:56:39 +04:00
|
|
|
if (error != NSERROR_OK) {
|
2011-07-08 12:38:17 +04:00
|
|
|
encoding = lwc_string_ref(textplain_default_charset);
|
2006-02-13 02:07:28 +03:00
|
|
|
}
|
|
|
|
|
2011-05-07 00:40:09 +04:00
|
|
|
error = textplain_create_internal(text, encoding);
|
|
|
|
if (error != NSERROR_OK) {
|
2011-07-08 12:38:17 +04:00
|
|
|
lwc_string_unref(encoding);
|
2011-05-07 00:40:09 +04:00
|
|
|
talloc_free(text);
|
|
|
|
return error;
|
|
|
|
}
|
|
|
|
|
2011-07-08 12:38:17 +04:00
|
|
|
lwc_string_unref(encoding);
|
|
|
|
|
2011-05-07 00:40:09 +04:00
|
|
|
*c = (struct content *) text;
|
|
|
|
|
|
|
|
return NSERROR_OK;
|
2010-04-04 16:41:19 +04:00
|
|
|
}
|
|
|
|
|
2010-09-14 02:18:51 +04:00
|
|
|
/*
|
|
|
|
* Hack around bug in libparserutils: if the client provides an
|
|
|
|
* encoding up front, but does not provide a charset detection
|
|
|
|
* callback, then libparserutils will replace the provided encoding
|
|
|
|
* with UTF-8. This breaks our input handling.
|
|
|
|
*
|
|
|
|
* We avoid this by providing a callback that does precisely nothing,
|
|
|
|
* thus preserving whatever charset information we decided on in
|
|
|
|
* textplain_create.
|
|
|
|
*/
|
|
|
|
parserutils_error textplain_charset_hack(const uint8_t *data, size_t len,
|
|
|
|
uint16_t *mibenum, uint32_t *source)
|
|
|
|
{
|
|
|
|
return PARSERUTILS_OK;
|
|
|
|
}
|
|
|
|
|
2011-07-08 12:38:17 +04:00
|
|
|
nserror textplain_create_internal(textplain_content *c, lwc_string *encoding)
|
2010-04-04 16:41:19 +04:00
|
|
|
{
|
|
|
|
char *utf8_data;
|
2010-09-14 02:18:51 +04:00
|
|
|
parserutils_inputstream *stream;
|
|
|
|
parserutils_error error;
|
2010-04-04 16:41:19 +04:00
|
|
|
union content_msg_data msg_data;
|
|
|
|
|
2011-05-07 00:40:09 +04:00
|
|
|
textplain_style.size = (option_font_size * FONT_SIZE_SCALE) / 10;
|
|
|
|
|
2010-04-04 16:41:19 +04:00
|
|
|
utf8_data = talloc_array(c, char, CHUNK);
|
2010-09-14 02:18:51 +04:00
|
|
|
if (utf8_data == NULL)
|
2010-04-04 16:41:19 +04:00
|
|
|
goto no_memory;
|
|
|
|
|
2011-07-08 12:38:17 +04:00
|
|
|
error = parserutils_inputstream_create(lwc_string_data(encoding), 0,
|
2010-09-14 02:18:51 +04:00
|
|
|
textplain_charset_hack, ns_realloc, NULL, &stream);
|
|
|
|
if (error == PARSERUTILS_BADENCODING) {
|
|
|
|
/* Fall back to Windows-1252 */
|
|
|
|
error = parserutils_inputstream_create("Windows-1252", 0,
|
|
|
|
textplain_charset_hack, ns_realloc, NULL,
|
|
|
|
&stream);
|
2006-02-13 02:07:28 +03:00
|
|
|
}
|
2010-09-14 02:18:51 +04:00
|
|
|
if (error != PARSERUTILS_OK) {
|
|
|
|
talloc_free(utf8_data);
|
|
|
|
goto no_memory;
|
2006-02-13 02:07:28 +03:00
|
|
|
}
|
2010-09-14 02:18:51 +04:00
|
|
|
|
2011-07-08 12:38:17 +04:00
|
|
|
c->encoding = lwc_string_ref(encoding);
|
2011-05-07 00:40:09 +04:00
|
|
|
c->inputstream = stream;
|
|
|
|
c->utf8_data = utf8_data;
|
|
|
|
c->utf8_data_size = 0;
|
|
|
|
c->utf8_data_allocated = CHUNK;
|
|
|
|
c->physical_line = 0;
|
|
|
|
c->physical_line_count = 0;
|
|
|
|
c->formatted_width = 0;
|
2011-06-30 22:27:24 +04:00
|
|
|
c->bw = NULL;
|
2006-02-13 02:07:28 +03:00
|
|
|
|
2011-07-26 17:53:42 +04:00
|
|
|
selection_prepare(&c->sel, (struct content *)c, false);
|
2011-07-13 17:20:26 +04:00
|
|
|
|
2011-05-07 00:40:09 +04:00
|
|
|
return NSERROR_OK;
|
2006-02-13 02:07:28 +03:00
|
|
|
|
|
|
|
no_memory:
|
|
|
|
msg_data.error = messages_get("NoMemory");
|
2011-05-07 00:40:09 +04:00
|
|
|
content_broadcast(&c->base, CONTENT_MSG_ERROR, msg_data);
|
|
|
|
return NSERROR_NOMEM;
|
2003-02-09 15:58:15 +03:00
|
|
|
}
|
|
|
|
|
2011-05-07 00:40:09 +04:00
|
|
|
bool textplain_drain_input(textplain_content *c,
|
|
|
|
parserutils_inputstream *stream,
|
2010-09-14 02:18:51 +04:00
|
|
|
parserutils_error terminator)
|
2004-11-22 03:33:04 +03:00
|
|
|
{
|
2010-09-14 02:32:52 +04:00
|
|
|
static const uint8_t *u_fffd = (const uint8_t *) "\xef\xbf\xfd";
|
2010-09-14 02:18:51 +04:00
|
|
|
const uint8_t *ch;
|
2010-10-23 22:43:48 +04:00
|
|
|
size_t chlen, offset = 0;
|
2010-09-14 02:18:51 +04:00
|
|
|
|
2010-10-23 22:43:48 +04:00
|
|
|
while (parserutils_inputstream_peek(stream, offset, &ch, &chlen) !=
|
2010-09-14 02:18:51 +04:00
|
|
|
terminator) {
|
2010-09-14 02:32:52 +04:00
|
|
|
/* Replace all instances of NUL with U+FFFD */
|
|
|
|
if (chlen == 1 && *ch == 0) {
|
2010-10-23 22:43:48 +04:00
|
|
|
if (offset > 0) {
|
|
|
|
/* Obtain pointer to start of input data */
|
|
|
|
parserutils_inputstream_peek(stream, 0,
|
|
|
|
&ch, &chlen);
|
|
|
|
/* Copy from it up to the start of the NUL */
|
|
|
|
if (textplain_copy_utf8_data(c, ch,
|
|
|
|
offset) == false)
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Emit U+FFFD */
|
|
|
|
if (textplain_copy_utf8_data(c, u_fffd, 3) == false)
|
|
|
|
return false;
|
|
|
|
|
|
|
|
/* Advance inputstream past the NUL we just read */
|
|
|
|
parserutils_inputstream_advance(stream, offset + 1);
|
|
|
|
/* Reset the read offset */
|
|
|
|
offset = 0;
|
2010-09-14 02:32:52 +04:00
|
|
|
} else {
|
2010-10-23 22:43:48 +04:00
|
|
|
/* Accumulate input */
|
|
|
|
offset += chlen;
|
|
|
|
|
|
|
|
if (offset > CHUNK) {
|
|
|
|
/* Obtain pointer to start of input data */
|
|
|
|
parserutils_inputstream_peek(stream, 0,
|
|
|
|
&ch, &chlen);
|
|
|
|
|
|
|
|
/* Emit the data we've read */
|
|
|
|
if (textplain_copy_utf8_data(c, ch,
|
|
|
|
offset) == false)
|
|
|
|
return false;
|
|
|
|
|
|
|
|
/* Advance the inputstream */
|
|
|
|
parserutils_inputstream_advance(stream, offset);
|
|
|
|
/* Reset the read offset */
|
|
|
|
offset = 0;
|
|
|
|
}
|
2010-09-14 02:32:52 +04:00
|
|
|
}
|
2010-10-23 22:43:48 +04:00
|
|
|
}
|
2010-09-14 02:32:52 +04:00
|
|
|
|
2010-10-23 22:43:48 +04:00
|
|
|
if (offset > 0) {
|
|
|
|
/* Obtain pointer to start of input data */
|
|
|
|
parserutils_inputstream_peek(stream, 0, &ch, &chlen);
|
|
|
|
/* Emit any data remaining */
|
|
|
|
if (textplain_copy_utf8_data(c, ch, offset) == false)
|
|
|
|
return false;
|
2010-09-14 02:18:51 +04:00
|
|
|
|
2010-10-23 22:43:48 +04:00
|
|
|
/* Advance the inputstream past the data we've read */
|
|
|
|
parserutils_inputstream_advance(stream, offset);
|
|
|
|
}
|
2007-03-12 01:08:57 +03:00
|
|
|
|
2010-10-23 22:43:48 +04:00
|
|
|
return true;
|
|
|
|
}
|
2007-03-12 01:08:57 +03:00
|
|
|
|
2011-05-07 00:40:09 +04:00
|
|
|
bool textplain_copy_utf8_data(textplain_content *c,
|
|
|
|
const uint8_t *buf, size_t len)
|
2010-10-23 22:43:48 +04:00
|
|
|
{
|
2011-05-07 00:40:09 +04:00
|
|
|
if (c->utf8_data_size + len >= c->utf8_data_allocated) {
|
2010-10-23 22:43:48 +04:00
|
|
|
/* Compute next multiple of chunk above the required space */
|
2011-05-07 00:40:09 +04:00
|
|
|
size_t allocated = (c->utf8_data_size + len +
|
2010-10-23 22:43:48 +04:00
|
|
|
CHUNK - 1) & ~(CHUNK - 1);
|
|
|
|
char *utf8_data = talloc_realloc(c,
|
2011-05-07 00:40:09 +04:00
|
|
|
c->utf8_data,
|
2010-10-23 22:43:48 +04:00
|
|
|
char, allocated);
|
|
|
|
if (utf8_data == NULL)
|
|
|
|
return false;
|
|
|
|
|
2011-05-07 00:40:09 +04:00
|
|
|
c->utf8_data = utf8_data;
|
|
|
|
c->utf8_data_allocated = allocated;
|
2010-09-14 02:18:51 +04:00
|
|
|
}
|
2007-03-12 01:08:57 +03:00
|
|
|
|
2011-05-07 00:40:09 +04:00
|
|
|
memcpy(c->utf8_data + c->utf8_data_size, buf, len);
|
|
|
|
c->utf8_data_size += len;
|
2010-10-23 22:43:48 +04:00
|
|
|
|
2010-09-14 02:18:51 +04:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Process data for CONTENT_TEXTPLAIN.
|
|
|
|
*/
|
|
|
|
|
|
|
|
bool textplain_process_data(struct content *c,
|
|
|
|
const char *data, unsigned int size)
|
|
|
|
{
|
2011-05-07 00:40:09 +04:00
|
|
|
textplain_content *text = (textplain_content *) c;
|
|
|
|
parserutils_inputstream *stream = text->inputstream;
|
2010-09-14 02:18:51 +04:00
|
|
|
union content_msg_data msg_data;
|
|
|
|
parserutils_error error;
|
|
|
|
|
|
|
|
error = parserutils_inputstream_append(stream,
|
|
|
|
(const uint8_t *) data, size);
|
|
|
|
if (error != PARSERUTILS_OK) {
|
|
|
|
goto no_memory;
|
|
|
|
}
|
2006-02-13 02:07:28 +03:00
|
|
|
|
2011-05-07 00:40:09 +04:00
|
|
|
if (textplain_drain_input(text, stream, PARSERUTILS_NEEDDATA) == false)
|
2010-09-14 02:18:51 +04:00
|
|
|
goto no_memory;
|
2006-02-13 02:07:28 +03:00
|
|
|
|
|
|
|
return true;
|
|
|
|
|
|
|
|
no_memory:
|
|
|
|
msg_data.error = messages_get("NoMemory");
|
|
|
|
content_broadcast(c, CONTENT_MSG_ERROR, msg_data);
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Convert a CONTENT_TEXTPLAIN for display.
|
|
|
|
*/
|
|
|
|
|
2010-03-30 02:33:21 +04:00
|
|
|
bool textplain_convert(struct content *c)
|
2006-02-13 02:07:28 +03:00
|
|
|
{
|
2011-05-07 00:40:09 +04:00
|
|
|
textplain_content *text = (textplain_content *) c;
|
|
|
|
parserutils_inputstream *stream = text->inputstream;
|
2010-09-14 02:18:51 +04:00
|
|
|
parserutils_error error;
|
|
|
|
|
|
|
|
error = parserutils_inputstream_append(stream, NULL, 0);
|
|
|
|
if (error != PARSERUTILS_OK) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2011-05-07 00:40:09 +04:00
|
|
|
if (textplain_drain_input(text, stream, PARSERUTILS_EOF) == false)
|
2010-09-14 02:18:51 +04:00
|
|
|
return false;
|
|
|
|
|
|
|
|
parserutils_inputstream_destroy(stream);
|
2011-05-07 00:40:09 +04:00
|
|
|
text->inputstream = NULL;
|
2006-02-13 02:07:28 +03:00
|
|
|
|
2011-02-27 23:11:39 +03:00
|
|
|
content_set_ready(c);
|
|
|
|
content_set_done(c);
|
2006-07-05 01:01:17 +04:00
|
|
|
content_set_status(c, messages_get("Done"));
|
2006-02-13 02:07:28 +03:00
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Reformat a CONTENT_TEXTPLAIN to a new width.
|
|
|
|
*/
|
|
|
|
|
|
|
|
void textplain_reformat(struct content *c, int width, int height)
|
|
|
|
{
|
2011-05-07 00:40:09 +04:00
|
|
|
textplain_content *text = (textplain_content *) c;
|
|
|
|
char *utf8_data = text->utf8_data;
|
|
|
|
size_t utf8_data_size = text->utf8_data_size;
|
2006-02-13 02:07:28 +03:00
|
|
|
unsigned long line_count = 0;
|
2011-05-07 00:40:09 +04:00
|
|
|
struct textplain_line *line = text->physical_line;
|
2006-02-16 02:09:55 +03:00
|
|
|
struct textplain_line *line1;
|
2006-02-13 02:07:28 +03:00
|
|
|
size_t i, space, col;
|
|
|
|
size_t columns = 80;
|
|
|
|
int character_width;
|
2006-02-16 02:09:55 +03:00
|
|
|
size_t line_start;
|
2006-02-13 02:07:28 +03:00
|
|
|
|
|
|
|
/* compute available columns (assuming monospaced font) - use 8
|
|
|
|
* characters for better accuracy */
|
First merge of Adam Blokus' GSoC work from his branch 'branches/adamblokus/netsurf'.
Merged revisions 4212-4552,4554-4709,4711-4724 via svnmerge from
svn://svn.netsurf-browser.org/branches/adamblokus/netsurf
........
r4212 | adamblokus | 2008-05-26 19:42:31 +0200 (Mon, 26 May 2008) | 4 lines
Pdf plotting skeleton pinned on Print Preview in GTK.
Just creates a file and draws lines.
........
r4213 | adamblokus | 2008-05-27 00:11:03 +0200 (Tue, 27 May 2008) | 4 lines
Pdf plotter - added drawing some graphic primitives.
Still with limited functionality, but a snapshot of the
currently viewed page can be made and resembles the original.
........
r4214 | adamblokus | 2008-05-27 11:43:31 +0200 (Tue, 27 May 2008) | 2 lines
Corrected encoding name
........
r4215 | adamblokus | 2008-05-27 12:47:26 +0200 (Tue, 27 May 2008) | 3 lines
Colours and polygons added.
........
r4217 | adamblokus | 2008-05-27 21:39:35 +0200 (Tue, 27 May 2008) | 6 lines
Added rectangles, filled boxes and clipping.
Taken into consideration joty's comments.
Added a todo list for this part.
Added some debug stuff and checking boundaries.
........
r4218 | adamblokus | 2008-05-28 12:37:30 +0200 (Wed, 28 May 2008) | 2 lines
Added path ploting (not sure if valid argument order for bezier) and dashed/dotted line styles
........
r4221 | adamblokus | 2008-05-28 22:11:05 +0200 (Wed, 28 May 2008) | 3 lines
Some more options in graphic primitives and normalizing some parameters.
........
r4235 | adamblokus | 2008-05-31 22:54:56 +0200 (Sat, 31 May 2008) | 4 lines
Plotting changed as jmb suggested (is the least invasive one from the possible)
Added dummy bitmap plotting - way of plotting an image is determined by its type.
........
r4251 | adamblokus | 2008-06-03 17:12:15 +0200 (Tue, 03 Jun 2008) | 3 lines
Added plotting jpg and png images - quite a lot to improve in this code, but it seems to work ;)
........
r4263 | adamblokus | 2008-06-05 14:20:32 +0200 (Thu, 05 Jun 2008) | 3 lines
Added hadling images other than png and jpeg - with transparency.
........
r4267 | adamblokus | 2008-06-06 15:36:34 +0200 (Fri, 06 Jun 2008) | 5 lines
Added handling NULL-returns from all mallocs.
Added plot_bitmap_tile handling.
Changed code style a little.
........
r4327 | adamblokus | 2008-06-12 17:46:34 +0200 (Thu, 12 Jun 2008) | 5 lines
Added a first prototype of the paged-output organization.
Still not sure about naming, file locations etc.
Works with the same pdf plotting as before.
........
r4328 | adamblokus | 2008-06-13 13:52:15 +0200 (Fri, 13 Jun 2008) | 4 lines
Added primitive width adjustment and outputing the whole
website in multiple pages.
........
r4336 | joty | 2008-06-15 15:06:57 +0200 (Sun, 15 Jun 2008) | 1 line
Fix RISC OS build failure (change r4235 wasn't complete).
........
r4337 | joty | 2008-06-15 18:15:32 +0200 (Sun, 15 Jun 2008) | 16 lines
This enables "Export PDF" in RISC OS build:
- Docs/Doxyfile(PREDEFINED): Added WITH_PDF_EXPORT
- Makefile.sources(S_PDF): Add to RISC OS target as well.
- utils/config.h: Define WITH_PDF_EXPORT which controls if we want to have
PDF export functionality or not.
- riscos/save_pdf.c,riscos/save_pdf.h(save_as_pdf): Use PDF print API made
by Adam Blokus to write a PDF file under RISC OS.
- riscos/save.c: Call save_as_pdf added.
- riscos/menus.c: Add 'Export->PDF' menu entry.
- riscos/menus.h(menu_action): Added BROWSER_EXPORT_PDF.
- desktop/gui.h(gui_save_type): Added GUI_SAVE_PDF.
- desktop/print.c(print_run): Added return value.
- Makefile(CCACHE): Moved closed to the place where CC is set for the first time.
(LDFLAGS): Centralised adding all non-pkgconfig libraries and added Haru + PNG libs.
........
r4343 | adamblokus | 2008-06-16 01:08:52 +0200 (Mon, 16 Jun 2008) | 3 lines
Added margins and page size adjustment.
........
r4412 | adamblokus | 2008-06-21 20:22:07 +0200 (Sat, 21 Jun 2008) | 4 lines
Added 'fuzzy' margins on page bottom.
Disabled direct png embedding, because it is too unstable in Haru now.
........
r4421 | adamblokus | 2008-06-22 18:52:28 +0200 (Sun, 22 Jun 2008) | 2 lines
Added "Save as.." dialog and Export->PDF menu entry. Print preview still works with default path.
........
r4437 | adamblokus | 2008-06-25 02:44:46 +0200 (Wed, 25 Jun 2008) | 4 lines
Added skeleton of applying loose layout.
Minor code cleaning-up.
........
r4492 | adamblokus | 2008-07-02 09:02:42 +0200 (Wed, 02 Jul 2008) | 5 lines
Implemented the elementar ideas of the loose layout.
Added scaling in the printing routine.
Added some basic demonstrations.
........
r4493 | adamblokus | 2008-07-02 09:05:55 +0200 (Wed, 02 Jul 2008) | 3 lines
Cleaned up the loosing code - commited to much of leftover rubbish code.
........
r4507 | adamblokus | 2008-07-04 14:25:48 +0200 (Fri, 04 Jul 2008) | 4 lines
Added duplicating box tree and current content - window flickering during printing solved.
Minor error checking after new HPDF_Image_AddSMask call.
........
r4515 | adamblokus | 2008-07-06 22:28:16 +0200 (Sun, 06 Jul 2008) | 2 lines
Changes in loosen layout (image resizing).
........
r4517 | adamblokus | 2008-07-06 22:38:23 +0200 (Sun, 06 Jul 2008) | 2 lines
Added pdf font handling and rendering functions with the use of Haru functions.
........
r4555 | adamblokus | 2008-07-10 00:59:05 +0200 (Thu, 10 Jul 2008) | 2 lines
Added a very basic and still buggy GTK print implementation.
........
r4565 | adamblokus | 2008-07-10 14:50:16 +0200 (Thu, 10 Jul 2008) | 2 lines
Added gtk printing one more time - I have forgotten to add the main file.
........
r4566 | adamblokus | 2008-07-10 14:57:02 +0200 (Thu, 10 Jul 2008) | 2 lines
removed error with comment
........
r4569 | adamblokus | 2008-07-10 15:52:55 +0200 (Thu, 10 Jul 2008) | 5 lines
Major style improvements - added a lot of doxygen comments,
followed tlsa's style guide.
Added some more error checking, too.
........
r4575 | adamblokus | 2008-07-10 18:48:26 +0200 (Thu, 10 Jul 2008) | 2 lines
Cleaned up the code.
........
r4687 | adamblokus | 2008-07-17 14:17:19 +0200 (Thu, 17 Jul 2008) | 2 lines
Changed everything according to jmb's review plus some minor bug fixes to gtk_print.
........
r4688 | adamblokus | 2008-07-17 17:16:34 +0200 (Thu, 17 Jul 2008) | 2 lines
Solved the netsurf.glade clash from r4421.
........
r4693 | adamblokus | 2008-07-18 18:11:51 +0200 (Fri, 18 Jul 2008) | 2 lines
Fixed bug with wrong number of pages in gtk printing.
........
r4695 | adamblokus | 2008-07-18 19:59:24 +0200 (Fri, 18 Jul 2008) | 3 lines
- fixed uncommented line from the previous commit
- fixed bug with scale bigger than 1.0 (incorretly clipped page)
........
r4696 | adamblokus | 2008-07-18 23:28:00 +0200 (Fri, 18 Jul 2008) | 2 lines
Fixed bug in gtk_print_font_paint (and nsfont_paint).
........
r4697 | adamblokus | 2008-07-18 23:35:38 +0200 (Fri, 18 Jul 2008) | 2 lines
Bug fix in nsfont_paint.
........
r4711 | adamblokus | 2008-07-19 22:44:15 +0200 (Sat, 19 Jul 2008) | 2 lines
Added gtk_selection files.
........
r4712 | adamblokus | 2008-07-20 11:15:06 +0200 (Sun, 20 Jul 2008) | 2 lines
Addam missing glade files.
........
r4713 | joty | 2008-07-20 17:13:10 +0200 (Sun, 20 Jul 2008) | 1 line
Follow change r4517 for RISC OS and BeOS platforms : Added pdf font handling and rendering functions with the use of Haru functions.
........
r4714 | joty | 2008-07-20 18:19:50 +0200 (Sun, 20 Jul 2008) | 1 line
Declare haru_nsfont iso define an instance for each C source including the font_haru.h header. This fixes breakage of PDF export on RISC OS.
........
r4724 | adamblokus | 2008-07-23 03:30:08 +0200 (Wed, 23 Jul 2008) | 6 lines
Applied changes according to joty's review.
Added checking the dimensions of a plotted image to pdf plotter.
Commented out jpg embedding (it seems to cause some problems
I'll bring it back when I figure out what's wrong) .
Added back some files removed by mistake.
........
svn path=/trunk/netsurf/; revision=4741
2008-07-26 20:01:59 +04:00
|
|
|
if (!nsfont.font_width(&textplain_style, "ABCDEFGH", 8, &character_width))
|
2006-02-13 02:07:28 +03:00
|
|
|
return;
|
|
|
|
columns = (width - MARGIN - MARGIN) * 8 / character_width;
|
2006-03-25 11:53:32 +03:00
|
|
|
textplain_tab_width = (TAB_WIDTH * character_width) / 8;
|
2006-02-13 02:07:28 +03:00
|
|
|
|
2011-05-07 00:40:09 +04:00
|
|
|
text->formatted_width = width;
|
2006-02-16 02:09:55 +03:00
|
|
|
|
2011-05-07 00:40:09 +04:00
|
|
|
text->physical_line_count = 0;
|
2006-02-13 02:07:28 +03:00
|
|
|
|
2006-02-16 02:09:55 +03:00
|
|
|
if (!line) {
|
2011-05-07 00:40:09 +04:00
|
|
|
text->physical_line = line =
|
2006-02-16 02:09:55 +03:00
|
|
|
talloc_array(c, struct textplain_line, 1024 + 3);
|
|
|
|
if (!line)
|
2006-02-13 02:07:28 +03:00
|
|
|
goto no_memory;
|
2004-11-22 03:33:04 +03:00
|
|
|
}
|
|
|
|
|
2006-02-16 02:09:55 +03:00
|
|
|
line[line_count++].start = line_start = 0;
|
2006-02-13 02:07:28 +03:00
|
|
|
space = 0;
|
|
|
|
for (i = 0, col = 0; i != utf8_data_size; i++) {
|
2006-02-16 02:09:55 +03:00
|
|
|
bool term = (utf8_data[i] == '\n' || utf8_data[i] == '\r');
|
2006-03-26 08:48:45 +04:00
|
|
|
size_t next_col = col + 1;
|
2006-03-25 11:53:32 +03:00
|
|
|
|
|
|
|
if (utf8_data[i] == '\t')
|
|
|
|
next_col = (next_col + TAB_WIDTH - 1) & ~(TAB_WIDTH - 1);
|
|
|
|
|
|
|
|
if (term || next_col >= columns) {
|
2006-02-13 02:07:28 +03:00
|
|
|
if (line_count % 1024 == 0) {
|
2006-02-16 02:09:55 +03:00
|
|
|
line1 = talloc_realloc(c, line,
|
|
|
|
struct textplain_line, line_count + 1024 + 3);
|
|
|
|
if (!line1)
|
2006-02-13 02:07:28 +03:00
|
|
|
goto no_memory;
|
2011-05-07 00:40:09 +04:00
|
|
|
text->physical_line = line = line1;
|
2006-02-16 02:09:55 +03:00
|
|
|
}
|
|
|
|
if (term) {
|
|
|
|
line[line_count-1].length = i - line_start;
|
|
|
|
|
|
|
|
/* skip second char of CR/LF or LF/CR pair */
|
|
|
|
if (i + 1 < utf8_data_size &&
|
|
|
|
utf8_data[i+1] != utf8_data[i] &&
|
|
|
|
(utf8_data[i+1] == '\n' || utf8_data[i+1] == '\r'))
|
|
|
|
i++;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
if (space) {
|
|
|
|
/* break at last space in line */
|
|
|
|
i = space;
|
|
|
|
line[line_count-1].length = (i + 1) - line_start;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
line[line_count-1].length = i - line_start;
|
|
|
|
}
|
|
|
|
line[line_count++].start = line_start = i + 1;
|
2006-02-13 02:07:28 +03:00
|
|
|
col = 0;
|
|
|
|
space = 0;
|
|
|
|
} else {
|
|
|
|
col++;
|
|
|
|
if (utf8_data[i] == ' ')
|
|
|
|
space = i;
|
2004-11-22 03:33:04 +03:00
|
|
|
}
|
|
|
|
}
|
2006-02-16 02:09:55 +03:00
|
|
|
line[line_count-1].length = i - line[line_count-1].start;
|
|
|
|
line[line_count].start = utf8_data_size;
|
2004-11-22 03:33:04 +03:00
|
|
|
|
2011-05-07 00:40:09 +04:00
|
|
|
text->physical_line_count = line_count;
|
2006-02-13 02:07:28 +03:00
|
|
|
c->width = width;
|
2009-07-21 14:59:53 +04:00
|
|
|
c->height = line_count * textplain_line_height() + MARGIN + MARGIN;
|
2004-11-22 03:33:04 +03:00
|
|
|
|
2006-02-13 02:07:28 +03:00
|
|
|
return;
|
2004-11-22 03:33:04 +03:00
|
|
|
|
2006-02-13 02:07:28 +03:00
|
|
|
no_memory:
|
|
|
|
LOG(("out of memory (line_count %lu)", line_count));
|
|
|
|
return;
|
2004-11-22 03:33:04 +03:00
|
|
|
}
|
2003-02-09 15:58:15 +03:00
|
|
|
|
2006-02-13 02:07:28 +03:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Destroy a CONTENT_TEXTPLAIN and free all resources it owns.
|
|
|
|
*/
|
|
|
|
|
|
|
|
void textplain_destroy(struct content *c)
|
|
|
|
{
|
2011-05-07 00:40:09 +04:00
|
|
|
textplain_content *text = (textplain_content *) c;
|
2010-04-04 16:41:19 +04:00
|
|
|
|
2011-07-08 12:38:17 +04:00
|
|
|
lwc_string_unref(text->encoding);
|
2011-05-07 00:40:09 +04:00
|
|
|
|
|
|
|
if (text->inputstream != NULL)
|
|
|
|
parserutils_inputstream_destroy(text->inputstream);
|
2006-02-13 02:07:28 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2011-05-07 00:40:09 +04:00
|
|
|
nserror textplain_clone(const struct content *old, struct content **newc)
|
2010-04-04 16:41:19 +04:00
|
|
|
{
|
2011-05-07 00:40:09 +04:00
|
|
|
const textplain_content *old_text = (textplain_content *) old;
|
|
|
|
textplain_content *text;
|
|
|
|
nserror error;
|
2010-04-04 16:41:19 +04:00
|
|
|
const char *data;
|
|
|
|
unsigned long size;
|
|
|
|
|
2011-05-07 00:40:09 +04:00
|
|
|
text = talloc_zero(0, textplain_content);
|
|
|
|
if (text == NULL)
|
|
|
|
return NSERROR_NOMEM;
|
|
|
|
|
|
|
|
error = content__clone(old, &text->base);
|
|
|
|
if (error != NSERROR_OK) {
|
|
|
|
content_destroy(&text->base);
|
|
|
|
return error;
|
|
|
|
}
|
|
|
|
|
2010-04-04 16:41:19 +04:00
|
|
|
/* Simply replay create/process/convert */
|
2011-05-07 00:40:09 +04:00
|
|
|
error = textplain_create_internal(text, old_text->encoding);
|
|
|
|
if (error != NSERROR_OK) {
|
|
|
|
content_destroy(&text->base);
|
|
|
|
return error;
|
|
|
|
}
|
2010-04-04 16:41:19 +04:00
|
|
|
|
2011-05-07 00:40:09 +04:00
|
|
|
data = content__get_source_data(&text->base, &size);
|
2010-04-04 16:41:19 +04:00
|
|
|
if (size > 0) {
|
2011-05-07 00:40:09 +04:00
|
|
|
if (textplain_process_data(&text->base, data, size) == false) {
|
|
|
|
content_destroy(&text->base);
|
|
|
|
return NSERROR_NOMEM;
|
|
|
|
}
|
2010-04-04 16:41:19 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
if (old->status == CONTENT_STATUS_READY ||
|
|
|
|
old->status == CONTENT_STATUS_DONE) {
|
2011-05-07 00:40:09 +04:00
|
|
|
if (textplain_convert(&text->base) == false) {
|
|
|
|
content_destroy(&text->base);
|
|
|
|
return NSERROR_CLONE_FAILED;
|
|
|
|
}
|
2010-04-04 16:41:19 +04:00
|
|
|
}
|
|
|
|
|
2011-05-07 00:40:09 +04:00
|
|
|
return NSERROR_OK;
|
2010-04-04 16:41:19 +04:00
|
|
|
}
|
|
|
|
|
2011-09-03 13:27:42 +04:00
|
|
|
content_type textplain_content_type(void)
|
2011-05-07 00:40:09 +04:00
|
|
|
{
|
|
|
|
return CONTENT_TEXTPLAIN;
|
|
|
|
}
|
2010-04-04 16:41:19 +04:00
|
|
|
|
2010-06-04 13:35:08 +04:00
|
|
|
/**
|
|
|
|
* Handle mouse tracking (including drags) in a TEXTPLAIN content window.
|
|
|
|
*
|
|
|
|
* \param c content of type textplain
|
|
|
|
* \param bw browser window
|
|
|
|
* \param mouse state of mouse buttons and modifier keys
|
|
|
|
* \param x coordinate of mouse
|
|
|
|
* \param y coordinate of mouse
|
|
|
|
*/
|
|
|
|
|
|
|
|
void textplain_mouse_track(struct content *c, struct browser_window *bw,
|
|
|
|
browser_mouse_state mouse, int x, int y)
|
|
|
|
{
|
2011-07-13 17:20:26 +04:00
|
|
|
textplain_content *text = (textplain_content *) c;
|
|
|
|
|
|
|
|
if (bw->drag_type == DRAGGING_SELECTION && !mouse) {
|
|
|
|
int dir = -1;
|
|
|
|
size_t idx;
|
|
|
|
|
|
|
|
if (selection_dragging_start(&text->sel))
|
|
|
|
dir = 1;
|
|
|
|
|
2011-07-26 17:53:42 +04:00
|
|
|
idx = textplain_offset_from_coords(c, x, y, dir);
|
2011-07-13 17:20:26 +04:00
|
|
|
selection_track(&text->sel, mouse, idx);
|
|
|
|
|
|
|
|
browser_window_set_drag_type(bw, DRAGGING_NONE);
|
|
|
|
}
|
|
|
|
|
2010-06-04 13:35:08 +04:00
|
|
|
switch (bw->drag_type) {
|
|
|
|
|
|
|
|
case DRAGGING_SELECTION: {
|
|
|
|
int dir = -1;
|
|
|
|
size_t idx;
|
|
|
|
|
2011-07-13 17:20:26 +04:00
|
|
|
if (selection_dragging_start(&text->sel)) dir = 1;
|
2010-06-04 13:35:08 +04:00
|
|
|
|
2011-07-26 17:53:42 +04:00
|
|
|
idx = textplain_offset_from_coords(c, x, y, dir);
|
2011-07-13 17:20:26 +04:00
|
|
|
selection_track(&text->sel, mouse, idx);
|
2010-06-04 13:35:08 +04:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
textplain_mouse_action(c, bw, mouse, x, y);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Handle mouse clicks and movements in a TEXTPLAIN content window.
|
|
|
|
*
|
|
|
|
* \param c content of type textplain
|
|
|
|
* \param bw browser window
|
|
|
|
* \param click type of mouse click
|
|
|
|
* \param x coordinate of mouse
|
|
|
|
* \param y coordinate of mouse
|
|
|
|
*/
|
|
|
|
|
|
|
|
void textplain_mouse_action(struct content *c, struct browser_window *bw,
|
|
|
|
browser_mouse_state mouse, int x, int y)
|
|
|
|
{
|
2011-07-13 17:20:26 +04:00
|
|
|
textplain_content *text = (textplain_content *) c;
|
2010-06-04 13:35:08 +04:00
|
|
|
gui_pointer_shape pointer = GUI_POINTER_DEFAULT;
|
|
|
|
const char *status = 0;
|
|
|
|
size_t idx;
|
|
|
|
int dir = 0;
|
|
|
|
|
2011-07-13 17:20:26 +04:00
|
|
|
browser_window_set_drag_type(bw, DRAGGING_NONE);
|
2010-06-04 13:35:08 +04:00
|
|
|
|
2011-07-26 17:53:42 +04:00
|
|
|
idx = textplain_offset_from_coords(c, x, y, dir);
|
2011-07-13 17:20:26 +04:00
|
|
|
if (selection_click(&text->sel, mouse, idx)) {
|
2010-06-04 13:35:08 +04:00
|
|
|
|
2011-07-13 17:20:26 +04:00
|
|
|
if (selection_dragging(&text->sel)) {
|
2010-06-04 13:35:08 +04:00
|
|
|
bw->drag_type = DRAGGING_SELECTION;
|
|
|
|
status = messages_get("Selecting");
|
|
|
|
}
|
|
|
|
else
|
2011-07-26 17:53:42 +04:00
|
|
|
status = content__get_status_message(c);
|
2010-06-04 13:35:08 +04:00
|
|
|
}
|
|
|
|
else {
|
|
|
|
if (bw->loading_content)
|
|
|
|
status = content_get_status_message(
|
|
|
|
bw->loading_content);
|
|
|
|
else
|
2011-07-26 17:53:42 +04:00
|
|
|
status = content__get_status_message(c);
|
2010-06-04 13:35:08 +04:00
|
|
|
|
|
|
|
if (mouse & (BROWSER_MOUSE_DRAG_1 | BROWSER_MOUSE_DRAG_2)) {
|
|
|
|
browser_window_page_drag_start(bw, x, y);
|
|
|
|
pointer = GUI_POINTER_MOVE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-09-17 23:11:53 +04:00
|
|
|
if (status != NULL)
|
|
|
|
browser_window_set_status(bw, status);
|
2010-06-04 13:35:08 +04:00
|
|
|
|
2011-06-15 00:00:18 +04:00
|
|
|
browser_window_set_pointer(bw, pointer);
|
2010-06-04 13:35:08 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2006-02-13 02:07:28 +03:00
|
|
|
/**
|
|
|
|
* Draw a CONTENT_TEXTPLAIN using the current set of plotters (plot).
|
|
|
|
*
|
2011-06-29 00:17:39 +04:00
|
|
|
* \param c content of type CONTENT_TEXTPLAIN
|
|
|
|
* \param data redraw data for this content redraw
|
|
|
|
* \param clip current clip region
|
2011-06-30 19:48:07 +04:00
|
|
|
* \param ctx current redraw context
|
2006-02-13 02:07:28 +03:00
|
|
|
* \return true if successful, false otherwise
|
|
|
|
*
|
|
|
|
* x, y, clip_[xy][01] are in target coordinates.
|
|
|
|
*/
|
|
|
|
|
2011-06-29 00:17:39 +04:00
|
|
|
bool textplain_redraw(struct content *c, struct content_redraw_data *data,
|
2011-06-30 19:48:07 +04:00
|
|
|
const struct rect *clip, const struct redraw_context *ctx)
|
2003-02-09 15:58:15 +03:00
|
|
|
{
|
2011-05-07 00:40:09 +04:00
|
|
|
textplain_content *text = (textplain_content *) c;
|
2011-06-30 22:27:24 +04:00
|
|
|
struct browser_window *bw = text->bw;
|
2011-06-30 19:48:07 +04:00
|
|
|
const struct plotter_table *plot = ctx->plot;
|
2011-05-07 00:40:09 +04:00
|
|
|
char *utf8_data = text->utf8_data;
|
2006-02-16 02:09:55 +03:00
|
|
|
long lineno;
|
2011-06-29 00:17:39 +04:00
|
|
|
int x = data->x;
|
|
|
|
int y = data->y;
|
2011-05-07 00:40:09 +04:00
|
|
|
unsigned long line_count = text->physical_line_count;
|
2009-07-21 14:59:53 +04:00
|
|
|
float line_height = textplain_line_height();
|
2011-06-29 00:17:39 +04:00
|
|
|
float scaled_line_height = line_height * data->scale;
|
|
|
|
long line0 = (clip->y0 - y * data->scale) / scaled_line_height - 1;
|
|
|
|
long line1 = (clip->y1 - y * data->scale) / scaled_line_height + 1;
|
2011-05-07 00:40:09 +04:00
|
|
|
struct textplain_line *line = text->physical_line;
|
2006-03-26 08:48:45 +04:00
|
|
|
size_t length;
|
2009-07-06 14:38:13 +04:00
|
|
|
plot_style_t *plot_style_highlight;
|
2006-02-16 02:09:55 +03:00
|
|
|
|
2006-02-13 02:07:28 +03:00
|
|
|
if (line0 < 0)
|
|
|
|
line0 = 0;
|
|
|
|
if (line1 < 0)
|
|
|
|
line1 = 0;
|
|
|
|
if (line_count < (unsigned long) line0)
|
|
|
|
line0 = line_count;
|
|
|
|
if (line_count < (unsigned long) line1)
|
|
|
|
line1 = line_count;
|
|
|
|
if (line1 < line0)
|
|
|
|
line1 = line0;
|
|
|
|
|
2011-06-30 19:48:07 +04:00
|
|
|
if (!plot->rectangle(clip->x0, clip->y0, clip->x1, clip->y1,
|
2011-02-14 01:25:11 +03:00
|
|
|
plot_style_fill_white))
|
2006-02-13 02:07:28 +03:00
|
|
|
return false;
|
|
|
|
|
2006-02-16 02:09:55 +03:00
|
|
|
if (!line)
|
2006-02-13 02:07:28 +03:00
|
|
|
return true;
|
|
|
|
|
2006-03-26 08:48:45 +04:00
|
|
|
/* choose a suitable background colour for any highlighted text */
|
2011-06-29 00:17:39 +04:00
|
|
|
if ((data->background_colour & 0x808080) == 0x808080)
|
2009-07-06 14:38:13 +04:00
|
|
|
plot_style_highlight = plot_style_fill_black;
|
|
|
|
else
|
|
|
|
plot_style_highlight = plot_style_fill_white;
|
2006-03-26 08:48:45 +04:00
|
|
|
|
2011-03-15 18:10:10 +03:00
|
|
|
/* Set up font plot style */
|
2011-06-29 00:17:39 +04:00
|
|
|
textplain_style.background = data->background_colour;
|
2009-07-21 14:59:53 +04:00
|
|
|
|
2011-06-29 00:17:39 +04:00
|
|
|
x = (x + MARGIN) * data->scale;
|
|
|
|
y = (y + MARGIN) * data->scale;
|
2006-02-16 02:09:55 +03:00
|
|
|
for (lineno = line0; lineno != line1; lineno++) {
|
2011-07-13 17:20:26 +04:00
|
|
|
const char *text_d = utf8_data + line[lineno].start;
|
2011-06-29 00:17:39 +04:00
|
|
|
int tab_width = textplain_tab_width * data->scale;
|
2006-03-25 11:53:32 +03:00
|
|
|
size_t offset = 0;
|
|
|
|
int tx = x;
|
|
|
|
|
2006-03-26 08:48:45 +04:00
|
|
|
if (!tab_width) tab_width = 1;
|
|
|
|
|
2006-02-16 02:09:55 +03:00
|
|
|
length = line[lineno].length;
|
2006-02-13 02:07:28 +03:00
|
|
|
if (!length)
|
|
|
|
continue;
|
2006-03-25 11:53:32 +03:00
|
|
|
|
|
|
|
while (offset < length) {
|
|
|
|
size_t next_offset = offset;
|
|
|
|
int width;
|
2006-03-26 08:48:45 +04:00
|
|
|
int ntx;
|
2006-03-25 11:53:32 +03:00
|
|
|
|
2011-07-13 17:20:26 +04:00
|
|
|
while (next_offset < length && text_d[next_offset] != '\t')
|
|
|
|
next_offset = utf8_next(text_d, length, next_offset);
|
2006-03-25 11:53:32 +03:00
|
|
|
|
2011-07-13 17:20:26 +04:00
|
|
|
if (!text_redraw(text_d + offset, next_offset - offset,
|
2011-03-01 23:00:41 +03:00
|
|
|
line[lineno].start + offset, 0,
|
2006-03-25 11:53:32 +03:00
|
|
|
&textplain_style,
|
|
|
|
tx, y + (lineno * scaled_line_height),
|
2011-06-30 19:48:07 +04:00
|
|
|
clip, line_height, data->scale, false,
|
2011-08-24 16:29:30 +04:00
|
|
|
(struct content *)text, &text->sel,
|
|
|
|
text->search, ctx))
|
2006-03-25 11:53:32 +03:00
|
|
|
return false;
|
|
|
|
|
|
|
|
if (next_offset >= length)
|
|
|
|
break;
|
|
|
|
|
|
|
|
/* locate end of string and align to next tab position */
|
2011-07-13 17:20:26 +04:00
|
|
|
if (nsfont.font_width(&textplain_style, &text_d[offset],
|
2006-03-25 11:53:32 +03:00
|
|
|
next_offset - offset, &width))
|
2011-06-29 00:17:39 +04:00
|
|
|
tx += (int)(width * data->scale);
|
2006-03-26 08:48:45 +04:00
|
|
|
|
|
|
|
ntx = x + ((1 + (tx - x) / tab_width) * tab_width);
|
2006-03-25 11:53:32 +03:00
|
|
|
|
2006-03-26 08:48:45 +04:00
|
|
|
/* if the tab character lies within the selection, if any,
|
|
|
|
then we must draw it as a filled rectangle so that it's
|
|
|
|
consistent with background of the selected text */
|
|
|
|
|
|
|
|
if (bw) {
|
|
|
|
unsigned tab_ofst = line[lineno].start + next_offset;
|
2011-07-13 17:20:26 +04:00
|
|
|
struct selection *sel = &text->sel;
|
2006-03-26 08:48:45 +04:00
|
|
|
bool highlighted = false;
|
|
|
|
|
|
|
|
if (selection_defined(sel)) {
|
|
|
|
unsigned start_idx, end_idx;
|
|
|
|
if (selection_highlighted(sel,
|
|
|
|
tab_ofst, tab_ofst + 1,
|
|
|
|
&start_idx, &end_idx))
|
|
|
|
highlighted = true;
|
|
|
|
}
|
|
|
|
|
2011-08-24 16:29:30 +04:00
|
|
|
if (!highlighted && (text->search != NULL)) {
|
2006-03-26 08:48:45 +04:00
|
|
|
unsigned start_idx, end_idx;
|
2011-08-24 16:29:30 +04:00
|
|
|
if (search_term_highlighted(c,
|
2009-12-18 02:55:02 +03:00
|
|
|
tab_ofst, tab_ofst + 1,
|
|
|
|
&start_idx, &end_idx,
|
2011-08-24 16:29:30 +04:00
|
|
|
text->search))
|
2006-03-26 08:48:45 +04:00
|
|
|
highlighted = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (highlighted) {
|
|
|
|
int sy = y + (lineno * scaled_line_height);
|
2011-06-30 19:48:07 +04:00
|
|
|
if (!plot->rectangle(tx, sy,
|
2009-07-09 02:04:40 +04:00
|
|
|
ntx, sy + scaled_line_height,
|
|
|
|
plot_style_highlight))
|
2006-03-26 08:48:45 +04:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
2006-03-25 11:53:32 +03:00
|
|
|
|
|
|
|
offset = next_offset + 1;
|
2006-03-26 08:48:45 +04:00
|
|
|
tx = ntx;
|
2006-03-25 11:53:32 +03:00
|
|
|
}
|
2006-02-13 02:07:28 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
2003-02-09 15:58:15 +03:00
|
|
|
}
|
2006-02-16 02:09:55 +03:00
|
|
|
|
2011-06-30 22:27:24 +04:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Handle a window containing a CONTENT_TEXTPLAIN being opened.
|
|
|
|
*/
|
|
|
|
|
|
|
|
void textplain_open(struct content *c, struct browser_window *bw,
|
|
|
|
struct content *page, struct box *box,
|
|
|
|
struct object_params *params)
|
|
|
|
{
|
2011-07-01 15:16:43 +04:00
|
|
|
textplain_content *text = (textplain_content *) c;
|
|
|
|
|
|
|
|
text->bw = bw;
|
2011-07-02 16:34:35 +04:00
|
|
|
|
2011-07-13 17:20:26 +04:00
|
|
|
/* text selection */
|
|
|
|
selection_init(&text->sel, NULL);
|
2011-07-01 15:16:43 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Handle a window containing a CONTENT_TEXTPLAIN being closed.
|
|
|
|
*/
|
|
|
|
|
|
|
|
void textplain_close(struct content *c)
|
|
|
|
{
|
|
|
|
textplain_content *text = (textplain_content *) c;
|
|
|
|
|
2011-08-24 16:29:30 +04:00
|
|
|
if (text->search != NULL)
|
|
|
|
search_destroy_context(text->search);
|
|
|
|
|
2011-07-01 15:16:43 +04:00
|
|
|
text->bw = NULL;
|
2011-06-30 22:27:24 +04:00
|
|
|
}
|
|
|
|
|
2011-07-13 17:20:26 +04:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Return an textplain content's selection context
|
|
|
|
*/
|
|
|
|
|
|
|
|
struct selection *textplain_get_selection(struct content *c)
|
|
|
|
{
|
|
|
|
textplain_content *text = (textplain_content *) c;
|
|
|
|
|
|
|
|
return &text->sel;
|
|
|
|
}
|
|
|
|
|
2011-08-24 16:29:30 +04:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Set an TEXTPLAIN content's search context
|
|
|
|
*
|
|
|
|
* \param c content of type text
|
|
|
|
* \param s search context, or NULL if none
|
|
|
|
*/
|
|
|
|
|
|
|
|
void textplain_set_search(struct content *c, struct search_context *s)
|
|
|
|
{
|
|
|
|
textplain_content *text = (textplain_content *) c;
|
|
|
|
|
|
|
|
text->search = s;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Return an TEXTPLAIN content's search context
|
|
|
|
*
|
|
|
|
* \param c content of type text
|
|
|
|
* \return content's search context, or NULL if none
|
|
|
|
*/
|
|
|
|
|
|
|
|
struct search_context *textplain_get_search(struct content *c)
|
|
|
|
{
|
|
|
|
textplain_content *text = (textplain_content *) c;
|
|
|
|
|
|
|
|
return text->search;
|
|
|
|
}
|
|
|
|
|
2010-03-28 16:56:39 +04:00
|
|
|
/**
|
|
|
|
* Retrieve number of lines in content
|
|
|
|
*
|
|
|
|
* \param h Content to retrieve line count from
|
|
|
|
* \return Number of lines
|
|
|
|
*/
|
2011-07-26 17:53:42 +04:00
|
|
|
unsigned long textplain_line_count(struct content *c)
|
2010-03-28 16:56:39 +04:00
|
|
|
{
|
2011-07-26 17:53:42 +04:00
|
|
|
textplain_content *text = (textplain_content *) c;
|
2010-03-28 16:56:39 +04:00
|
|
|
|
|
|
|
assert(c != NULL);
|
|
|
|
|
2011-07-26 17:53:42 +04:00
|
|
|
return text->physical_line_count;
|
2010-03-28 16:56:39 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Retrieve the size (in bytes) of text data
|
|
|
|
*
|
|
|
|
* \param h Content to retrieve size of
|
|
|
|
* \return Size, in bytes, of data
|
|
|
|
*/
|
2011-07-26 17:53:42 +04:00
|
|
|
size_t textplain_size(struct content *c)
|
2010-03-28 16:56:39 +04:00
|
|
|
{
|
2011-07-26 17:53:42 +04:00
|
|
|
textplain_content *text = (textplain_content *) c;
|
2010-03-28 16:56:39 +04:00
|
|
|
|
|
|
|
assert(c != NULL);
|
|
|
|
|
2011-07-26 17:53:42 +04:00
|
|
|
return text->utf8_data_size;
|
2010-03-28 16:56:39 +04:00
|
|
|
}
|
2006-02-16 02:09:55 +03:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Return byte offset within UTF8 textplain content, given the co-ordinates
|
|
|
|
* of a point within a textplain content. 'dir' specifies the direction in
|
|
|
|
* which to search (-1 = above-left, +1 = below-right) if the co-ordinates are not
|
|
|
|
* contained within a line.
|
|
|
|
*
|
2010-03-28 16:56:39 +04:00
|
|
|
* \param h content of type CONTENT_TEXTPLAIN
|
2006-02-16 02:09:55 +03:00
|
|
|
* \param x x ordinate of point
|
|
|
|
* \param y y ordinate of point
|
|
|
|
* \param dir direction of search if not within line
|
2006-03-26 08:48:45 +04:00
|
|
|
* \return byte offset of character containing (or nearest to) point
|
2006-02-16 02:09:55 +03:00
|
|
|
*/
|
|
|
|
|
2011-07-26 17:53:42 +04:00
|
|
|
size_t textplain_offset_from_coords(struct content *c, int x, int y, int dir)
|
2006-02-16 02:09:55 +03:00
|
|
|
{
|
2011-07-26 17:53:42 +04:00
|
|
|
textplain_content *textc = (textplain_content *) c;
|
2009-07-21 14:59:53 +04:00
|
|
|
float line_height = textplain_line_height();
|
2006-02-16 02:09:55 +03:00
|
|
|
struct textplain_line *line;
|
2006-03-26 08:48:45 +04:00
|
|
|
const char *text;
|
2006-02-16 02:09:55 +03:00
|
|
|
unsigned nlines;
|
2006-03-26 08:48:45 +04:00
|
|
|
size_t length;
|
2006-02-16 02:09:55 +03:00
|
|
|
int idx;
|
|
|
|
|
2010-03-28 16:56:39 +04:00
|
|
|
assert(c != NULL);
|
2006-02-16 02:09:55 +03:00
|
|
|
|
|
|
|
y = (int)((float)(y - MARGIN) / line_height);
|
|
|
|
x -= MARGIN;
|
|
|
|
|
2011-07-26 17:53:42 +04:00
|
|
|
nlines = textc->physical_line_count;
|
2006-02-16 02:09:55 +03:00
|
|
|
if (!nlines)
|
|
|
|
return 0;
|
|
|
|
|
2006-03-26 08:48:45 +04:00
|
|
|
if (y <= 0) y = 0;
|
|
|
|
else if ((unsigned)y >= nlines)
|
2006-02-16 02:09:55 +03:00
|
|
|
y = nlines - 1;
|
2006-03-26 08:48:45 +04:00
|
|
|
|
2011-07-26 17:53:42 +04:00
|
|
|
line = &textc->physical_line[y];
|
|
|
|
text = textc->utf8_data + line->start;
|
2006-03-26 08:48:45 +04:00
|
|
|
length = line->length;
|
|
|
|
idx = 0;
|
|
|
|
|
|
|
|
while (x > 0) {
|
|
|
|
size_t next_offset = 0;
|
|
|
|
int width = INT_MAX;
|
|
|
|
|
|
|
|
while (next_offset < length && text[next_offset] != '\t')
|
2006-03-26 09:46:21 +04:00
|
|
|
next_offset = utf8_next(text, length, next_offset);
|
2006-02-16 02:09:55 +03:00
|
|
|
|
2006-03-26 08:48:45 +04:00
|
|
|
if (next_offset < length)
|
First merge of Adam Blokus' GSoC work from his branch 'branches/adamblokus/netsurf'.
Merged revisions 4212-4552,4554-4709,4711-4724 via svnmerge from
svn://svn.netsurf-browser.org/branches/adamblokus/netsurf
........
r4212 | adamblokus | 2008-05-26 19:42:31 +0200 (Mon, 26 May 2008) | 4 lines
Pdf plotting skeleton pinned on Print Preview in GTK.
Just creates a file and draws lines.
........
r4213 | adamblokus | 2008-05-27 00:11:03 +0200 (Tue, 27 May 2008) | 4 lines
Pdf plotter - added drawing some graphic primitives.
Still with limited functionality, but a snapshot of the
currently viewed page can be made and resembles the original.
........
r4214 | adamblokus | 2008-05-27 11:43:31 +0200 (Tue, 27 May 2008) | 2 lines
Corrected encoding name
........
r4215 | adamblokus | 2008-05-27 12:47:26 +0200 (Tue, 27 May 2008) | 3 lines
Colours and polygons added.
........
r4217 | adamblokus | 2008-05-27 21:39:35 +0200 (Tue, 27 May 2008) | 6 lines
Added rectangles, filled boxes and clipping.
Taken into consideration joty's comments.
Added a todo list for this part.
Added some debug stuff and checking boundaries.
........
r4218 | adamblokus | 2008-05-28 12:37:30 +0200 (Wed, 28 May 2008) | 2 lines
Added path ploting (not sure if valid argument order for bezier) and dashed/dotted line styles
........
r4221 | adamblokus | 2008-05-28 22:11:05 +0200 (Wed, 28 May 2008) | 3 lines
Some more options in graphic primitives and normalizing some parameters.
........
r4235 | adamblokus | 2008-05-31 22:54:56 +0200 (Sat, 31 May 2008) | 4 lines
Plotting changed as jmb suggested (is the least invasive one from the possible)
Added dummy bitmap plotting - way of plotting an image is determined by its type.
........
r4251 | adamblokus | 2008-06-03 17:12:15 +0200 (Tue, 03 Jun 2008) | 3 lines
Added plotting jpg and png images - quite a lot to improve in this code, but it seems to work ;)
........
r4263 | adamblokus | 2008-06-05 14:20:32 +0200 (Thu, 05 Jun 2008) | 3 lines
Added hadling images other than png and jpeg - with transparency.
........
r4267 | adamblokus | 2008-06-06 15:36:34 +0200 (Fri, 06 Jun 2008) | 5 lines
Added handling NULL-returns from all mallocs.
Added plot_bitmap_tile handling.
Changed code style a little.
........
r4327 | adamblokus | 2008-06-12 17:46:34 +0200 (Thu, 12 Jun 2008) | 5 lines
Added a first prototype of the paged-output organization.
Still not sure about naming, file locations etc.
Works with the same pdf plotting as before.
........
r4328 | adamblokus | 2008-06-13 13:52:15 +0200 (Fri, 13 Jun 2008) | 4 lines
Added primitive width adjustment and outputing the whole
website in multiple pages.
........
r4336 | joty | 2008-06-15 15:06:57 +0200 (Sun, 15 Jun 2008) | 1 line
Fix RISC OS build failure (change r4235 wasn't complete).
........
r4337 | joty | 2008-06-15 18:15:32 +0200 (Sun, 15 Jun 2008) | 16 lines
This enables "Export PDF" in RISC OS build:
- Docs/Doxyfile(PREDEFINED): Added WITH_PDF_EXPORT
- Makefile.sources(S_PDF): Add to RISC OS target as well.
- utils/config.h: Define WITH_PDF_EXPORT which controls if we want to have
PDF export functionality or not.
- riscos/save_pdf.c,riscos/save_pdf.h(save_as_pdf): Use PDF print API made
by Adam Blokus to write a PDF file under RISC OS.
- riscos/save.c: Call save_as_pdf added.
- riscos/menus.c: Add 'Export->PDF' menu entry.
- riscos/menus.h(menu_action): Added BROWSER_EXPORT_PDF.
- desktop/gui.h(gui_save_type): Added GUI_SAVE_PDF.
- desktop/print.c(print_run): Added return value.
- Makefile(CCACHE): Moved closed to the place where CC is set for the first time.
(LDFLAGS): Centralised adding all non-pkgconfig libraries and added Haru + PNG libs.
........
r4343 | adamblokus | 2008-06-16 01:08:52 +0200 (Mon, 16 Jun 2008) | 3 lines
Added margins and page size adjustment.
........
r4412 | adamblokus | 2008-06-21 20:22:07 +0200 (Sat, 21 Jun 2008) | 4 lines
Added 'fuzzy' margins on page bottom.
Disabled direct png embedding, because it is too unstable in Haru now.
........
r4421 | adamblokus | 2008-06-22 18:52:28 +0200 (Sun, 22 Jun 2008) | 2 lines
Added "Save as.." dialog and Export->PDF menu entry. Print preview still works with default path.
........
r4437 | adamblokus | 2008-06-25 02:44:46 +0200 (Wed, 25 Jun 2008) | 4 lines
Added skeleton of applying loose layout.
Minor code cleaning-up.
........
r4492 | adamblokus | 2008-07-02 09:02:42 +0200 (Wed, 02 Jul 2008) | 5 lines
Implemented the elementar ideas of the loose layout.
Added scaling in the printing routine.
Added some basic demonstrations.
........
r4493 | adamblokus | 2008-07-02 09:05:55 +0200 (Wed, 02 Jul 2008) | 3 lines
Cleaned up the loosing code - commited to much of leftover rubbish code.
........
r4507 | adamblokus | 2008-07-04 14:25:48 +0200 (Fri, 04 Jul 2008) | 4 lines
Added duplicating box tree and current content - window flickering during printing solved.
Minor error checking after new HPDF_Image_AddSMask call.
........
r4515 | adamblokus | 2008-07-06 22:28:16 +0200 (Sun, 06 Jul 2008) | 2 lines
Changes in loosen layout (image resizing).
........
r4517 | adamblokus | 2008-07-06 22:38:23 +0200 (Sun, 06 Jul 2008) | 2 lines
Added pdf font handling and rendering functions with the use of Haru functions.
........
r4555 | adamblokus | 2008-07-10 00:59:05 +0200 (Thu, 10 Jul 2008) | 2 lines
Added a very basic and still buggy GTK print implementation.
........
r4565 | adamblokus | 2008-07-10 14:50:16 +0200 (Thu, 10 Jul 2008) | 2 lines
Added gtk printing one more time - I have forgotten to add the main file.
........
r4566 | adamblokus | 2008-07-10 14:57:02 +0200 (Thu, 10 Jul 2008) | 2 lines
removed error with comment
........
r4569 | adamblokus | 2008-07-10 15:52:55 +0200 (Thu, 10 Jul 2008) | 5 lines
Major style improvements - added a lot of doxygen comments,
followed tlsa's style guide.
Added some more error checking, too.
........
r4575 | adamblokus | 2008-07-10 18:48:26 +0200 (Thu, 10 Jul 2008) | 2 lines
Cleaned up the code.
........
r4687 | adamblokus | 2008-07-17 14:17:19 +0200 (Thu, 17 Jul 2008) | 2 lines
Changed everything according to jmb's review plus some minor bug fixes to gtk_print.
........
r4688 | adamblokus | 2008-07-17 17:16:34 +0200 (Thu, 17 Jul 2008) | 2 lines
Solved the netsurf.glade clash from r4421.
........
r4693 | adamblokus | 2008-07-18 18:11:51 +0200 (Fri, 18 Jul 2008) | 2 lines
Fixed bug with wrong number of pages in gtk printing.
........
r4695 | adamblokus | 2008-07-18 19:59:24 +0200 (Fri, 18 Jul 2008) | 3 lines
- fixed uncommented line from the previous commit
- fixed bug with scale bigger than 1.0 (incorretly clipped page)
........
r4696 | adamblokus | 2008-07-18 23:28:00 +0200 (Fri, 18 Jul 2008) | 2 lines
Fixed bug in gtk_print_font_paint (and nsfont_paint).
........
r4697 | adamblokus | 2008-07-18 23:35:38 +0200 (Fri, 18 Jul 2008) | 2 lines
Bug fix in nsfont_paint.
........
r4711 | adamblokus | 2008-07-19 22:44:15 +0200 (Sat, 19 Jul 2008) | 2 lines
Added gtk_selection files.
........
r4712 | adamblokus | 2008-07-20 11:15:06 +0200 (Sun, 20 Jul 2008) | 2 lines
Addam missing glade files.
........
r4713 | joty | 2008-07-20 17:13:10 +0200 (Sun, 20 Jul 2008) | 1 line
Follow change r4517 for RISC OS and BeOS platforms : Added pdf font handling and rendering functions with the use of Haru functions.
........
r4714 | joty | 2008-07-20 18:19:50 +0200 (Sun, 20 Jul 2008) | 1 line
Declare haru_nsfont iso define an instance for each C source including the font_haru.h header. This fixes breakage of PDF export on RISC OS.
........
r4724 | adamblokus | 2008-07-23 03:30:08 +0200 (Wed, 23 Jul 2008) | 6 lines
Applied changes according to joty's review.
Added checking the dimensions of a plotted image to pdf plotter.
Commented out jpg embedding (it seems to cause some problems
I'll bring it back when I figure out what's wrong) .
Added back some files removed by mistake.
........
svn path=/trunk/netsurf/; revision=4741
2008-07-26 20:01:59 +04:00
|
|
|
nsfont.font_width(&textplain_style, text, next_offset, &width);
|
2006-03-26 08:48:45 +04:00
|
|
|
|
2006-03-26 09:46:21 +04:00
|
|
|
if (x <= width) {
|
2006-03-26 08:48:45 +04:00
|
|
|
int pixel_offset;
|
2008-02-25 20:58:00 +03:00
|
|
|
size_t char_offset;
|
2006-03-26 08:48:45 +04:00
|
|
|
|
First merge of Adam Blokus' GSoC work from his branch 'branches/adamblokus/netsurf'.
Merged revisions 4212-4552,4554-4709,4711-4724 via svnmerge from
svn://svn.netsurf-browser.org/branches/adamblokus/netsurf
........
r4212 | adamblokus | 2008-05-26 19:42:31 +0200 (Mon, 26 May 2008) | 4 lines
Pdf plotting skeleton pinned on Print Preview in GTK.
Just creates a file and draws lines.
........
r4213 | adamblokus | 2008-05-27 00:11:03 +0200 (Tue, 27 May 2008) | 4 lines
Pdf plotter - added drawing some graphic primitives.
Still with limited functionality, but a snapshot of the
currently viewed page can be made and resembles the original.
........
r4214 | adamblokus | 2008-05-27 11:43:31 +0200 (Tue, 27 May 2008) | 2 lines
Corrected encoding name
........
r4215 | adamblokus | 2008-05-27 12:47:26 +0200 (Tue, 27 May 2008) | 3 lines
Colours and polygons added.
........
r4217 | adamblokus | 2008-05-27 21:39:35 +0200 (Tue, 27 May 2008) | 6 lines
Added rectangles, filled boxes and clipping.
Taken into consideration joty's comments.
Added a todo list for this part.
Added some debug stuff and checking boundaries.
........
r4218 | adamblokus | 2008-05-28 12:37:30 +0200 (Wed, 28 May 2008) | 2 lines
Added path ploting (not sure if valid argument order for bezier) and dashed/dotted line styles
........
r4221 | adamblokus | 2008-05-28 22:11:05 +0200 (Wed, 28 May 2008) | 3 lines
Some more options in graphic primitives and normalizing some parameters.
........
r4235 | adamblokus | 2008-05-31 22:54:56 +0200 (Sat, 31 May 2008) | 4 lines
Plotting changed as jmb suggested (is the least invasive one from the possible)
Added dummy bitmap plotting - way of plotting an image is determined by its type.
........
r4251 | adamblokus | 2008-06-03 17:12:15 +0200 (Tue, 03 Jun 2008) | 3 lines
Added plotting jpg and png images - quite a lot to improve in this code, but it seems to work ;)
........
r4263 | adamblokus | 2008-06-05 14:20:32 +0200 (Thu, 05 Jun 2008) | 3 lines
Added hadling images other than png and jpeg - with transparency.
........
r4267 | adamblokus | 2008-06-06 15:36:34 +0200 (Fri, 06 Jun 2008) | 5 lines
Added handling NULL-returns from all mallocs.
Added plot_bitmap_tile handling.
Changed code style a little.
........
r4327 | adamblokus | 2008-06-12 17:46:34 +0200 (Thu, 12 Jun 2008) | 5 lines
Added a first prototype of the paged-output organization.
Still not sure about naming, file locations etc.
Works with the same pdf plotting as before.
........
r4328 | adamblokus | 2008-06-13 13:52:15 +0200 (Fri, 13 Jun 2008) | 4 lines
Added primitive width adjustment and outputing the whole
website in multiple pages.
........
r4336 | joty | 2008-06-15 15:06:57 +0200 (Sun, 15 Jun 2008) | 1 line
Fix RISC OS build failure (change r4235 wasn't complete).
........
r4337 | joty | 2008-06-15 18:15:32 +0200 (Sun, 15 Jun 2008) | 16 lines
This enables "Export PDF" in RISC OS build:
- Docs/Doxyfile(PREDEFINED): Added WITH_PDF_EXPORT
- Makefile.sources(S_PDF): Add to RISC OS target as well.
- utils/config.h: Define WITH_PDF_EXPORT which controls if we want to have
PDF export functionality or not.
- riscos/save_pdf.c,riscos/save_pdf.h(save_as_pdf): Use PDF print API made
by Adam Blokus to write a PDF file under RISC OS.
- riscos/save.c: Call save_as_pdf added.
- riscos/menus.c: Add 'Export->PDF' menu entry.
- riscos/menus.h(menu_action): Added BROWSER_EXPORT_PDF.
- desktop/gui.h(gui_save_type): Added GUI_SAVE_PDF.
- desktop/print.c(print_run): Added return value.
- Makefile(CCACHE): Moved closed to the place where CC is set for the first time.
(LDFLAGS): Centralised adding all non-pkgconfig libraries and added Haru + PNG libs.
........
r4343 | adamblokus | 2008-06-16 01:08:52 +0200 (Mon, 16 Jun 2008) | 3 lines
Added margins and page size adjustment.
........
r4412 | adamblokus | 2008-06-21 20:22:07 +0200 (Sat, 21 Jun 2008) | 4 lines
Added 'fuzzy' margins on page bottom.
Disabled direct png embedding, because it is too unstable in Haru now.
........
r4421 | adamblokus | 2008-06-22 18:52:28 +0200 (Sun, 22 Jun 2008) | 2 lines
Added "Save as.." dialog and Export->PDF menu entry. Print preview still works with default path.
........
r4437 | adamblokus | 2008-06-25 02:44:46 +0200 (Wed, 25 Jun 2008) | 4 lines
Added skeleton of applying loose layout.
Minor code cleaning-up.
........
r4492 | adamblokus | 2008-07-02 09:02:42 +0200 (Wed, 02 Jul 2008) | 5 lines
Implemented the elementar ideas of the loose layout.
Added scaling in the printing routine.
Added some basic demonstrations.
........
r4493 | adamblokus | 2008-07-02 09:05:55 +0200 (Wed, 02 Jul 2008) | 3 lines
Cleaned up the loosing code - commited to much of leftover rubbish code.
........
r4507 | adamblokus | 2008-07-04 14:25:48 +0200 (Fri, 04 Jul 2008) | 4 lines
Added duplicating box tree and current content - window flickering during printing solved.
Minor error checking after new HPDF_Image_AddSMask call.
........
r4515 | adamblokus | 2008-07-06 22:28:16 +0200 (Sun, 06 Jul 2008) | 2 lines
Changes in loosen layout (image resizing).
........
r4517 | adamblokus | 2008-07-06 22:38:23 +0200 (Sun, 06 Jul 2008) | 2 lines
Added pdf font handling and rendering functions with the use of Haru functions.
........
r4555 | adamblokus | 2008-07-10 00:59:05 +0200 (Thu, 10 Jul 2008) | 2 lines
Added a very basic and still buggy GTK print implementation.
........
r4565 | adamblokus | 2008-07-10 14:50:16 +0200 (Thu, 10 Jul 2008) | 2 lines
Added gtk printing one more time - I have forgotten to add the main file.
........
r4566 | adamblokus | 2008-07-10 14:57:02 +0200 (Thu, 10 Jul 2008) | 2 lines
removed error with comment
........
r4569 | adamblokus | 2008-07-10 15:52:55 +0200 (Thu, 10 Jul 2008) | 5 lines
Major style improvements - added a lot of doxygen comments,
followed tlsa's style guide.
Added some more error checking, too.
........
r4575 | adamblokus | 2008-07-10 18:48:26 +0200 (Thu, 10 Jul 2008) | 2 lines
Cleaned up the code.
........
r4687 | adamblokus | 2008-07-17 14:17:19 +0200 (Thu, 17 Jul 2008) | 2 lines
Changed everything according to jmb's review plus some minor bug fixes to gtk_print.
........
r4688 | adamblokus | 2008-07-17 17:16:34 +0200 (Thu, 17 Jul 2008) | 2 lines
Solved the netsurf.glade clash from r4421.
........
r4693 | adamblokus | 2008-07-18 18:11:51 +0200 (Fri, 18 Jul 2008) | 2 lines
Fixed bug with wrong number of pages in gtk printing.
........
r4695 | adamblokus | 2008-07-18 19:59:24 +0200 (Fri, 18 Jul 2008) | 3 lines
- fixed uncommented line from the previous commit
- fixed bug with scale bigger than 1.0 (incorretly clipped page)
........
r4696 | adamblokus | 2008-07-18 23:28:00 +0200 (Fri, 18 Jul 2008) | 2 lines
Fixed bug in gtk_print_font_paint (and nsfont_paint).
........
r4697 | adamblokus | 2008-07-18 23:35:38 +0200 (Fri, 18 Jul 2008) | 2 lines
Bug fix in nsfont_paint.
........
r4711 | adamblokus | 2008-07-19 22:44:15 +0200 (Sat, 19 Jul 2008) | 2 lines
Added gtk_selection files.
........
r4712 | adamblokus | 2008-07-20 11:15:06 +0200 (Sun, 20 Jul 2008) | 2 lines
Addam missing glade files.
........
r4713 | joty | 2008-07-20 17:13:10 +0200 (Sun, 20 Jul 2008) | 1 line
Follow change r4517 for RISC OS and BeOS platforms : Added pdf font handling and rendering functions with the use of Haru functions.
........
r4714 | joty | 2008-07-20 18:19:50 +0200 (Sun, 20 Jul 2008) | 1 line
Declare haru_nsfont iso define an instance for each C source including the font_haru.h header. This fixes breakage of PDF export on RISC OS.
........
r4724 | adamblokus | 2008-07-23 03:30:08 +0200 (Wed, 23 Jul 2008) | 6 lines
Applied changes according to joty's review.
Added checking the dimensions of a plotted image to pdf plotter.
Commented out jpg embedding (it seems to cause some problems
I'll bring it back when I figure out what's wrong) .
Added back some files removed by mistake.
........
svn path=/trunk/netsurf/; revision=4741
2008-07-26 20:01:59 +04:00
|
|
|
nsfont.font_position_in_string(&textplain_style,
|
2006-03-26 08:48:45 +04:00
|
|
|
text, next_offset, x,
|
|
|
|
&char_offset, &pixel_offset);
|
|
|
|
|
|
|
|
idx += char_offset;
|
|
|
|
break;
|
|
|
|
}
|
2006-02-16 02:09:55 +03:00
|
|
|
|
2006-03-26 08:48:45 +04:00
|
|
|
x -= width;
|
|
|
|
length -= next_offset;
|
|
|
|
text += next_offset;
|
|
|
|
idx += next_offset;
|
|
|
|
|
|
|
|
/* check if it's within the tab */
|
|
|
|
width = textplain_tab_width - (width % textplain_tab_width);
|
2006-03-26 09:46:21 +04:00
|
|
|
if (x <= width) break;
|
2006-03-26 08:48:45 +04:00
|
|
|
|
|
|
|
x -= width;
|
|
|
|
length--;
|
|
|
|
text++;
|
|
|
|
idx++;
|
|
|
|
}
|
2006-02-16 02:09:55 +03:00
|
|
|
|
|
|
|
return line->start + idx;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Given a byte offset within the text, return the line number
|
|
|
|
* of the line containing that offset (or -1 if offset invalid)
|
|
|
|
*
|
2011-07-26 17:53:42 +04:00
|
|
|
* \param c content of type CONTENT_TEXTPLAIN
|
2006-02-16 02:09:55 +03:00
|
|
|
* \param offset byte offset within textual representation
|
|
|
|
* \return line number, or -1 if offset invalid (larger than size)
|
|
|
|
*/
|
|
|
|
|
2011-07-26 17:53:42 +04:00
|
|
|
int textplain_find_line(struct content *c, unsigned offset)
|
2006-02-16 02:09:55 +03:00
|
|
|
{
|
2011-07-26 17:53:42 +04:00
|
|
|
textplain_content *text = (textplain_content *) c;
|
2010-03-28 16:56:39 +04:00
|
|
|
struct textplain_line *line;
|
|
|
|
int nlines;
|
2006-02-16 02:09:55 +03:00
|
|
|
int lineno = 0;
|
|
|
|
|
2010-03-28 16:56:39 +04:00
|
|
|
assert(c != NULL);
|
2006-02-16 02:09:55 +03:00
|
|
|
|
2011-07-26 17:53:42 +04:00
|
|
|
line = text->physical_line;
|
|
|
|
nlines = text->physical_line_count;
|
2010-03-28 16:56:39 +04:00
|
|
|
|
2011-07-26 17:53:42 +04:00
|
|
|
if (offset > text->utf8_data_size)
|
2006-02-16 02:09:55 +03:00
|
|
|
return -1;
|
|
|
|
|
|
|
|
/* \todo - implement binary search here */
|
|
|
|
while (lineno < nlines && line[lineno].start < offset)
|
|
|
|
lineno++;
|
|
|
|
if (line[lineno].start > offset)
|
|
|
|
lineno--;
|
|
|
|
|
|
|
|
return lineno;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2006-03-26 08:48:45 +04:00
|
|
|
/**
|
|
|
|
* Convert a character offset within a line of text into the
|
|
|
|
* horizontal co-ordinate, taking into account the font being
|
|
|
|
* used and any tabs in the text
|
|
|
|
*
|
|
|
|
* \param text line of text
|
|
|
|
* \param offset char offset within text
|
|
|
|
* \param length line length
|
|
|
|
* \return x ordinate
|
|
|
|
*/
|
|
|
|
|
|
|
|
int textplain_coord_from_offset(const char *text, size_t offset, size_t length)
|
|
|
|
{
|
|
|
|
int x = 0;
|
|
|
|
|
|
|
|
while (offset > 0) {
|
|
|
|
size_t next_offset = 0;
|
|
|
|
int tx;
|
|
|
|
|
|
|
|
while (next_offset < offset && text[next_offset] != '\t')
|
|
|
|
next_offset = utf8_next(text, length, next_offset);
|
|
|
|
|
First merge of Adam Blokus' GSoC work from his branch 'branches/adamblokus/netsurf'.
Merged revisions 4212-4552,4554-4709,4711-4724 via svnmerge from
svn://svn.netsurf-browser.org/branches/adamblokus/netsurf
........
r4212 | adamblokus | 2008-05-26 19:42:31 +0200 (Mon, 26 May 2008) | 4 lines
Pdf plotting skeleton pinned on Print Preview in GTK.
Just creates a file and draws lines.
........
r4213 | adamblokus | 2008-05-27 00:11:03 +0200 (Tue, 27 May 2008) | 4 lines
Pdf plotter - added drawing some graphic primitives.
Still with limited functionality, but a snapshot of the
currently viewed page can be made and resembles the original.
........
r4214 | adamblokus | 2008-05-27 11:43:31 +0200 (Tue, 27 May 2008) | 2 lines
Corrected encoding name
........
r4215 | adamblokus | 2008-05-27 12:47:26 +0200 (Tue, 27 May 2008) | 3 lines
Colours and polygons added.
........
r4217 | adamblokus | 2008-05-27 21:39:35 +0200 (Tue, 27 May 2008) | 6 lines
Added rectangles, filled boxes and clipping.
Taken into consideration joty's comments.
Added a todo list for this part.
Added some debug stuff and checking boundaries.
........
r4218 | adamblokus | 2008-05-28 12:37:30 +0200 (Wed, 28 May 2008) | 2 lines
Added path ploting (not sure if valid argument order for bezier) and dashed/dotted line styles
........
r4221 | adamblokus | 2008-05-28 22:11:05 +0200 (Wed, 28 May 2008) | 3 lines
Some more options in graphic primitives and normalizing some parameters.
........
r4235 | adamblokus | 2008-05-31 22:54:56 +0200 (Sat, 31 May 2008) | 4 lines
Plotting changed as jmb suggested (is the least invasive one from the possible)
Added dummy bitmap plotting - way of plotting an image is determined by its type.
........
r4251 | adamblokus | 2008-06-03 17:12:15 +0200 (Tue, 03 Jun 2008) | 3 lines
Added plotting jpg and png images - quite a lot to improve in this code, but it seems to work ;)
........
r4263 | adamblokus | 2008-06-05 14:20:32 +0200 (Thu, 05 Jun 2008) | 3 lines
Added hadling images other than png and jpeg - with transparency.
........
r4267 | adamblokus | 2008-06-06 15:36:34 +0200 (Fri, 06 Jun 2008) | 5 lines
Added handling NULL-returns from all mallocs.
Added plot_bitmap_tile handling.
Changed code style a little.
........
r4327 | adamblokus | 2008-06-12 17:46:34 +0200 (Thu, 12 Jun 2008) | 5 lines
Added a first prototype of the paged-output organization.
Still not sure about naming, file locations etc.
Works with the same pdf plotting as before.
........
r4328 | adamblokus | 2008-06-13 13:52:15 +0200 (Fri, 13 Jun 2008) | 4 lines
Added primitive width adjustment and outputing the whole
website in multiple pages.
........
r4336 | joty | 2008-06-15 15:06:57 +0200 (Sun, 15 Jun 2008) | 1 line
Fix RISC OS build failure (change r4235 wasn't complete).
........
r4337 | joty | 2008-06-15 18:15:32 +0200 (Sun, 15 Jun 2008) | 16 lines
This enables "Export PDF" in RISC OS build:
- Docs/Doxyfile(PREDEFINED): Added WITH_PDF_EXPORT
- Makefile.sources(S_PDF): Add to RISC OS target as well.
- utils/config.h: Define WITH_PDF_EXPORT which controls if we want to have
PDF export functionality or not.
- riscos/save_pdf.c,riscos/save_pdf.h(save_as_pdf): Use PDF print API made
by Adam Blokus to write a PDF file under RISC OS.
- riscos/save.c: Call save_as_pdf added.
- riscos/menus.c: Add 'Export->PDF' menu entry.
- riscos/menus.h(menu_action): Added BROWSER_EXPORT_PDF.
- desktop/gui.h(gui_save_type): Added GUI_SAVE_PDF.
- desktop/print.c(print_run): Added return value.
- Makefile(CCACHE): Moved closed to the place where CC is set for the first time.
(LDFLAGS): Centralised adding all non-pkgconfig libraries and added Haru + PNG libs.
........
r4343 | adamblokus | 2008-06-16 01:08:52 +0200 (Mon, 16 Jun 2008) | 3 lines
Added margins and page size adjustment.
........
r4412 | adamblokus | 2008-06-21 20:22:07 +0200 (Sat, 21 Jun 2008) | 4 lines
Added 'fuzzy' margins on page bottom.
Disabled direct png embedding, because it is too unstable in Haru now.
........
r4421 | adamblokus | 2008-06-22 18:52:28 +0200 (Sun, 22 Jun 2008) | 2 lines
Added "Save as.." dialog and Export->PDF menu entry. Print preview still works with default path.
........
r4437 | adamblokus | 2008-06-25 02:44:46 +0200 (Wed, 25 Jun 2008) | 4 lines
Added skeleton of applying loose layout.
Minor code cleaning-up.
........
r4492 | adamblokus | 2008-07-02 09:02:42 +0200 (Wed, 02 Jul 2008) | 5 lines
Implemented the elementar ideas of the loose layout.
Added scaling in the printing routine.
Added some basic demonstrations.
........
r4493 | adamblokus | 2008-07-02 09:05:55 +0200 (Wed, 02 Jul 2008) | 3 lines
Cleaned up the loosing code - commited to much of leftover rubbish code.
........
r4507 | adamblokus | 2008-07-04 14:25:48 +0200 (Fri, 04 Jul 2008) | 4 lines
Added duplicating box tree and current content - window flickering during printing solved.
Minor error checking after new HPDF_Image_AddSMask call.
........
r4515 | adamblokus | 2008-07-06 22:28:16 +0200 (Sun, 06 Jul 2008) | 2 lines
Changes in loosen layout (image resizing).
........
r4517 | adamblokus | 2008-07-06 22:38:23 +0200 (Sun, 06 Jul 2008) | 2 lines
Added pdf font handling and rendering functions with the use of Haru functions.
........
r4555 | adamblokus | 2008-07-10 00:59:05 +0200 (Thu, 10 Jul 2008) | 2 lines
Added a very basic and still buggy GTK print implementation.
........
r4565 | adamblokus | 2008-07-10 14:50:16 +0200 (Thu, 10 Jul 2008) | 2 lines
Added gtk printing one more time - I have forgotten to add the main file.
........
r4566 | adamblokus | 2008-07-10 14:57:02 +0200 (Thu, 10 Jul 2008) | 2 lines
removed error with comment
........
r4569 | adamblokus | 2008-07-10 15:52:55 +0200 (Thu, 10 Jul 2008) | 5 lines
Major style improvements - added a lot of doxygen comments,
followed tlsa's style guide.
Added some more error checking, too.
........
r4575 | adamblokus | 2008-07-10 18:48:26 +0200 (Thu, 10 Jul 2008) | 2 lines
Cleaned up the code.
........
r4687 | adamblokus | 2008-07-17 14:17:19 +0200 (Thu, 17 Jul 2008) | 2 lines
Changed everything according to jmb's review plus some minor bug fixes to gtk_print.
........
r4688 | adamblokus | 2008-07-17 17:16:34 +0200 (Thu, 17 Jul 2008) | 2 lines
Solved the netsurf.glade clash from r4421.
........
r4693 | adamblokus | 2008-07-18 18:11:51 +0200 (Fri, 18 Jul 2008) | 2 lines
Fixed bug with wrong number of pages in gtk printing.
........
r4695 | adamblokus | 2008-07-18 19:59:24 +0200 (Fri, 18 Jul 2008) | 3 lines
- fixed uncommented line from the previous commit
- fixed bug with scale bigger than 1.0 (incorretly clipped page)
........
r4696 | adamblokus | 2008-07-18 23:28:00 +0200 (Fri, 18 Jul 2008) | 2 lines
Fixed bug in gtk_print_font_paint (and nsfont_paint).
........
r4697 | adamblokus | 2008-07-18 23:35:38 +0200 (Fri, 18 Jul 2008) | 2 lines
Bug fix in nsfont_paint.
........
r4711 | adamblokus | 2008-07-19 22:44:15 +0200 (Sat, 19 Jul 2008) | 2 lines
Added gtk_selection files.
........
r4712 | adamblokus | 2008-07-20 11:15:06 +0200 (Sun, 20 Jul 2008) | 2 lines
Addam missing glade files.
........
r4713 | joty | 2008-07-20 17:13:10 +0200 (Sun, 20 Jul 2008) | 1 line
Follow change r4517 for RISC OS and BeOS platforms : Added pdf font handling and rendering functions with the use of Haru functions.
........
r4714 | joty | 2008-07-20 18:19:50 +0200 (Sun, 20 Jul 2008) | 1 line
Declare haru_nsfont iso define an instance for each C source including the font_haru.h header. This fixes breakage of PDF export on RISC OS.
........
r4724 | adamblokus | 2008-07-23 03:30:08 +0200 (Wed, 23 Jul 2008) | 6 lines
Applied changes according to joty's review.
Added checking the dimensions of a plotted image to pdf plotter.
Commented out jpg embedding (it seems to cause some problems
I'll bring it back when I figure out what's wrong) .
Added back some files removed by mistake.
........
svn path=/trunk/netsurf/; revision=4741
2008-07-26 20:01:59 +04:00
|
|
|
nsfont.font_width(&textplain_style, text, next_offset, &tx);
|
2006-03-26 08:48:45 +04:00
|
|
|
x += tx;
|
|
|
|
|
|
|
|
if (next_offset >= offset)
|
|
|
|
break;
|
|
|
|
|
|
|
|
/* align to next tab boundary */
|
|
|
|
next_offset++;
|
|
|
|
x = (1 + (x / textplain_tab_width)) * textplain_tab_width;
|
|
|
|
offset -= next_offset;
|
|
|
|
text += next_offset;
|
|
|
|
length -= next_offset;
|
|
|
|
}
|
|
|
|
|
|
|
|
return x;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2006-02-16 02:09:55 +03:00
|
|
|
/**
|
|
|
|
* Given a range of byte offsets within a UTF8 textplain content,
|
|
|
|
* return a box that fully encloses the text
|
|
|
|
*
|
2010-03-28 16:56:39 +04:00
|
|
|
* \param h content of type CONTENT_TEXTPLAIN
|
2006-02-16 02:09:55 +03:00
|
|
|
* \param start byte offset of start of text range
|
|
|
|
* \param end byte offset of end
|
|
|
|
* \param r rectangle to be completed
|
|
|
|
*/
|
|
|
|
|
2011-07-26 17:53:42 +04:00
|
|
|
void textplain_coords_from_range(struct content *c, unsigned start,
|
2010-03-28 16:56:39 +04:00
|
|
|
unsigned end, struct rect *r)
|
2006-02-16 02:09:55 +03:00
|
|
|
{
|
2011-07-26 17:53:42 +04:00
|
|
|
textplain_content *text = (textplain_content *) c;
|
2009-07-21 14:59:53 +04:00
|
|
|
float line_height = textplain_line_height();
|
2010-03-28 16:56:39 +04:00
|
|
|
char *utf8_data;
|
2006-02-16 02:09:55 +03:00
|
|
|
struct textplain_line *line;
|
|
|
|
unsigned lineno = 0;
|
|
|
|
unsigned nlines;
|
|
|
|
|
2010-03-28 16:56:39 +04:00
|
|
|
assert(c != NULL);
|
2006-02-16 02:09:55 +03:00
|
|
|
assert(start <= end);
|
2011-07-26 17:53:42 +04:00
|
|
|
assert(end <= text->utf8_data_size);
|
2006-02-16 02:09:55 +03:00
|
|
|
|
2011-07-26 17:53:42 +04:00
|
|
|
utf8_data = text->utf8_data;
|
|
|
|
nlines = text->physical_line_count;
|
|
|
|
line = text->physical_line;
|
2006-02-16 02:09:55 +03:00
|
|
|
|
|
|
|
/* find start */
|
2011-07-26 17:53:42 +04:00
|
|
|
lineno = textplain_find_line(c, start);
|
2006-02-16 02:09:55 +03:00
|
|
|
|
|
|
|
r->y0 = (int)(MARGIN + lineno * line_height);
|
|
|
|
|
|
|
|
if (lineno + 1 <= nlines || line[lineno + 1].start >= end) {
|
|
|
|
/* \todo - it may actually be more efficient just to run
|
|
|
|
forwards most of the time */
|
|
|
|
|
|
|
|
/* find end */
|
2011-07-26 17:53:42 +04:00
|
|
|
lineno = textplain_find_line(c, end);
|
2006-02-16 02:09:55 +03:00
|
|
|
|
|
|
|
r->x0 = 0;
|
2011-07-26 17:53:42 +04:00
|
|
|
r->x1 = text->formatted_width;
|
2006-02-16 02:09:55 +03:00
|
|
|
}
|
|
|
|
else {
|
|
|
|
/* single line */
|
2006-03-26 08:48:45 +04:00
|
|
|
const char *text = utf8_data + line[lineno].start;
|
|
|
|
|
|
|
|
r->x0 = textplain_coord_from_offset(text, start - line[lineno].start,
|
|
|
|
line[lineno].length);
|
|
|
|
|
|
|
|
r->x1 = textplain_coord_from_offset(text, end - line[lineno].start,
|
|
|
|
line[lineno].length);
|
2006-02-16 02:09:55 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
r->y1 = (int)(MARGIN + (lineno + 1) * line_height);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Return a pointer to the requested line of text.
|
|
|
|
*
|
2010-03-28 16:56:39 +04:00
|
|
|
* \param h content of type CONTENT_TEXTPLAIN
|
2006-02-16 02:09:55 +03:00
|
|
|
* \param lineno line number
|
|
|
|
* \param poffset receives byte offset of line start within text
|
|
|
|
* \param plen receives length of returned line
|
|
|
|
* \return pointer to text, or NULL if invalid line number
|
|
|
|
*/
|
|
|
|
|
2011-07-26 17:53:42 +04:00
|
|
|
char *textplain_get_line(struct content *c, unsigned lineno,
|
2006-02-16 02:09:55 +03:00
|
|
|
size_t *poffset, size_t *plen)
|
|
|
|
{
|
2011-07-26 17:53:42 +04:00
|
|
|
textplain_content *text = (textplain_content *) c;
|
2006-02-16 02:09:55 +03:00
|
|
|
struct textplain_line *line;
|
|
|
|
|
2010-03-28 16:56:39 +04:00
|
|
|
assert(c != NULL);
|
2006-02-16 02:09:55 +03:00
|
|
|
|
2011-07-26 17:53:42 +04:00
|
|
|
if (lineno >= text->physical_line_count)
|
2006-02-16 02:09:55 +03:00
|
|
|
return NULL;
|
2011-07-26 17:53:42 +04:00
|
|
|
line = &text->physical_line[lineno];
|
2006-02-16 02:09:55 +03:00
|
|
|
|
|
|
|
*poffset = line->start;
|
|
|
|
*plen = line->length;
|
2011-07-26 17:53:42 +04:00
|
|
|
return text->utf8_data + line->start;
|
2006-02-16 02:09:55 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Return a pointer to the raw UTF-8 data, as opposed to the reformatted
|
|
|
|
* text to fit the window width. Thus only hard newlines are preserved
|
|
|
|
* in the saved/copied text of a selection.
|
|
|
|
*
|
2010-03-28 16:56:39 +04:00
|
|
|
* \param h content of type CONTENT_TEXTPLAIN
|
2006-02-16 02:09:55 +03:00
|
|
|
* \param start starting byte offset within UTF-8 text
|
|
|
|
* \param end ending byte offset
|
|
|
|
* \param plen receives validated length
|
|
|
|
* \return pointer to text, or NULL if no text
|
|
|
|
*/
|
|
|
|
|
2011-07-26 17:53:42 +04:00
|
|
|
char *textplain_get_raw_data(struct content *c, unsigned start, unsigned end,
|
2006-02-16 02:09:55 +03:00
|
|
|
size_t *plen)
|
|
|
|
{
|
2011-07-26 17:53:42 +04:00
|
|
|
textplain_content *text = (textplain_content *) c;
|
2010-03-28 16:56:39 +04:00
|
|
|
size_t utf8_size;
|
2006-02-16 02:09:55 +03:00
|
|
|
|
2010-03-28 16:56:39 +04:00
|
|
|
assert(c != NULL);
|
2006-02-16 02:09:55 +03:00
|
|
|
|
2011-07-26 17:53:42 +04:00
|
|
|
utf8_size = text->utf8_data_size;
|
2010-03-28 16:56:39 +04:00
|
|
|
|
2006-02-16 02:09:55 +03:00
|
|
|
/* any text at all? */
|
|
|
|
if (!utf8_size) return NULL;
|
|
|
|
|
|
|
|
/* clamp to valid offset range */
|
|
|
|
if (start >= utf8_size) start = utf8_size;
|
|
|
|
if (end >= utf8_size) end = utf8_size;
|
|
|
|
|
|
|
|
*plen = end - start;
|
|
|
|
|
2011-07-26 17:53:42 +04:00
|
|
|
return text->utf8_data + start;
|
2006-02-16 02:09:55 +03:00
|
|
|
}
|
2009-07-21 14:59:53 +04:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Calculate the line height, in pixels
|
|
|
|
*
|
|
|
|
* \return Line height, in pixels
|
|
|
|
*/
|
|
|
|
float textplain_line_height(void)
|
|
|
|
{
|
|
|
|
/* Size is in points, so convert to pixels.
|
|
|
|
* Then use a constant line height of 1.2 x font size.
|
|
|
|
*/
|
2011-03-12 20:46:11 +03:00
|
|
|
return FIXTOFLT(FDIV((FMUL(FLTTOFIX(1.2), FMUL(nscss_screen_dpi,
|
|
|
|
INTTOFIX((textplain_style.size / FONT_SIZE_SCALE))))), F_72));
|
2009-07-21 14:59:53 +04:00
|
|
|
}
|
|
|
|
|
2011-07-26 17:53:42 +04:00
|
|
|
/**
|
|
|
|
* Get the browser window containing a textplain content
|
|
|
|
*
|
|
|
|
* \param c text/plain content
|
|
|
|
* \return the browser window
|
|
|
|
*/
|
|
|
|
struct browser_window *textplain_get_browser_window(struct content *c)
|
|
|
|
{
|
|
|
|
textplain_content *text = (textplain_content *) c;
|
|
|
|
|
|
|
|
assert(c != NULL);
|
|
|
|
assert(c->handler == &textplain_content_handler);
|
|
|
|
|
|
|
|
return text->bw;
|
|
|
|
}
|
|
|
|
|