summaryrefslogtreecommitdiff
path: root/riscos/draw.c
blob: b59a962612282c0263b008dd8e76550c84f9af32 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
/*
 * This file is part of NetSurf, http://netsurf.sourceforge.net/
 * Licensed under the GNU General Public License,
 *                http://www.opensource.org/licenses/gpl-license
 * Copyright 2003 John M Bell <jmb202@ecs.soton.ac.uk>
 */

#include <assert.h>
#include <string.h>
#include <stdlib.h>
#include "netsurf/utils/config.h"
#include "netsurf/content/content.h"
#include "netsurf/riscos/draw.h"
#include "netsurf/utils/utils.h"
#include "netsurf/utils/messages.h"
#include "netsurf/utils/log.h"
#include "oslib/drawfile.h"

#ifdef WITH_DRAW

int draw_convert(struct content *c, unsigned int width, unsigned int height)
{
	os_error *error;
	os_trfm *matrix = xcalloc(1, sizeof(os_trfm));
	os_box *bbox = xcalloc(1, sizeof(os_box));

        /* Full size image (1:1) */
        matrix->entries[0][0] = 1 << 16;
        matrix->entries[0][1] = 0;
        matrix->entries[1][0] = 0;
        matrix->entries[1][1] = 1 << 16;
        matrix->entries[2][0] = 0;
        matrix->entries[2][1] = 0;

        /* BBox contents in Draw units (256*OS unit) */
	error = xdrawfile_bbox(0, (drawfile_diagram*)(c->source_data),
	                       (int)c->source_size, matrix, bbox);

        if (error) {
                LOG(("error: %s", error->errmess));
                xfree(matrix);
                xfree(bbox);
                return 1;
        }

        /* 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);
	c->data.draw.x0 = bbox->x0 / 2;
	c->data.draw.y0 = bbox->y0 / 2;
	c->title = xcalloc(100, 1);
	sprintf(c->title, messages_get("DrawTitle"), c->width,
	                                c->height, c->source_size);
	c->status = CONTENT_STATUS_DONE;
	xfree(matrix);
	xfree(bbox);
	return 0;
}


void draw_destroy(struct content *c)
{
	xfree(c->title);
}


void draw_redraw(struct content *c, long x, long y,
		unsigned long width, unsigned long height,
		long clip_x0, long clip_y0, long clip_x1, long clip_y1,
		float scale)
{
        os_trfm matrix;

        /* Scaled image. Transform units (65536*OS units) */
        matrix.entries[0][0] = ((width*65536) / (c->width*2));
        matrix.entries[0][1] = 0;
        matrix.entries[1][0] = 0;
        matrix.entries[1][1] = ((height*65536) / (c->height*2));
        /* Draw units. (x,y) = bottom left */
        matrix.entries[2][0] = x * 256 - c->data.draw.x0 * width / c->width;
        matrix.entries[2][1] = (y - height) * 256 -
        		c->data.draw.y0 * height / c->height;

	xdrawfile_render(0, (drawfile_diagram*)(c->source_data),
			(int)c->source_size, &matrix, 0, 0);
}
#endif