NetSurf
plot.c
Go to the documentation of this file.
1/*
2 * Copyright 2011 Daniel Silverstone <dsilvers@digital-scurf.org>
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#include <stdio.h>
20
21#include "utils/utils.h"
22#include "utils/errors.h"
23#include "netsurf/plotters.h"
24
25#include "monkey/output.h"
26
27/**
28 * \brief Sets a clip rectangle for subsequent plot operations.
29 *
30 * \param ctx The current redraw context.
31 * \param clip The rectangle to limit all subsequent plot
32 * operations within.
33 * \return NSERROR_OK on success else error code.
34 */
35static nserror
36monkey_plot_clip(const struct redraw_context *ctx, const struct rect *clip)
37{
38 moutf(MOUT_PLOT, "CLIP X0 %d Y0 %d X1 %d Y1 %d",
39 clip->x0, clip->y0, clip->x1, clip->y1);
40 return NSERROR_OK;
41}
42
43
44/**
45 * Plots an arc
46 *
47 * plot an arc segment around (x,y), anticlockwise from angle1
48 * to angle2. Angles are measured anticlockwise from
49 * horizontal, in degrees.
50 *
51 * \param ctx The current redraw context.
52 * \param style Style controlling the arc plot.
53 * \param x The x coordinate of the arc.
54 * \param y The y coordinate of the arc.
55 * \param radius The radius of the arc.
56 * \param angle1 The start angle of the arc.
57 * \param angle2 The finish angle of the arc.
58 * \return NSERROR_OK on success else error code.
59 */
60static nserror
62 const plot_style_t *style,
63 int x, int y, int radius, int angle1, int angle2)
64{
65 moutf(MOUT_PLOT, "ARC X %d Y %d RADIUS %d ANGLE1 %d ANGLE2 %d",
66 x, y, radius, angle1, angle2);
67 return NSERROR_OK;
68}
69
70
71/**
72 * Plots a circle
73 *
74 * Plot a circle centered on (x,y), which is optionally filled.
75 *
76 * \param ctx The current redraw context.
77 * \param style Style controlling the circle plot.
78 * \param x x coordinate of circle centre.
79 * \param y y coordinate of circle centre.
80 * \param radius circle radius.
81 * \return NSERROR_OK on success else error code.
82 */
83static nserror
85 const plot_style_t *style,
86 int x, int y, int radius)
87{
88 moutf(MOUT_PLOT, "DISC X %d Y %d RADIUS %d", x, y, radius);
89 return NSERROR_OK;
90}
91
92
93/**
94 * Plots a line
95 *
96 * plot a line from (x0,y0) to (x1,y1). Coordinates are at
97 * centre of line width/thickness.
98 *
99 * \param ctx The current redraw context.
100 * \param style Style controlling the line plot.
101 * \param line A rectangle defining the line to be drawn
102 * \return NSERROR_OK on success else error code.
103 */
104static nserror
106 const plot_style_t *style,
107 const struct rect *line)
108{
109 moutf(MOUT_PLOT, "LINE X0 %d Y0 %d X1 %d Y1 %d",
110 line->x0, line->y0, line->x1, line->y1);
111 return NSERROR_OK;
112}
113
114
115/**
116 * Plots a rectangle.
117 *
118 * The rectangle can be filled an outline or both controlled
119 * by the plot style The line can be solid, dotted or
120 * dashed. Top left corner at (x0,y0) and rectangle has given
121 * width and height.
122 *
123 * \param ctx The current redraw context.
124 * \param style Style controlling the rectangle plot.
125 * \param rect A rectangle defining the line to be drawn
126 * \return NSERROR_OK on success else error code.
127 */
128static nserror
130 const plot_style_t *style,
131 const struct rect *rect)
132{
133 moutf(MOUT_PLOT, "RECT X0 %d Y0 %d X1 %d Y1 %d",
134 rect->x0, rect->y0, rect->x1, rect->y1);
135 return NSERROR_OK;
136}
137
138
139/**
140 * Plot a polygon
141 *
142 * Plots a filled polygon with straight lines between
143 * points. The lines around the edge of the ploygon are not
144 * plotted. The polygon is filled with the non-zero winding
145 * rule.
146 *
147 * \param ctx The current redraw context.
148 * \param style Style controlling the polygon plot.
149 * \param p verticies of polygon
150 * \param n number of verticies.
151 * \return NSERROR_OK on success else error code.
152 */
153static nserror
155 const plot_style_t *style,
156 const int *p,
157 unsigned int n)
158{
159 moutf(MOUT_PLOT, "POLYGON VERTICIES %d", n);
160 return NSERROR_OK;
161}
162
163
164/**
165 * Plots a path.
166 *
167 * Path plot consisting of cubic Bezier curves. Line and fill colour is
168 * controlled by the plot style.
169 *
170 * \param ctx The current redraw context.
171 * \param pstyle Style controlling the path plot.
172 * \param p elements of path
173 * \param n nunber of elements on path
174 * \param transform A transform to apply to the path.
175 * \return NSERROR_OK on success else error code.
176 */
177static nserror
179 const plot_style_t *pstyle,
180 const float *p,
181 unsigned int n,
182 const float transform[6])
183{
184 moutf(MOUT_PLOT, "PATH VERTICIES %d WIDTH %f",
186 return NSERROR_OK;
187}
188
189
190/**
191 * Plot a bitmap
192 *
193 * Tiled plot of a bitmap image. (x,y) gives the top left
194 * coordinate of an explicitly placed tile. From this tile the
195 * image can repeat in all four directions -- up, down, left
196 * and right -- to the extents given by the current clip
197 * rectangle.
198 *
199 * The bitmap_flags say whether to tile in the x and y
200 * directions. If not tiling in x or y directions, the single
201 * image is plotted. The width and height give the dimensions
202 * the image is to be scaled to.
203 *
204 * \param ctx The current redraw context.
205 * \param bitmap The bitmap to plot
206 * \param x The x coordinate to plot the bitmap
207 * \param y The y coordiante to plot the bitmap
208 * \param width The width of area to plot the bitmap into
209 * \param height The height of area to plot the bitmap into
210 * \param bg the background colour to alpha blend into
211 * \param flags the flags controlling the type of plot operation
212 * \return NSERROR_OK on success else error code.
213 */
214static nserror
216 struct bitmap *bitmap,
217 int x, int y,
218 int width,
219 int height,
220 colour bg,
221 bitmap_flags_t flags)
222{
223 moutf(MOUT_PLOT, "BITMAP X %d Y %d WIDTH %d HEIGHT %d",
224 x, y, width, height);
225 return NSERROR_OK;
226}
227
228
229/**
230 * Text plotting.
231 *
232 * \param ctx The current redraw context.
233 * \param fstyle plot style for this text
234 * \param x x coordinate
235 * \param y y coordinate
236 * \param text UTF-8 string to plot
237 * \param length length of string, in bytes
238 * \return NSERROR_OK on success else error code.
239 */
240static nserror
242 const struct plot_font_style *fstyle,
243 int x,
244 int y,
245 const char *text,
246 size_t length)
247{
248 moutf(MOUT_PLOT, "TEXT X %d Y %d STR %.*s", x, y, (int)length, text);
249 return NSERROR_OK;
250}
251
252
253/** monkey plotter operations table */
254static const struct plotter_table plotters = {
256 .arc = monkey_plot_arc,
257 .disc = monkey_plot_disc,
258 .line = monkey_plot_line,
259 .rectangle = monkey_plot_rectangle,
260 .polygon = monkey_plot_polygon,
261 .path = monkey_plot_path,
262 .bitmap = monkey_plot_bitmap,
263 .text = monkey_plot_text,
264 .option_knockout = true,
265};
266
Error codes.
nserror
Enumeration of error codes.
Definition: errors.h:29
@ NSERROR_OK
No error.
Definition: errors.h:30
Target independent plotting interface.
unsigned long bitmap_flags_t
Definition: plotters.h:36
static nserror monkey_plot_disc(const struct redraw_context *ctx, const plot_style_t *style, int x, int y, int radius)
Plots a circle.
Definition: plot.c:84
static nserror monkey_plot_polygon(const struct redraw_context *ctx, const plot_style_t *style, const int *p, unsigned int n)
Plot a polygon.
Definition: plot.c:154
static nserror monkey_plot_clip(const struct redraw_context *ctx, const struct rect *clip)
Sets a clip rectangle for subsequent plot operations.
Definition: plot.c:36
static nserror monkey_plot_line(const struct redraw_context *ctx, const plot_style_t *style, const struct rect *line)
Plots a line.
Definition: plot.c:105
const struct plotter_table * monkey_plotters
Definition: plot.c:267
static nserror monkey_plot_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: plot.c:215
static nserror monkey_plot_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: plot.c:178
static nserror monkey_plot_arc(const struct redraw_context *ctx, const plot_style_t *style, int x, int y, int radius, int angle1, int angle2)
Plots an arc.
Definition: plot.c:61
static nserror monkey_plot_text(const struct redraw_context *ctx, const struct plot_font_style *fstyle, int x, int y, const char *text, size_t length)
Text plotting.
Definition: plot.c:241
static const struct plotter_table plotters
monkey plotter operations table
Definition: plot.c:254
static nserror monkey_plot_rectangle(const struct redraw_context *ctx, const plot_style_t *style, const struct rect *rect)
Plots a rectangle.
Definition: plot.c:129
int moutf(enum monkey_output_type mout_type, const char *fmt,...)
Definition: output.c:39
@ MOUT_PLOT
Definition: output.h:30
#define plot_style_fixed_to_float(v)
Definition: plot_style.h:57
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
plot_style_fixed stroke_width
Width of stroke, in pixels.
Definition: plot_style.h:78
Plotter operations table.
Definition: plotters.h:102
nserror(* clip)(const struct redraw_context *ctx, const struct rect *clip)
Sets a clip rectangle for subsequent plot operations.
Definition: plotters.h:111
Rectangle coordinates.
Definition: types.h:40
int x0
Definition: types.h:41
int y0
Top left.
Definition: types.h:41
int x1
Definition: types.h:42
int y1
Bottom right.
Definition: types.h:42
Redraw context.
Definition: plotters.h:51
uint32_t colour
Colour type: XBGR.
Definition: types.h:35
Interface to a number of general purpose functionality.
static nserror line(const struct redraw_context *ctx, const plot_style_t *style, const struct rect *line)
Plots a line.
Definition: plot.c:579
static nserror text(const struct redraw_context *ctx, const struct plot_font_style *fstyle, int x, int y, const char *text, size_t length)
Text plotting.
Definition: plot.c:978
static nserror clip(const struct redraw_context *ctx, const struct rect *clip)
Sets a clip rectangle for subsequent plot operations.
Definition: plot.c:357