NetSurf
Functions | Variables
plotters.c File Reference

GTK and Cairo plotter implementations. More...

#include <math.h>
#include <assert.h>
#include <gdk/gdk.h>
#include <gtk/gtk.h>
#include "utils/log.h"
#include "netsurf/plotters.h"
#include "utils/nsoption.h"
#include "gtk/layout_pango.h"
#include "gtk/plotters.h"
#include "gtk/scaffolding.h"
#include "gtk/bitmap.h"
Include dependency graph for plotters.c:

Go to the source code of this file.

Functions

void nsgtk_set_colour (colour c)
 Set cairo context colour to nsgtk colour. More...
 
static void nsgtk_set_solid (void)
 Set cairo context to solid plot operation. More...
 
static void nsgtk_set_dotted (void)
 Set cairo context to dotted plot operation. More...
 
static void nsgtk_set_dashed (void)
 Set cairo context to dashed plot operation. More...
 
static void nsgtk_set_line_width (plot_style_fixed width)
 Set cairo context line width. More...
 
static nserror nsgtk_plot_clip (const struct redraw_context *ctx, const struct rect *clip)
 Sets a clip rectangle for subsequent plot operations. More...
 
static nserror nsgtk_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. More...
 
static nserror nsgtk_plot_disc (const struct redraw_context *ctx, const plot_style_t *style, int x, int y, int radius)
 Plots a circle. More...
 
static nserror nsgtk_plot_line (const struct redraw_context *ctx, const plot_style_t *style, const struct rect *line)
 Plots a line. More...
 
void nsgtk_plot_caret (int x, int y, int h)
 Plot a caret. More...
 
static nserror nsgtk_plot_rectangle (const struct redraw_context *ctx, const plot_style_t *style, const struct rect *rect)
 Plots a rectangle. More...
 
static nserror nsgtk_plot_polygon (const struct redraw_context *ctx, const plot_style_t *style, const int *p, unsigned int n)
 Plot a polygon. More...
 
static nserror nsgtk_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. More...
 
static nserror nsgtk_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. More...
 
static nserror nsgtk_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. More...
 

Variables

cairo_t * current_cr
 
static GdkRectangle cliprect
 
const struct plotter_table nsgtk_plotters
 GTK plotter table. More...
 

Detailed Description

GTK and Cairo plotter implementations.

Uses Cairo drawing primitives to render browser output.

Todo:
remove the use of the gdk structure for clipping

Definition in file plotters.c.

Function Documentation

◆ nsgtk_plot_arc()

static nserror nsgtk_plot_arc ( const struct redraw_context ctx,
const plot_style_t style,
int  x,
int  y,
int  radius,
int  angle1,
int  angle2 
)
static

Plots an arc.

plot an arc segment around (x,y), anticlockwise from angle1 to angle2. Angles are measured anticlockwise from horizontal, in degrees.

Parameters
ctxThe current redraw context.
styleStyle controlling the arc plot.
xThe x coordinate of the arc.
yThe y coordinate of the arc.
radiusThe radius of the arc.
angle1The start angle of the arc.
angle2The finish angle of the arc.
Returns
NSERROR_OK on success else error code.

Definition at line 147 of file plotters.c.

References current_cr, plot_style_s::fill_colour, M_PI, NSERROR_OK, nsgtk_set_colour(), and nsgtk_set_solid().

Here is the call graph for this function:

◆ nsgtk_plot_bitmap()

static nserror nsgtk_plot_bitmap ( const struct redraw_context ctx,
struct bitmap bitmap,
int  x,
int  y,
int  width,
int  height,
colour  bg,
bitmap_flags_t  flags 
)
static

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.

Parameters
ctxThe current redraw context.
bitmapThe bitmap to plot
xThe x coordinate to plot the bitmap
yThe y coordiante to plot the bitmap
widthThe width of area to plot the bitmap into
heightThe height of area to plot the bitmap into
bgthe background colour to alpha blend into
flagsthe flags controlling the type of plot operation
Returns
NSERROR_OK on success else error code.

Definition at line 515 of file plotters.c.

References BITMAPF_REPEAT_X, BITMAPF_REPEAT_Y, cliprect, current_cr, height, NSERROR_OK, bitmap::surface, and width.

◆ nsgtk_plot_caret()

void nsgtk_plot_caret ( int  x,
int  y,
int  h 
)

Plot a caret.

Note
It is assumed that the plotters have been set up.

Definition at line 278 of file plotters.c.

References current_cr, nsgtk_set_colour(), and nsgtk_set_solid().

Referenced by nsgtk_window_draw_event().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ nsgtk_plot_clip()

static nserror nsgtk_plot_clip ( const struct redraw_context ctx,
const struct rect clip 
)
static

Sets a clip rectangle for subsequent plot operations.

Parameters
ctxThe current redraw context.
clipThe rectangle to limit all subsequent plot operations within.
Returns
NSERROR_OK on success else error code.

Definition at line 114 of file plotters.c.

References clip(), cliprect, current_cr, and NSERROR_OK.

Here is the call graph for this function:

◆ nsgtk_plot_disc()

static nserror nsgtk_plot_disc ( const struct redraw_context ctx,
const plot_style_t style,
int  x,
int  y,
int  radius 
)
static

Plots a circle.

Plot a circle centered on (x,y), which is optionally filled.

Parameters
ctxThe current redraw context.
styleStyle controlling the circle plot.
xx coordinate of circle centre.
yy coordinate of circle centre.
radiuscircle radius.
Returns
NSERROR_OK on success else error code.

Definition at line 177 of file plotters.c.

References current_cr, plot_style_s::fill_colour, plot_style_s::fill_type, M_PI, NSERROR_OK, nsgtk_set_colour(), nsgtk_set_dashed(), nsgtk_set_dotted(), nsgtk_set_line_width(), nsgtk_set_solid(), PLOT_OP_TYPE_DASH, PLOT_OP_TYPE_DOT, PLOT_OP_TYPE_NONE, PLOT_OP_TYPE_SOLID, plot_style_s::stroke_colour, plot_style_s::stroke_type, and plot_style_s::stroke_width.

Here is the call graph for this function:

◆ nsgtk_plot_line()

static nserror nsgtk_plot_line ( const struct redraw_context ctx,
const plot_style_t style,
const struct rect line 
)
static

Plots a line.

plot a line from (x0,y0) to (x1,y1). Coordinates are at centre of line width/thickness.

Parameters
ctxThe current redraw context.
styleStyle controlling the line plot.
lineA rectangle defining the line to be drawn
Returns
NSERROR_OK on success else error code.

Definition at line 231 of file plotters.c.

References current_cr, line(), NSERROR_OK, nsgtk_set_colour(), nsgtk_set_dashed(), nsgtk_set_dotted(), nsgtk_set_line_width(), nsgtk_set_solid(), PLOT_OP_TYPE_DASH, PLOT_OP_TYPE_DOT, PLOT_OP_TYPE_NONE, PLOT_OP_TYPE_SOLID, plot_style_s::stroke_colour, plot_style_s::stroke_type, and plot_style_s::stroke_width.

Here is the call graph for this function:

◆ nsgtk_plot_path()

static nserror nsgtk_plot_path ( const struct redraw_context ctx,
const plot_style_t pstyle,
const float *  p,
unsigned int  n,
const float  transform[6] 
)
static

Plots a path.

Path plot consisting of cubic Bezier curves. Line and fill colour is controlled by the plot style.

Parameters
ctxThe current redraw context.
pstyleStyle controlling the path plot.
pelements of path
nnunber of elements on path
transformA transform to apply to the path.
Returns
NSERROR_OK on success else error code.

Definition at line 406 of file plotters.c.

References current_cr, plot_style_s::fill_colour, NS_TRANSPARENT, NSERROR_INVALID, NSERROR_OK, nsgtk_set_colour(), nsgtk_set_line_width(), nsgtk_set_solid(), NSLOG, PLOTTER_PATH_BEZIER, PLOTTER_PATH_CLOSE, PLOTTER_PATH_LINE, PLOTTER_PATH_MOVE, plot_style_s::stroke_colour, and plot_style_s::stroke_width.

Here is the call graph for this function:

◆ nsgtk_plot_polygon()

static nserror nsgtk_plot_polygon ( const struct redraw_context ctx,
const plot_style_t style,
const int *  p,
unsigned int  n 
)
static

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.

Parameters
ctxThe current redraw context.
styleStyle controlling the polygon plot.
pverticies of polygon
nnumber of verticies.
Returns
NSERROR_OK on success else error code.

Definition at line 370 of file plotters.c.

References current_cr, plot_style_s::fill_colour, NSERROR_OK, nsgtk_set_colour(), and nsgtk_set_solid().

Here is the call graph for this function:

◆ nsgtk_plot_rectangle()

static nserror nsgtk_plot_rectangle ( const struct redraw_context ctx,
const plot_style_t style,
const struct rect rect 
)
static

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.

Parameters
ctxThe current redraw context.
styleStyle controlling the rectangle plot.
rectA rectangle defining the line to be drawn
Returns
NSERROR_OK on success else error code.

Definition at line 306 of file plotters.c.

References current_cr, plot_style_s::fill_colour, plot_style_s::fill_type, NSERROR_OK, nsgtk_set_colour(), nsgtk_set_dashed(), nsgtk_set_dotted(), nsgtk_set_line_width(), nsgtk_set_solid(), PLOT_OP_TYPE_DASH, PLOT_OP_TYPE_DOT, PLOT_OP_TYPE_NONE, PLOT_OP_TYPE_SOLID, plot_style_s::stroke_colour, plot_style_s::stroke_type, plot_style_s::stroke_width, rect::x0, rect::x1, rect::y0, and rect::y1.

Here is the call graph for this function:

◆ nsgtk_plot_text()

static nserror nsgtk_plot_text ( const struct redraw_context ctx,
const struct plot_font_style fstyle,
int  x,
int  y,
const char *  text,
size_t  length 
)
static

Text plotting.

Parameters
ctxThe current redraw context.
fstyleplot style for this text
xx coordinate
yy coordinate
textUTF-8 string to plot
lengthlength of string, in bytes
Returns
NSERROR_OK on success else error code.

Definition at line 635 of file plotters.c.

References nsfont_paint(), and text().

Here is the call graph for this function:

◆ nsgtk_set_colour()

void nsgtk_set_colour ( colour  c)

Set cairo context colour to nsgtk colour.

Parameters
cthe netsurf colour to set in cairo

Definition at line 51 of file plotters.c.

References current_cr.

Referenced by nsfont_paint(), nsgtk_plot_arc(), nsgtk_plot_caret(), nsgtk_plot_disc(), nsgtk_plot_line(), nsgtk_plot_path(), nsgtk_plot_polygon(), and nsgtk_plot_rectangle().

Here is the caller graph for this function:

◆ nsgtk_set_dashed()

static void nsgtk_set_dashed ( void  )
inlinestatic

Set cairo context to dashed plot operation.

Definition at line 84 of file plotters.c.

References current_cr.

Referenced by nsgtk_plot_disc(), nsgtk_plot_line(), and nsgtk_plot_rectangle().

Here is the caller graph for this function:

◆ nsgtk_set_dotted()

static void nsgtk_set_dotted ( void  )
inlinestatic

Set cairo context to dotted plot operation.

Definition at line 74 of file plotters.c.

References current_cr.

Referenced by nsgtk_plot_disc(), nsgtk_plot_line(), and nsgtk_plot_rectangle().

Here is the caller graph for this function:

◆ nsgtk_set_line_width()

static void nsgtk_set_line_width ( plot_style_fixed  width)
inlinestatic

Set cairo context line width.

Definition at line 94 of file plotters.c.

References current_cr, plot_style_fixed_to_double, and width.

Referenced by nsgtk_plot_disc(), nsgtk_plot_line(), nsgtk_plot_path(), and nsgtk_plot_rectangle().

Here is the caller graph for this function:

◆ nsgtk_set_solid()

static void nsgtk_set_solid ( void  )
inlinestatic

Set cairo context to solid plot operation.

Definition at line 64 of file plotters.c.

References current_cr.

Referenced by nsgtk_plot_arc(), nsgtk_plot_caret(), nsgtk_plot_disc(), nsgtk_plot_line(), nsgtk_plot_path(), nsgtk_plot_polygon(), and nsgtk_plot_rectangle().

Here is the caller graph for this function:

Variable Documentation

◆ cliprect

GdkRectangle cliprect
static

Definition at line 44 of file plotters.c.

Referenced by nsbeos_plot_bitmap(), nsgtk_plot_bitmap(), and nsgtk_plot_clip().

◆ current_cr

cairo_t* current_cr

◆ nsgtk_plotters

const struct plotter_table nsgtk_plotters
Initial value:
= {
.clip = nsgtk_plot_clip,
.disc = nsgtk_plot_disc,
.line = nsgtk_plot_line,
.rectangle = nsgtk_plot_rectangle,
.polygon = nsgtk_plot_polygon,
.path = nsgtk_plot_path,
.bitmap = nsgtk_plot_bitmap,
.text = nsgtk_plot_text,
.option_knockout = true
}
static nserror nsgtk_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: plotters.c:635
static nserror nsgtk_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: plotters.c:406
static nserror nsgtk_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: plotters.c:515
static nserror nsgtk_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: plotters.c:147
static nserror nsgtk_plot_line(const struct redraw_context *ctx, const plot_style_t *style, const struct rect *line)
Plots a line.
Definition: plotters.c:231
static nserror nsgtk_plot_polygon(const struct redraw_context *ctx, const plot_style_t *style, const int *p, unsigned int n)
Plot a polygon.
Definition: plotters.c:370
static nserror nsgtk_plot_disc(const struct redraw_context *ctx, const plot_style_t *style, int x, int y, int radius)
Plots a circle.
Definition: plotters.c:177
static nserror nsgtk_plot_rectangle(const struct redraw_context *ctx, const plot_style_t *style, const struct rect *rect)
Plots a rectangle.
Definition: plotters.c:306
static nserror nsgtk_plot_clip(const struct redraw_context *ctx, const struct rect *clip)
Sets a clip rectangle for subsequent plot operations.
Definition: plotters.c:114

GTK plotter table.

Definition at line 647 of file plotters.c.

Referenced by bitmap_render(), nsgtk_cookies_draw(), nsgtk_global_history_draw(), nsgtk_hotlist_draw(), nsgtk_local_history_draw(), nsgtk_pi_draw(), and nsgtk_window_draw_event().