summaryrefslogtreecommitdiff
path: root/desktop/plotters.h
blob: 4a626151668c038b6a35a1ccc2b8590072793ccf (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
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
/*
 * Copyright 2004 James Bursa <bursa@users.sourceforge.net>
 *
 * 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/>.
 */

/** \file
 * Target independent plotting (interface).
 */

#ifndef _NETSURF_DESKTOP_PLOTTERS_H_
#define _NETSURF_DESKTOP_PLOTTERS_H_

#include <stdbool.h>
#include "css/css.h"
#include "content/content.h"
#include "desktop/plot_style.h"

struct bitmap;

typedef unsigned long bitmap_flags_t;
#define BITMAPF_NONE 0
#define BITMAPF_REPEAT_X 1
#define BITMAPF_REPEAT_Y 2


/** Set of target specific plotting functions.
 *
 * The functions are:
 *  arc		- Plots an arc, around (x,y), from anticlockwise from angle1 to
 *		  angle2. Angles are measured anticlockwise from horizontal, in
 *		  degrees.
 *  disc	- Plots a circle, centered on (x,y), which is optionally filled.
 *  line	- Plots a line from (x0,y0) to (x1,y1). Coordinates are at
 *		  centre of line width/thickness.
 *  path	- Plots a path consisting of cubic Bezier curves. Line colour is
 *		  given by c and fill colour is given by fill.
 *  polygon	- Plots a filled polygon with straight lines between points.
 *		  The lines around the edge of the ploygon are not plotted. The
 *		  polygon is filled with the non-zero winding rule.
 *  rectangle	- Plots a rectangle outline. The line can be solid, dotted or
 *		  dashed. Top left corner at (x0,y0) and rectangle has given
 *		  width and height.
 *  fill	- Plots a filled rectangle. Top left corner at (x0,y0), bottom
 *		  right corner at (x1,y1). Note: (x0,y0) is inside filled area,
 *		  but (x1,y1) is below and to the right. See diagram below.
 *  clip	- Sets a clip rectangle for subsequent plots.
 *  text	- Plots text. (x,y) is the coordinate of the left hand side of
 *		  the text's baseline. The text is UTF-8 encoded. The colour, c,
 *		  is the colour of the text. Background colour, bg, may be used
 *		  optionally to attempt to provide anti-aliased text without
 *		  screen reads. Font information is provided in the style.
 *  bitmap     	- Tiled plot of a bitmap image. (x,y) gives the top left
 *		  coordinate of an explicitly placed tile. From this tile the
 *		  image can repeat in all four directions -- up, down, left and
 *		  right -- to the extents given by the current clip rectangle.
 *		  The bitmap_flags say whether to tile in the x and y
 *		  directions. If not tiling in x or y directions, the single
 *		  image is plotted. The width and height give the dimensions
 *		  the image is to be scaled to.
 *  group_start	- Start of a group of objects. Used when plotter implements
 *		  export to a vector graphics file format. (Optional.)
 *  group_end	- End of the most recently started group. (Optional.)
 *  flush	- Only used internally by the knockout code. Should be NULL in
 *		  any front end display plotters or export plotters.
 *
 * Plotter options:
 *  option_knockout	- Optimisation particularly for unaccelerated screen
 *			  redraw. It tries to avoid plotting to the same area
 *			  more than once. See desktop/knockout.c
 *
 * Coordinates are from top left of canvas and (0,0) is the top left grid
 * denomination. If a "fill" is drawn from (0,0) to (4,3), the result is:
 *
 *     0 1 2 3 4 5
 *    +-+-+-+-+-+-
 *  0 |#|#|#|#| |
 *    +-+-+-+-+-+-
 *  1 |#|#|#|#| |
 *    +-+-+-+-+-+-
 *  2 |#|#|#|#| |
 *    +-+-+-+-+-+-
 *  3 | | | | | |
 */
struct plotter_table {
	bool (*rectangle)(int x0, int y0, int x1, int y1, const plot_style_t *pstyle);
	bool (*line)(int x0, int y0, int x1, int y1, const plot_style_t *pstyle);
	bool (*polygon)(const int *p, unsigned int n, colour fill);
	bool (*clip)(int x0, int y0, int x1, int y1);
	bool (*text)(int x, int y, const struct css_style *style,
			const char *text, size_t length, colour bg, colour c);
	bool (*disc)(int x, int y, int radius, colour c, bool filled);
	bool (*arc)(int x, int y, int radius, int angle1, int angle2, colour c);
	bool (*bitmap)(int x, int y, int width, int height,
			struct bitmap *bitmap, colour bg,
			bitmap_flags_t flags);
	bool (*group_start)(const char *name);  /**< optional, may be NULL */
	bool (*group_end)(void);		/**< optional, may be NULL */
	bool (*flush)(void);			/**< optional, may be NULL */
	bool (*path)(const float *p, unsigned int n, colour fill, float width,
			colour c, const float transform[6]);
	bool option_knockout;	/**< set if knockout rendering is required */
};

/** Current plotters, must be assigned before use. */
extern struct plotter_table plot;

enum path_command {
	PLOTTER_PATH_MOVE,
	PLOTTER_PATH_CLOSE,
	PLOTTER_PATH_LINE,
	PLOTTER_PATH_BEZIER,
};


#endif