2003-09-11 02:46:56 +04:00
|
|
|
/*
|
|
|
|
* Copyright 2003 John M Bell <jmb202@ecs.soton.ac.uk>
|
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-09-11 02:46:56 +04:00
|
|
|
*/
|
|
|
|
|
2004-11-07 00:03:55 +03:00
|
|
|
/** \file
|
|
|
|
* Content for image/x-drawfile (RISC OS implementation).
|
|
|
|
*
|
|
|
|
* The DrawFile module is used to plot the DrawFile.
|
|
|
|
*/
|
|
|
|
|
2008-07-27 03:42:24 +04:00
|
|
|
#include "utils/config.h"
|
|
|
|
#ifdef WITH_DRAW
|
|
|
|
|
2003-09-11 02:46:56 +04:00
|
|
|
#include <string.h>
|
|
|
|
#include <stdlib.h>
|
2004-11-07 00:03:55 +03:00
|
|
|
#include "oslib/drawfile.h"
|
2007-05-31 02:39:54 +04:00
|
|
|
#include "utils/config.h"
|
2010-04-06 02:03:44 +04:00
|
|
|
#include "content/content_protected.h"
|
2011-05-07 00:40:09 +04:00
|
|
|
#include "desktop/plotters.h"
|
2011-05-09 13:57:40 +04:00
|
|
|
#include "riscos/content-handlers/draw.h"
|
2007-05-31 02:39:54 +04:00
|
|
|
#include "riscos/gui.h"
|
|
|
|
#include "utils/log.h"
|
2011-05-07 00:40:09 +04:00
|
|
|
#include "utils/messages.h"
|
|
|
|
#include "utils/utils.h"
|
|
|
|
|
|
|
|
typedef struct draw_content {
|
|
|
|
struct content base;
|
|
|
|
|
|
|
|
int x0, y0;
|
|
|
|
} draw_content;
|
|
|
|
|
|
|
|
static nserror draw_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 bool draw_convert(struct content *c);
|
|
|
|
static void draw_destroy(struct content *c);
|
2011-06-29 00:17:39 +04:00
|
|
|
static bool draw_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-05-07 00:40:09 +04:00
|
|
|
static nserror draw_clone(const struct content *old, struct content **newc);
|
2011-09-03 13:27:42 +04:00
|
|
|
static content_type draw_content_type(void);
|
2011-05-07 00:40:09 +04:00
|
|
|
|
|
|
|
static const content_handler draw_content_handler = {
|
2011-05-09 19:32:34 +04:00
|
|
|
.create = draw_create,
|
|
|
|
.data_complete = draw_convert,
|
|
|
|
.destroy = draw_destroy,
|
|
|
|
.redraw = draw_redraw,
|
|
|
|
.clone = draw_clone,
|
|
|
|
.type = draw_content_type,
|
|
|
|
.no_share = false,
|
2011-05-07 00:40:09 +04:00
|
|
|
};
|
|
|
|
|
|
|
|
static const char *draw_types[] = {
|
|
|
|
"application/drawfile",
|
|
|
|
"application/x-drawfile",
|
|
|
|
"image/drawfile",
|
|
|
|
"image/x-drawfile"
|
|
|
|
};
|
|
|
|
|
2011-09-16 02:31:16 +04:00
|
|
|
CONTENT_FACTORY_REGISTER_TYPES(draw, draw_types, draw_content_handler)
|
2011-05-07 00:40:09 +04:00
|
|
|
|
|
|
|
nserror draw_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)
|
|
|
|
{
|
|
|
|
draw_content *draw;
|
|
|
|
nserror error;
|
|
|
|
|
2012-10-03 22:24:58 +04:00
|
|
|
draw = calloc(1, sizeof(draw_content));
|
2011-05-07 00:40:09 +04:00
|
|
|
if (draw == NULL)
|
|
|
|
return NSERROR_NOMEM;
|
|
|
|
|
|
|
|
error = content__init(&draw->base, handler, imime_type, params,
|
|
|
|
llcache, fallback_charset, quirks);
|
|
|
|
if (error != NSERROR_OK) {
|
2012-10-03 22:24:58 +04:00
|
|
|
free(draw);
|
2011-05-07 00:40:09 +04:00
|
|
|
return error;
|
|
|
|
}
|
|
|
|
|
|
|
|
*c = (struct content *) draw;
|
|
|
|
|
|
|
|
return NSERROR_OK;
|
|
|
|
}
|
2003-09-11 02:46:56 +04:00
|
|
|
|
2004-11-07 00:03:55 +03:00
|
|
|
/**
|
|
|
|
* Convert a CONTENT_DRAW for display.
|
|
|
|
*
|
|
|
|
* No conversion is necessary. We merely read the DrawFile dimensions and
|
|
|
|
* bounding box bottom-left.
|
|
|
|
*/
|
|
|
|
|
2010-04-06 02:03:44 +04:00
|
|
|
bool draw_convert(struct content *c)
|
2003-09-11 02:46:56 +04:00
|
|
|
{
|
2011-05-07 00:40:09 +04:00
|
|
|
draw_content *draw = (draw_content *) c;
|
2004-06-11 00:41:26 +04:00
|
|
|
union content_msg_data msg_data;
|
2010-04-06 02:03:44 +04:00
|
|
|
const char *source_data;
|
|
|
|
unsigned long source_size;
|
|
|
|
const void *data;
|
2004-06-11 00:41:26 +04:00
|
|
|
os_box bbox;
|
2003-09-11 02:46:56 +04:00
|
|
|
os_error *error;
|
2012-10-25 15:05:12 +04:00
|
|
|
char *title;
|
2010-04-06 02:03:44 +04:00
|
|
|
|
|
|
|
source_data = content__get_source_data(c, &source_size);
|
|
|
|
data = source_data;
|
2003-09-11 02:46:56 +04:00
|
|
|
|
2004-11-07 00:03:55 +03:00
|
|
|
/* BBox contents in Draw units (256*OS unit) */
|
2009-03-27 05:25:57 +03:00
|
|
|
error = xdrawfile_bbox(0, (drawfile_diagram *) data,
|
2010-04-06 02:03:44 +04:00
|
|
|
(int) source_size, 0, &bbox);
|
2004-11-07 00:03:55 +03:00
|
|
|
if (error) {
|
2015-05-28 18:08:46 +03:00
|
|
|
LOG("xdrawfile_bbox: 0x%x: %s", error->errnum, error->errmess);
|
2004-06-11 00:41:26 +04:00
|
|
|
msg_data.error = error->errmess;
|
|
|
|
content_broadcast(c, CONTENT_MSG_ERROR, msg_data);
|
2004-11-07 00:03:55 +03:00
|
|
|
return false;
|
|
|
|
}
|
2003-09-11 02:46:56 +04:00
|
|
|
|
2009-02-03 02:17:41 +03:00
|
|
|
if (bbox.x1 > bbox.x0 && bbox.y1 > bbox.y0) {
|
|
|
|
/* c->width & c->height stored as (OS units/2)
|
|
|
|
=> divide by 512 to convert from draw units */
|
|
|
|
c->width = ((bbox.x1 - bbox.x0) / 512);
|
|
|
|
c->height = ((bbox.y1 - bbox.y0) / 512);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
/* invalid/undefined bounding box */
|
|
|
|
c->height = c->width = 0;
|
|
|
|
|
2011-05-07 00:40:09 +04:00
|
|
|
draw->x0 = bbox.x0;
|
|
|
|
draw->y0 = bbox.y0;
|
2012-10-25 15:05:12 +04:00
|
|
|
|
|
|
|
title = messages_get_buff("DrawTitle",
|
2012-10-24 21:22:45 +04:00
|
|
|
nsurl_access_leaf(llcache_handle_get_url(c->llcache)),
|
|
|
|
c->width, c->height);
|
2012-10-25 15:05:12 +04:00
|
|
|
if (title != NULL) {
|
|
|
|
content__set_title(c, title);
|
|
|
|
free(title);
|
|
|
|
}
|
2010-04-06 02:03:44 +04:00
|
|
|
|
2011-02-27 23:11:39 +03:00
|
|
|
content_set_ready(c);
|
|
|
|
content_set_done(c);
|
2008-03-10 15:41:41 +03:00
|
|
|
/* Done: update status bar */
|
|
|
|
content_set_status(c, "");
|
2004-06-11 00:41:26 +04:00
|
|
|
return true;
|
2003-09-11 02:46:56 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2004-11-07 00:03:55 +03:00
|
|
|
/**
|
|
|
|
* Destroy a CONTENT_DRAW and free all resources it owns.
|
|
|
|
*/
|
|
|
|
|
2003-09-11 02:46:56 +04:00
|
|
|
void draw_destroy(struct content *c)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2004-11-07 00:03:55 +03:00
|
|
|
/**
|
|
|
|
* Redraw a CONTENT_DRAW.
|
|
|
|
*/
|
|
|
|
|
2011-06-29 00:17:39 +04:00
|
|
|
bool draw_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-09-11 02:46:56 +04:00
|
|
|
{
|
2011-05-07 00:40:09 +04:00
|
|
|
draw_content *draw = (draw_content *) c;
|
2004-08-11 20:26:13 +04:00
|
|
|
os_trfm matrix;
|
2010-04-06 02:03:44 +04:00
|
|
|
const char *source_data;
|
|
|
|
unsigned long source_size;
|
2011-06-29 00:17:39 +04:00
|
|
|
const void *src_data;
|
2009-03-27 05:25:57 +03:00
|
|
|
os_error *error;
|
2003-09-11 02:46:56 +04:00
|
|
|
|
2011-06-30 19:48:07 +04:00
|
|
|
if (ctx->plot->flush && !ctx->plot->flush())
|
2006-08-19 23:31:07 +04:00
|
|
|
return false;
|
|
|
|
|
2009-02-03 02:17:41 +03:00
|
|
|
if (!c->width || !c->height)
|
|
|
|
return false;
|
|
|
|
|
2010-04-06 02:03:44 +04:00
|
|
|
source_data = content__get_source_data(c, &source_size);
|
2011-06-29 00:17:39 +04:00
|
|
|
src_data = source_data;
|
2010-04-06 02:03:44 +04:00
|
|
|
|
2004-08-11 20:26:13 +04:00
|
|
|
/* Scaled image. Transform units (65536*OS units) */
|
2011-06-29 00:17:39 +04:00
|
|
|
matrix.entries[0][0] = data->width * 65536 / c->width;
|
2004-08-11 20:26:13 +04:00
|
|
|
matrix.entries[0][1] = 0;
|
|
|
|
matrix.entries[1][0] = 0;
|
2011-06-29 00:17:39 +04:00
|
|
|
matrix.entries[1][1] = data->height * 65536 / c->height;
|
2004-08-11 20:26:13 +04:00
|
|
|
/* Draw units. (x,y) = bottom left */
|
2011-06-29 00:17:39 +04:00
|
|
|
matrix.entries[2][0] = ro_plot_origin_x * 256 + data->x * 512 -
|
|
|
|
draw->x0 * data->width / c->width;
|
|
|
|
matrix.entries[2][1] = ro_plot_origin_y * 256 -
|
|
|
|
(data->y + data->height) * 512 -
|
|
|
|
draw->y0 * data->height / c->height;
|
2003-09-11 02:46:56 +04:00
|
|
|
|
2011-06-29 00:17:39 +04:00
|
|
|
error = xdrawfile_render(0, (drawfile_diagram *) src_data,
|
2010-04-06 02:03:44 +04:00
|
|
|
(int) source_size, &matrix, 0, 0);
|
2004-08-11 20:26:13 +04:00
|
|
|
if (error) {
|
2015-05-28 18:08:46 +03:00
|
|
|
LOG("xdrawfile_render: 0x%x: %s", error->errnum, error->errmess);
|
2004-08-11 20:26:13 +04:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
2003-09-11 02:46:56 +04:00
|
|
|
}
|
2004-11-07 00:03:55 +03:00
|
|
|
|
2010-04-12 03:11:40 +04:00
|
|
|
/**
|
|
|
|
* Clone a CONTENT_DRAW
|
|
|
|
*/
|
|
|
|
|
2011-05-07 00:40:09 +04:00
|
|
|
nserror draw_clone(const struct content *old, struct content **newc)
|
2010-04-12 03:11:40 +04:00
|
|
|
{
|
2011-05-07 00:40:09 +04:00
|
|
|
draw_content *draw;
|
|
|
|
nserror error;
|
|
|
|
|
2012-10-03 22:24:58 +04:00
|
|
|
draw = calloc(1, sizeof(draw_content));
|
2011-05-07 00:40:09 +04:00
|
|
|
if (draw == NULL)
|
|
|
|
return NSERROR_NOMEM;
|
|
|
|
|
|
|
|
error = content__clone(old, &draw->base);
|
|
|
|
if (error != NSERROR_OK) {
|
|
|
|
content_destroy(&draw->base);
|
|
|
|
return error;
|
|
|
|
}
|
|
|
|
|
2010-04-12 03:11:40 +04:00
|
|
|
/* Simply rerun convert */
|
|
|
|
if (old->status == CONTENT_STATUS_READY ||
|
|
|
|
old->status == CONTENT_STATUS_DONE) {
|
2011-05-07 00:40:09 +04:00
|
|
|
if (draw_convert(&draw->base) == false) {
|
|
|
|
content_destroy(&draw->base);
|
|
|
|
return NSERROR_CLONE_FAILED;
|
|
|
|
}
|
2010-04-12 03:11:40 +04:00
|
|
|
}
|
|
|
|
|
2011-05-07 00:40:09 +04:00
|
|
|
*newc = (struct content *) draw;
|
|
|
|
|
|
|
|
return NSERROR_OK;
|
|
|
|
}
|
|
|
|
|
2011-09-03 13:27:42 +04:00
|
|
|
content_type draw_content_type(void)
|
2011-05-07 00:40:09 +04:00
|
|
|
{
|
|
|
|
return CONTENT_IMAGE;
|
2010-04-12 03:11:40 +04:00
|
|
|
}
|
|
|
|
|
2004-01-05 05:10:59 +03:00
|
|
|
#endif
|