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"
|
|
|
|
#include "desktop/plotters.h"
|
2010-04-06 02:03:44 +04:00
|
|
|
#include "content/content_protected.h"
|
2007-05-31 02:39:54 +04:00
|
|
|
#include "riscos/draw.h"
|
|
|
|
#include "riscos/gui.h"
|
|
|
|
#include "utils/utils.h"
|
|
|
|
#include "utils/messages.h"
|
|
|
|
#include "utils/log.h"
|
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
|
|
|
{
|
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;
|
2010-04-06 02:03:44 +04:00
|
|
|
char title[100];
|
|
|
|
|
|
|
|
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) {
|
|
|
|
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;
|
|
|
|
|
2004-11-07 00:03:55 +03:00
|
|
|
c->data.draw.x0 = bbox.x0;
|
|
|
|
c->data.draw.y0 = bbox.y0;
|
2010-04-06 02:03:44 +04:00
|
|
|
snprintf(title, sizeof(title), messages_get("DrawTitle"), c->width,
|
|
|
|
c->height, source_size);
|
|
|
|
content__set_title(c, title);
|
|
|
|
|
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.
|
|
|
|
*/
|
|
|
|
|
2004-08-11 20:26:13 +04:00
|
|
|
bool draw_redraw(struct content *c, int x, int y,
|
2011-02-14 22:17:08 +03:00
|
|
|
int width, int height, const struct rect *clip,
|
2004-11-07 00:03:55 +03:00
|
|
|
float scale, colour background_colour)
|
2003-09-11 02:46:56 +04:00
|
|
|
{
|
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;
|
|
|
|
const void *data;
|
2009-03-27 05:25:57 +03:00
|
|
|
os_error *error;
|
2003-09-11 02:46:56 +04:00
|
|
|
|
2006-08-19 23:31:07 +04:00
|
|
|
if (plot.flush && !plot.flush())
|
|
|
|
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);
|
|
|
|
data = source_data;
|
|
|
|
|
2004-08-11 20:26:13 +04:00
|
|
|
/* Scaled image. Transform units (65536*OS units) */
|
2004-11-07 00:03:55 +03:00
|
|
|
matrix.entries[0][0] = width * 65536 / c->width;
|
2004-08-11 20:26:13 +04:00
|
|
|
matrix.entries[0][1] = 0;
|
|
|
|
matrix.entries[1][0] = 0;
|
2004-11-07 00:03:55 +03:00
|
|
|
matrix.entries[1][1] = height * 65536 / c->height;
|
2004-08-11 20:26:13 +04:00
|
|
|
/* Draw units. (x,y) = bottom left */
|
2004-11-07 00:03:55 +03:00
|
|
|
matrix.entries[2][0] = ro_plot_origin_x * 256 + x * 512 -
|
|
|
|
c->data.draw.x0 * width / c->width;
|
|
|
|
matrix.entries[2][1] = ro_plot_origin_y * 256 - (y + height) * 512 -
|
2004-08-11 20:26:13 +04:00
|
|
|
c->data.draw.y0 * height / c->height;
|
2003-09-11 02:46:56 +04:00
|
|
|
|
2009-03-27 05:25:57 +03:00
|
|
|
error = xdrawfile_render(0, (drawfile_diagram *) 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) {
|
|
|
|
LOG(("xdrawfile_render: 0x%x: %s",
|
|
|
|
error->errnum, error->errmess));
|
|
|
|
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
|
|
|
|
*/
|
|
|
|
|
|
|
|
bool draw_clone(const struct content *old, struct content *new_content)
|
|
|
|
{
|
|
|
|
/* Simply rerun convert */
|
|
|
|
if (old->status == CONTENT_STATUS_READY ||
|
|
|
|
old->status == CONTENT_STATUS_DONE) {
|
|
|
|
if (draw_convert(new_content) == false)
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2004-01-05 05:10:59 +03:00
|
|
|
#endif
|