2011-03-12 18:08:07 +03:00
|
|
|
/*
|
|
|
|
* Copyright 2011 Daniel Silverstone <dsilvers@digital-scurf.org>
|
|
|
|
*
|
|
|
|
* 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/>.
|
|
|
|
*/
|
|
|
|
|
2011-11-25 22:08:30 +04:00
|
|
|
#include <stdio.h>
|
|
|
|
|
2014-11-02 23:10:32 +03:00
|
|
|
#include "utils/utils.h"
|
2017-02-09 12:56:37 +03:00
|
|
|
#include "utils/errors.h"
|
2016-05-30 23:05:57 +03:00
|
|
|
#include "netsurf/plotters.h"
|
2014-05-19 02:16:46 +04:00
|
|
|
|
2017-02-09 12:56:37 +03:00
|
|
|
/**
|
|
|
|
* \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.
|
|
|
|
*/
|
|
|
|
static nserror
|
|
|
|
monkey_plot_clip(const struct redraw_context *ctx, const struct rect *clip)
|
2011-03-12 18:08:07 +03:00
|
|
|
{
|
2017-02-09 12:56:37 +03:00
|
|
|
fprintf(stdout,
|
|
|
|
"PLOT CLIP X0 %d Y0 %d X1 %d Y1 %d\n",
|
|
|
|
clip->x0, clip->y0, clip->x1, clip->y1);
|
|
|
|
return NSERROR_OK;
|
2011-03-12 18:08:07 +03:00
|
|
|
}
|
|
|
|
|
2017-02-09 12:56:37 +03:00
|
|
|
|
|
|
|
/**
|
|
|
|
* 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.
|
2017-02-15 02:05:30 +03:00
|
|
|
* \param style Style controlling the arc plot.
|
2017-02-09 12:56:37 +03:00
|
|
|
* \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.
|
|
|
|
*/
|
|
|
|
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)
|
2011-03-12 18:08:07 +03:00
|
|
|
{
|
2017-02-09 12:56:37 +03:00
|
|
|
fprintf(stdout,
|
|
|
|
"PLOT ARC X %d Y %d RADIUS %d ANGLE1 %d ANGLE2 %d\n",
|
|
|
|
x, y, radius, angle1, angle2);
|
|
|
|
return NSERROR_OK;
|
2011-03-12 18:08:07 +03:00
|
|
|
}
|
|
|
|
|
2017-02-09 12:56:37 +03:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Plots a circle
|
|
|
|
*
|
|
|
|
* Plot a circle centered on (x,y), which is optionally filled.
|
|
|
|
*
|
|
|
|
* \param ctx The current redraw context.
|
2017-02-15 02:05:30 +03:00
|
|
|
* \param style Style controlling the circle plot.
|
2017-02-09 12:56:37 +03:00
|
|
|
* \param x x coordinate of circle centre.
|
|
|
|
* \param y y coordinate of circle centre.
|
|
|
|
* \param radius circle radius.
|
|
|
|
* \return NSERROR_OK on success else error code.
|
|
|
|
*/
|
|
|
|
static nserror
|
|
|
|
monkey_plot_disc(const struct redraw_context *ctx,
|
|
|
|
const plot_style_t *style,
|
|
|
|
int x, int y, int radius)
|
2011-03-12 18:08:07 +03:00
|
|
|
{
|
2017-02-09 12:56:37 +03:00
|
|
|
fprintf(stdout,
|
|
|
|
"PLOT DISC X %d Y %d RADIUS %d\n",
|
|
|
|
x, y, radius);
|
|
|
|
return NSERROR_OK;
|
2011-03-12 18:08:07 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2017-02-09 12:56:37 +03:00
|
|
|
/**
|
|
|
|
* 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.
|
2017-02-15 02:05:30 +03:00
|
|
|
* \param style Style controlling the line plot.
|
2017-02-09 12:56:37 +03:00
|
|
|
* \param line A rectangle defining the line to be drawn
|
|
|
|
* \return NSERROR_OK on success else error code.
|
|
|
|
*/
|
|
|
|
static nserror
|
|
|
|
monkey_plot_line(const struct redraw_context *ctx,
|
|
|
|
const plot_style_t *style,
|
|
|
|
const struct rect *line)
|
2011-03-12 18:08:07 +03:00
|
|
|
{
|
2017-02-09 12:56:37 +03:00
|
|
|
fprintf(stdout,
|
|
|
|
"PLOT LINE X0 %d Y0 %d X1 %d Y1 %d\n",
|
|
|
|
line->x0, line->y0, line->x1, line->y1);
|
|
|
|
return NSERROR_OK;
|
2011-03-12 18:08:07 +03:00
|
|
|
}
|
|
|
|
|
2017-02-09 12:56:37 +03:00
|
|
|
|
|
|
|
/**
|
|
|
|
* 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.
|
2017-02-15 02:05:30 +03:00
|
|
|
* \param style Style controlling the rectangle plot.
|
2017-02-09 12:56:37 +03:00
|
|
|
* \param rect A rectangle defining the line to be drawn
|
|
|
|
* \return NSERROR_OK on success else error code.
|
|
|
|
*/
|
|
|
|
static nserror
|
|
|
|
monkey_plot_rectangle(const struct redraw_context *ctx,
|
|
|
|
const plot_style_t *style,
|
|
|
|
const struct rect *rect)
|
2011-03-12 18:08:07 +03:00
|
|
|
{
|
2017-02-09 12:56:37 +03:00
|
|
|
fprintf(stdout,
|
|
|
|
"PLOT RECT X0 %d Y0 %d X1 %d Y1 %d\n",
|
|
|
|
rect->x0, rect->y0, rect->x1, rect->y1);
|
|
|
|
return NSERROR_OK;
|
2011-03-12 18:08:07 +03:00
|
|
|
}
|
|
|
|
|
2017-02-09 12:56:37 +03:00
|
|
|
|
|
|
|
/**
|
|
|
|
* 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.
|
2017-02-15 02:05:30 +03:00
|
|
|
* \param style Style controlling the polygon plot.
|
2017-02-09 12:56:37 +03:00
|
|
|
* \param p verticies of polygon
|
|
|
|
* \param n number of verticies.
|
|
|
|
* \return NSERROR_OK on success else error code.
|
|
|
|
*/
|
|
|
|
static nserror
|
|
|
|
monkey_plot_polygon(const struct redraw_context *ctx,
|
|
|
|
const plot_style_t *style,
|
|
|
|
const int *p,
|
|
|
|
unsigned int n)
|
2011-03-12 18:08:07 +03:00
|
|
|
{
|
2017-02-09 12:56:37 +03:00
|
|
|
fprintf(stdout,
|
|
|
|
"PLOT POLYGON VERTICIES %d\n",
|
|
|
|
n);
|
|
|
|
return NSERROR_OK;
|
2011-03-12 18:08:07 +03:00
|
|
|
}
|
|
|
|
|
2017-02-09 12:56:37 +03:00
|
|
|
|
|
|
|
/**
|
|
|
|
* 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 width The width of the path
|
|
|
|
* \param transform A transform to apply to the path.
|
|
|
|
* \return NSERROR_OK on success else error code.
|
|
|
|
*/
|
|
|
|
static nserror
|
|
|
|
monkey_plot_path(const struct redraw_context *ctx,
|
|
|
|
const plot_style_t *pstyle,
|
|
|
|
const float *p,
|
|
|
|
unsigned int n,
|
|
|
|
float width,
|
|
|
|
const float transform[6])
|
2011-03-12 18:08:07 +03:00
|
|
|
{
|
2017-02-09 12:56:37 +03:00
|
|
|
fprintf(stdout,
|
|
|
|
"PLOT PATH VERTICIES %d WIDTH %f\n",
|
|
|
|
n, width);
|
|
|
|
return NSERROR_OK;
|
2011-03-12 18:08:07 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2017-02-09 12:56:37 +03:00
|
|
|
/**
|
|
|
|
* 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.
|
|
|
|
*/
|
|
|
|
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)
|
2011-03-12 18:08:07 +03:00
|
|
|
{
|
2017-02-09 12:56:37 +03:00
|
|
|
fprintf(stdout,
|
|
|
|
"PLOT BITMAP X %d Y %d WIDTH %d HEIGHT %d\n",
|
|
|
|
x, y, width, height);
|
|
|
|
return NSERROR_OK;
|
2011-03-12 18:08:07 +03:00
|
|
|
}
|
|
|
|
|
2017-02-09 12:56:37 +03:00
|
|
|
|
|
|
|
/**
|
|
|
|
* 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.
|
|
|
|
*/
|
|
|
|
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)
|
2011-03-12 18:08:07 +03:00
|
|
|
{
|
2017-02-09 12:56:37 +03:00
|
|
|
fprintf(stdout,
|
|
|
|
"PLOT TEXT X %d Y %d STR %*s\n",
|
|
|
|
x, y, (int)length, text);
|
|
|
|
return NSERROR_OK;
|
2011-03-12 18:08:07 +03:00
|
|
|
}
|
|
|
|
|
2017-02-09 12:56:37 +03:00
|
|
|
|
|
|
|
/** monkey plotter operations table */
|
2016-05-04 17:08:36 +03:00
|
|
|
static const struct plotter_table plotters = {
|
2011-03-12 18:08:07 +03:00
|
|
|
.clip = monkey_plot_clip,
|
|
|
|
.arc = monkey_plot_arc,
|
|
|
|
.disc = monkey_plot_disc,
|
|
|
|
.line = monkey_plot_line,
|
|
|
|
.rectangle = monkey_plot_rectangle,
|
|
|
|
.polygon = monkey_plot_polygon,
|
|
|
|
.path = monkey_plot_path,
|
|
|
|
.bitmap = monkey_plot_bitmap,
|
|
|
|
.text = monkey_plot_text,
|
|
|
|
.option_knockout = true,
|
|
|
|
};
|
2016-05-04 17:08:36 +03:00
|
|
|
|
|
|
|
const struct plotter_table* monkey_plotters = &plotters;
|