summaryrefslogtreecommitdiff
path: root/include/netsurf/plotters.h
blob: 2fd507aa5b1354626c9ebcf77a5d0bd77855d3b3 (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
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
/*
 * 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_PLOTTERS_H_
#define _NETSURF_PLOTTERS_H_

#include <stdbool.h>
#include <stdio.h>

#include "netsurf/plot_style.h"

struct bitmap;
struct rect;
struct plotter_table;

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

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

/**
 * Redraw context
 */
struct redraw_context {
	/**
	 * Redraw to show interactive features.
	 *
	 * Active features include selections etc.
	 *
	 * \note Should be off for printing.
	 */
	bool interactive;

	/**
	 * Render background images.
	 *
	 * \note May want it off for printing.
	 */
	bool background_images;

	/**
	 * Current plot operation table
	 *
	 * \warning must be assigned before use.
	 */
	const struct plotter_table *plot;

	/**
	 * Private context.
	 *
	 * Private context allows callers to pass context through to
	 *  plot operations without using a global.
	 */
	void *priv;
};


/**
 * Plotter operations table.
 *
 * 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 {
	/**
	 * \brief Sets a clip rectangle for subsequent plot operations.
	 *
	 * \param ctx The current redraw context.
	 * \param clip The rectangle to limit all subsequent plot
	 *              operations within.
	 * \return NSERROR_OK on success else error code.
	 */
	nserror (*clip)(
			const struct redraw_context *ctx,
			const struct rect *clip);

	/**
	 * Plots an arc
	 *
	 * plot an arc segment around (x,y), anticlockwise from angle1
	 *  to angle2. Angles are measured anticlockwise from
	 *  horizontal, in degrees.
	 *
	 * \param ctx The current redraw context.
	 * \param pstyle Style controlling the arc plot.
	 * \param x The x coordinate of the arc.
	 * \param y The y coordinate of the arc.
	 * \param radius The radius of the arc.
	 * \param angle1 The start angle of the arc.
	 * \param angle2 The finish angle of the arc.
	 * \return NSERROR_OK on success else error code.
	 */
	nserror (*arc)(
			const struct redraw_context *ctx,
			const plot_style_t *pstyle,
			int x,
			int y,
			int radius,
			int angle1,
			int angle2);

	/**
	 * Plots a circle
	 *
	 * Plot a circle centered on (x,y), which is optionally filled.
	 *
	 * \param ctx The current redraw context.
	 * \param pstyle Style controlling the circle plot.
	 * \param x The x coordinate of the circle.
	 * \param y The y coordinate of the circle.
	 * \param radius The radius of the circle.
	 * \return NSERROR_OK on success else error code.
	 */
	nserror (*disc)(
			const struct redraw_context *ctx,
			const plot_style_t *pstyle,
			int x,
			int y,
			int radius);

	/**
	 * Plots a line
	 *
	 * plot a line from (x0,y0) to (x1,y1). Coordinates are at
	 *  centre of line width/thickness.
	 *
	 * \param ctx The current redraw context.
	 * \param pstyle Style controlling the line plot.
	 * \param line A rectangle defining the line to be drawn
	 * \return NSERROR_OK on success else error code.
	 */
	nserror (*line)(
			const struct redraw_context *ctx,
			const plot_style_t *pstyle,
			const struct rect *line);

	/**
	 * Plots a rectangle.
	 *
	 * The rectangle can be filled an outline or both controlled
	 *  by the plot style The line can be solid, dotted or
	 *  dashed. Top left corner at (x0,y0) and rectangle has given
	 *  width and height.
	 *
	 * \param ctx The current redraw context.
	 * \param pstyle Style controlling the rectangle plot.
	 * \param rect A rectangle defining the line to be drawn
	 * \return NSERROR_OK on success else error code.
	 */
	nserror (*rectangle)(
			const struct redraw_context *ctx,
			const plot_style_t *pstyle,
			const struct rect *rectangle);

	/**
	 * Plot a 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.
	 *
	 * \param ctx The current redraw context.
	 * \param pstyle Style controlling the polygon plot.
	 * \param p verticies of polygon
	 * \param n number of verticies.
	 * \return NSERROR_OK on success else error code.
	 */
	nserror (*polygon)(
			const struct redraw_context *ctx,
			const plot_style_t *pstyle,
			const int *p,
			unsigned int n);

	/**
	 * Plots a path.
	 *
	 * Path plot consisting of cubic Bezier curves. Line and fill colour is
	 *  controlled by the plot style.
	 *
	 * \param ctx The current redraw context.
	 * \param pstyle Style controlling the path plot.
	 * \param p elements of path
	 * \param n nunber of elements on path
	 * \param transform A transform to apply to the path.
	 * \return NSERROR_OK on success else error code.
	 */
	nserror (*path)(
			const struct redraw_context *ctx,
			const plot_style_t *pstyle,
			const float *p,
			unsigned int n,
			const float transform[6]);

	/**
	 * Plot a 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.
	 *
	 * \param ctx The current redraw context.
	 * \param bitmap The bitmap to plot
	 * \param x The x coordinate to plot the bitmap
	 * \param y The y coordiante to plot the bitmap
	 * \param width The width of area to plot the bitmap into
	 * \param height The height of area to plot the bitmap into
	 * \param bg the background colour to alpha blend into
	 * \param flags the flags controlling the type of plot operation
	 * \return NSERROR_OK on success else error code.
	 */
	nserror (*bitmap)(
			const struct redraw_context *ctx,
			struct bitmap *bitmap,
			int x,
			int y,
			int width,
			int height,
			colour bg,
			bitmap_flags_t flags);

	/**
	 * Text plotting.
	 *
	 * \param ctx The current redraw context.
	 * \param fstyle plot style for this text
	 * \param x x coordinate
	 * \param y y coordinate
	 * \param text UTF-8 string to plot
	 * \param length length of string, in bytes
	 * \return NSERROR_OK on success else error code.
	 */
	nserror (*text)(
			const struct redraw_context *ctx,
			const plot_font_style_t *fstyle,
			int x,
			int y,
			const char *text,
			size_t length);

	/**
	 * Start of a group of objects.
	 *
	 * optional, may be NULL. Used when plotter implements export
	 *  to a vector graphics file format.
	 *
	 * \param ctx The current redraw context.
	 * \return NSERROR_OK on success else error code.
	 */
	nserror (*group_start)(
			const struct redraw_context *ctx,
			const char *name);

	/**
	 * End of the most recently started group.
	 *
	 * optional, may be NULL
	 *
	 * \param ctx The current redraw context.
	 * \return NSERROR_OK on success else error code.
	 */
	nserror (*group_end)(
			const struct redraw_context *ctx);

	/**
	 * Only used internally by the knockout code. Must be NULL in
	 * any front end display plotters or export plotters.
	 *
	 * \param ctx The current redraw context.
	 * \return NSERROR_OK on success else error code.
	 */
	nserror (*flush)(
			const struct redraw_context *ctx);

	/* flags */
	/**
	 * flag to enable knockout rendering.
	 *
	 * Optimisation particularly for unaccelerated screen
	 *  redraw. It tries to avoid plotting to the same area more
	 *  than once. See desktop/knockout.c
	 */
	bool option_knockout;
};

#endif