NetSurf
plotters.h
Go to the documentation of this file.
1/*
2 * Copyright 2004 James Bursa <bursa@users.sourceforge.net>
3 *
4 * This file is part of NetSurf, http://www.netsurf-browser.org/
5 *
6 * NetSurf is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; version 2 of the License.
9 *
10 * NetSurf is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License
16 * along with this program. If not, see <http://www.gnu.org/licenses/>.
17 */
18
19/**
20 * \file
21 * Target independent plotting interface.
22 */
23
24#ifndef _NETSURF_PLOTTERS_H_
25#define _NETSURF_PLOTTERS_H_
26
27#include <stdbool.h>
28#include <stdio.h>
29
30#include "netsurf/plot_style.h"
31
32struct bitmap;
33struct rect;
34struct plotter_table;
35
36typedef unsigned long bitmap_flags_t;
37#define BITMAPF_NONE 0
38#define BITMAPF_REPEAT_X 1
39#define BITMAPF_REPEAT_Y 2
40
46};
47
48/**
49 * Redraw context
50 */
52 /**
53 * Redraw to show interactive features.
54 *
55 * Active features include selections etc.
56 *
57 * \note Should be off for printing.
58 */
60
61 /**
62 * Render background images.
63 *
64 * \note May want it off for printing.
65 */
67
68 /**
69 * Current plot operation table
70 *
71 * \warning must be assigned before use.
72 */
73 const struct plotter_table *plot;
74
75 /**
76 * Private context.
77 *
78 * Private context allows callers to pass context through to
79 * plot operations without using a global.
80 */
81 void *priv;
82};
83
84
85/**
86 * Plotter operations table.
87 *
88 * Coordinates are from top left of canvas and (0,0) is the top left grid
89 * denomination. If a "fill" is drawn from (0,0) to (4,3), the result is:
90 *
91 * 0 1 2 3 4 5
92 * +-+-+-+-+-+-
93 * 0 |#|#|#|#| |
94 * +-+-+-+-+-+-
95 * 1 |#|#|#|#| |
96 * +-+-+-+-+-+-
97 * 2 |#|#|#|#| |
98 * +-+-+-+-+-+-
99 * 3 | | | | | |
100 *
101 */
103 /**
104 * \brief Sets a clip rectangle for subsequent plot operations.
105 *
106 * \param ctx The current redraw context.
107 * \param clip The rectangle to limit all subsequent plot
108 * operations within.
109 * \return NSERROR_OK on success else error code.
110 */
112 const struct redraw_context *ctx,
113 const struct rect *clip);
114
115 /**
116 * Plots an arc
117 *
118 * plot an arc segment around (x,y), anticlockwise from angle1
119 * to angle2. Angles are measured anticlockwise from
120 * horizontal, in degrees.
121 *
122 * \param ctx The current redraw context.
123 * \param pstyle Style controlling the arc plot.
124 * \param x The x coordinate of the arc.
125 * \param y The y coordinate of the arc.
126 * \param radius The radius of the arc.
127 * \param angle1 The start angle of the arc.
128 * \param angle2 The finish angle of the arc.
129 * \return NSERROR_OK on success else error code.
130 */
132 const struct redraw_context *ctx,
133 const plot_style_t *pstyle,
134 int x,
135 int y,
136 int radius,
137 int angle1,
138 int angle2);
139
140 /**
141 * Plots a circle
142 *
143 * Plot a circle centered on (x,y), which is optionally filled.
144 *
145 * \param ctx The current redraw context.
146 * \param pstyle Style controlling the circle plot.
147 * \param x The x coordinate of the circle.
148 * \param y The y coordinate of the circle.
149 * \param radius The radius of the circle.
150 * \return NSERROR_OK on success else error code.
151 */
153 const struct redraw_context *ctx,
154 const plot_style_t *pstyle,
155 int x,
156 int y,
157 int radius);
158
159 /**
160 * Plots a line
161 *
162 * plot a line from (x0,y0) to (x1,y1). Coordinates are at
163 * centre of line width/thickness.
164 *
165 * \param ctx The current redraw context.
166 * \param pstyle Style controlling the line plot.
167 * \param line A rectangle defining the line to be drawn
168 * \return NSERROR_OK on success else error code.
169 */
171 const struct redraw_context *ctx,
172 const plot_style_t *pstyle,
173 const struct rect *line);
174
175 /**
176 * Plots a rectangle.
177 *
178 * The rectangle can be filled an outline or both controlled
179 * by the plot style The line can be solid, dotted or
180 * dashed. Top left corner at (x0,y0) and rectangle has given
181 * width and height.
182 *
183 * \param ctx The current redraw context.
184 * \param pstyle Style controlling the rectangle plot.
185 * \param rect A rectangle defining the line to be drawn
186 * \return NSERROR_OK on success else error code.
187 */
189 const struct redraw_context *ctx,
190 const plot_style_t *pstyle,
191 const struct rect *rectangle);
192
193 /**
194 * Plot a polygon
195 *
196 * Plots a filled polygon with straight lines between
197 * points. The lines around the edge of the ploygon are not
198 * plotted. The polygon is filled with the non-zero winding
199 * rule.
200 *
201 * \param ctx The current redraw context.
202 * \param pstyle Style controlling the polygon plot.
203 * \param p verticies of polygon
204 * \param n number of verticies.
205 * \return NSERROR_OK on success else error code.
206 */
208 const struct redraw_context *ctx,
209 const plot_style_t *pstyle,
210 const int *p,
211 unsigned int n);
212
213 /**
214 * Plots a path.
215 *
216 * Path plot consisting of cubic Bezier curves. Line and fill colour is
217 * controlled by the plot style.
218 *
219 * \param ctx The current redraw context.
220 * \param pstyle Style controlling the path plot.
221 * \param p elements of path
222 * \param n nunber of elements on path
223 * \param transform A transform to apply to the path.
224 * \return NSERROR_OK on success else error code.
225 */
227 const struct redraw_context *ctx,
228 const plot_style_t *pstyle,
229 const float *p,
230 unsigned int n,
231 const float transform[6]);
232
233 /**
234 * Plot a bitmap
235 *
236 * Tiled plot of a bitmap image. (x,y) gives the top left
237 * coordinate of an explicitly placed tile. From this tile the
238 * image can repeat in all four directions -- up, down, left
239 * and right -- to the extents given by the current clip
240 * rectangle.
241 *
242 * The bitmap_flags say whether to tile in the x and y
243 * directions. If not tiling in x or y directions, the single
244 * image is plotted. The width and height give the dimensions
245 * the image is to be scaled to.
246 *
247 * \param ctx The current redraw context.
248 * \param bitmap The bitmap to plot
249 * \param x The x coordinate to plot the bitmap
250 * \param y The y coordiante to plot the bitmap
251 * \param width The width of area to plot the bitmap into
252 * \param height The height of area to plot the bitmap into
253 * \param bg the background colour to alpha blend into
254 * \param flags the flags controlling the type of plot operation
255 * \return NSERROR_OK on success else error code.
256 */
258 const struct redraw_context *ctx,
259 struct bitmap *bitmap,
260 int x,
261 int y,
262 int width,
263 int height,
264 colour bg,
265 bitmap_flags_t flags);
266
267 /**
268 * Text plotting.
269 *
270 * \param ctx The current redraw context.
271 * \param fstyle plot style for this text
272 * \param x x coordinate
273 * \param y y coordinate
274 * \param text UTF-8 string to plot
275 * \param length length of string, in bytes
276 * \return NSERROR_OK on success else error code.
277 */
279 const struct redraw_context *ctx,
280 const plot_font_style_t *fstyle,
281 int x,
282 int y,
283 const char *text,
284 size_t length);
285
286 /**
287 * Start of a group of objects.
288 *
289 * optional, may be NULL. Used when plotter implements export
290 * to a vector graphics file format.
291 *
292 * \param ctx The current redraw context.
293 * \return NSERROR_OK on success else error code.
294 */
296 const struct redraw_context *ctx,
297 const char *name);
298
299 /**
300 * End of the most recently started group.
301 *
302 * optional, may be NULL
303 *
304 * \param ctx The current redraw context.
305 * \return NSERROR_OK on success else error code.
306 */
308 const struct redraw_context *ctx);
309
310 /**
311 * Only used internally by the knockout code. Must be NULL in
312 * any front end display plotters or export plotters.
313 *
314 * \param ctx The current redraw context.
315 * \return NSERROR_OK on success else error code.
316 */
318 const struct redraw_context *ctx);
319
320 /* flags */
321 /**
322 * flag to enable knockout rendering.
323 *
324 * Optimisation particularly for unaccelerated screen
325 * redraw. It tries to avoid plotting to the same area more
326 * than once. See desktop/knockout.c
327 */
329};
330
331#endif
nserror
Enumeration of error codes.
Definition: errors.h:29
unsigned long bitmap_flags_t
Definition: plotters.h:36
path_command
Definition: plotters.h:41
@ PLOTTER_PATH_MOVE
Definition: plotters.h:42
@ PLOTTER_PATH_CLOSE
Definition: plotters.h:43
@ PLOTTER_PATH_LINE
Definition: plotters.h:44
@ PLOTTER_PATH_BEZIER
Definition: plotters.h:45
plotter style interfaces, generic styles and style colour helpers.
int width
Definition: gui.c:159
int height
Definition: gui.c:160
RISC OS wimp toolkit bitmap.
Definition: bitmap.c:68
Font style for plotting.
Definition: plot_style.h:111
Plot style for stroke/fill plotters.
Definition: plot_style.h:76
Plotter operations table.
Definition: plotters.h:102
nserror(* group_start)(const struct redraw_context *ctx, const char *name)
Start of a group of objects.
Definition: plotters.h:295
bool option_knockout
flag to enable knockout rendering.
Definition: plotters.h:328
nserror(* line)(const struct redraw_context *ctx, const plot_style_t *pstyle, const struct rect *line)
Plots a line.
Definition: plotters.h:170
nserror(* polygon)(const struct redraw_context *ctx, const plot_style_t *pstyle, const int *p, unsigned int n)
Plot a polygon.
Definition: plotters.h:207
nserror(* group_end)(const struct redraw_context *ctx)
End of the most recently started group.
Definition: plotters.h:307
nserror(* flush)(const struct redraw_context *ctx)
Only used internally by the knockout code.
Definition: plotters.h:317
nserror(* arc)(const struct redraw_context *ctx, const plot_style_t *pstyle, int x, int y, int radius, int angle1, int angle2)
Plots an arc.
Definition: plotters.h:131
nserror(* text)(const struct redraw_context *ctx, const plot_font_style_t *fstyle, int x, int y, const char *text, size_t length)
Text plotting.
Definition: plotters.h:278
nserror(* rectangle)(const struct redraw_context *ctx, const plot_style_t *pstyle, const struct rect *rectangle)
Plots a rectangle.
Definition: plotters.h:188
nserror(* clip)(const struct redraw_context *ctx, const struct rect *clip)
Sets a clip rectangle for subsequent plot operations.
Definition: plotters.h:111
nserror(* path)(const struct redraw_context *ctx, const plot_style_t *pstyle, const float *p, unsigned int n, const float transform[6])
Plots a path.
Definition: plotters.h:226
nserror(* bitmap)(const struct redraw_context *ctx, struct bitmap *bitmap, int x, int y, int width, int height, colour bg, bitmap_flags_t flags)
Plot a bitmap.
Definition: plotters.h:257
nserror(* disc)(const struct redraw_context *ctx, const plot_style_t *pstyle, int x, int y, int radius)
Plots a circle.
Definition: plotters.h:152
Rectangle coordinates.
Definition: types.h:40
Redraw context.
Definition: plotters.h:51
bool background_images
Render background images.
Definition: plotters.h:66
const struct plotter_table * plot
Current plot operation table.
Definition: plotters.h:73
bool interactive
Redraw to show interactive features.
Definition: plotters.h:59
void * priv
Private context.
Definition: plotters.h:81
uint32_t colour
Colour type: XBGR.
Definition: types.h:35