NetSurf
Functions | Variables
print.c File Reference

GTK printing implementation. More...

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

Go to the source code of this file.

Functions

static void nsgtk_print_set_colour (colour c)
 
static nserror gtk_print_font_paint (int x, int y, const char *string, size_t length, const plot_font_style_t *fstyle)
 
static void nsgtk_print_set_solid (void)
 Set cairo context to solid plot operation. More...
 
static void nsgtk_print_set_dotted (void)
 Set cairo context to dotted plot operation. More...
 
static void nsgtk_print_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_print_plot_clip (const struct redraw_context *ctx, const struct rect *clip)
 Sets a clip rectangle for subsequent plot operations. More...
 
static nserror nsgtk_print_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_print_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_print_plot_line (const struct redraw_context *ctx, const plot_style_t *style, const struct rect *line)
 Plots a line. More...
 
static nserror nsgtk_print_plot_rectangle (const struct redraw_context *ctx, const plot_style_t *style, const struct rect *rect)
 Plots a rectangle. More...
 
static nserror nsgtk_print_plot_polygon (const struct redraw_context *ctx, const plot_style_t *style, const int *p, unsigned int n)
 
static nserror nsgtk_print_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 bool nsgtk_print_plot_pixbuf (int x, int y, int width, int height, struct bitmap *bitmap, colour bg)
 
static nserror nsgtk_print_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_print_plot_text (const struct redraw_context *ctx, const struct plot_font_style *fstyle, int x, int y, const char *text, size_t length)
 
static bool gtk_print_begin (struct print_settings *settings)
 
static bool gtk_print_next_page (void)
 
static void gtk_print_end (void)
 
void gtk_print_signal_begin_print (GtkPrintOperation *operation, GtkPrintContext *context, gpointer user_data)
 Handle the begin_print signal from the GtkPrintOperation. More...
 
void gtk_print_signal_draw_page (GtkPrintOperation *operation, GtkPrintContext *context, gint page_nr, gpointer user_data)
 Handle the draw_page signal from the GtkPrintOperation. More...
 
void gtk_print_signal_end_print (GtkPrintOperation *operation, GtkPrintContext *context, gpointer user_data)
 Handle the end_print signal from the GtkPrintOperation. More...
 

Variables

cairo_t * gtk_print_current_cr
 
static struct print_settingssettings
 
struct hlcache_handlecontent_to_print
 
static GdkRectangle cliprect
 
static const struct plotter_table nsgtk_print_plotters
 GTK print plotter table. More...
 
static const struct printer gtk_printer
 

Detailed Description

GTK printing implementation.

All the functions and structures necessary for printing( signal handlers, plotters, printer) are here. Most of the plotters have been copied from the gtk_plotters.c file.

Definition in file print.c.

Function Documentation

◆ gtk_print_begin()

static bool gtk_print_begin ( struct print_settings settings)
static

Definition at line 667 of file print.c.

◆ gtk_print_end()

static void gtk_print_end ( void  )
static

Definition at line 677 of file print.c.

◆ gtk_print_font_paint()

static nserror gtk_print_font_paint ( int  x,
int  y,
const char *  string,
size_t  length,
const plot_font_style_t fstyle 
)
static

Definition at line 76 of file print.c.

References plot_font_style::foreground, gtk_print_current_cr, line(), NSERROR_OK, nsfont_style_to_description(), nsgtk_print_set_colour(), print_settings::scale, and settings.

Referenced by nsgtk_print_plot_text().

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

◆ gtk_print_next_page()

static bool gtk_print_next_page ( void  )
static

Definition at line 672 of file print.c.

◆ gtk_print_signal_begin_print()

void gtk_print_signal_begin_print ( GtkPrintOperation *  operation,
GtkPrintContext *  context,
gpointer  user_data 
)

Handle the begin_print signal from the GtkPrintOperation.

Parameters
operationthe operation which emited the signal
contextthe print context used to set up the pages
user_datanothing in here

Definition at line 695 of file print.c.

References content_to_print, print_settings::font_func, gtk_printer, MARGINBOTTOM, MARGINLEFT, MARGINRIGHT, print_settings::margins, MARGINTOP, nsgtk_layout_table, NSLOG, print_settings::page_height, print_settings::page_width, print_set_up(), print_settings::scale, and settings.

Referenced by print_button_clicked_cb().

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

◆ gtk_print_signal_draw_page()

void gtk_print_signal_draw_page ( GtkPrintOperation *  operation,
GtkPrintContext *  context,
gint  page_nr,
gpointer  user_data 
)

Handle the draw_page signal from the GtkPrintOperation.

This function changes only the cairo context to print on.

Definition at line 745 of file print.c.

References gtk_print_current_cr, gtk_printer, NSLOG, print_draw_next_page(), and settings.

Referenced by print_button_clicked_cb().

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

◆ gtk_print_signal_end_print()

void gtk_print_signal_end_print ( GtkPrintOperation *  operation,
GtkPrintContext *  context,
gpointer  user_data 
)

Handle the end_print signal from the GtkPrintOperation.

This functions calls only the print_cleanup function from the print interface

Definition at line 757 of file print.c.

References content_to_print, gtk_printer, NSLOG, and print_cleanup().

Referenced by print_button_clicked_cb().

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

◆ nsgtk_print_plot_arc()

static nserror nsgtk_print_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 201 of file print.c.

References plot_style_s::fill_colour, gtk_print_current_cr, M_PI, NSERROR_OK, nsgtk_print_set_colour(), and nsgtk_print_set_solid().

Here is the call graph for this function:

◆ nsgtk_print_plot_bitmap()

static nserror nsgtk_print_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 587 of file print.c.

References BITMAPF_REPEAT_X, BITMAPF_REPEAT_Y, cliprect, height, nsgtk_bitmap_get_height(), nsgtk_bitmap_get_width(), nsgtk_print_plot_pixbuf(), and width.

Here is the call graph for this function:

◆ nsgtk_print_plot_clip()

static nserror nsgtk_print_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 157 of file print.c.

References clip(), cliprect, gtk_print_current_cr, max, min, NSERROR_OK, NSLOG, print_settings::page_height, print_settings::page_width, and settings.

Here is the call graph for this function:

◆ nsgtk_print_plot_disc()

static nserror nsgtk_print_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.

< Solid colour

< Doted plot

< dashed plot

Definition at line 231 of file print.c.

References plot_style_s::fill_colour, plot_style_s::fill_type, gtk_print_current_cr, M_PI, NSERROR_OK, nsgtk_print_set_colour(), nsgtk_print_set_dashed(), nsgtk_print_set_dotted(), nsgtk_print_set_solid(), nsgtk_set_line_width(), 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_print_plot_line()

static nserror nsgtk_print_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.

< Solid colour

< Doted plot

< dashed plot

Definition at line 284 of file print.c.

References gtk_print_current_cr, line(), NSERROR_OK, nsgtk_print_set_colour(), nsgtk_print_set_dashed(), nsgtk_print_set_dotted(), nsgtk_print_set_solid(), nsgtk_set_line_width(), PLOT_OP_TYPE_DASH, PLOT_OP_TYPE_DOT, 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_print_plot_path()

static nserror nsgtk_print_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 434 of file print.c.

References NSERROR_OK.

◆ nsgtk_print_plot_pixbuf()

static bool nsgtk_print_plot_pixbuf ( int  x,
int  y,
int  width,
int  height,
struct bitmap bitmap,
colour  bg 
)
static

Definition at line 448 of file print.c.

References cliprect, gtk_print_current_cr, height, bitmap::scsurface, bitmap::surface, and width.

Referenced by nsgtk_print_plot_bitmap().

Here is the caller graph for this function:

◆ nsgtk_print_plot_polygon()

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

Definition at line 390 of file print.c.

References plot_style_s::fill_colour, gtk_print_current_cr, NSERROR_OK, nsgtk_print_set_colour(), nsgtk_print_set_solid(), and NSLOG.

Here is the call graph for this function:

◆ nsgtk_print_plot_rectangle()

static nserror nsgtk_print_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.

< Solid colour

< Doted plot

< dashed plot

Definition at line 329 of file print.c.

References plot_style_s::fill_colour, plot_style_s::fill_type, gtk_print_current_cr, max, min, NSERROR_OK, nsgtk_print_set_colour(), nsgtk_print_set_dashed(), nsgtk_print_set_dotted(), nsgtk_print_set_solid(), nsgtk_set_line_width(), NSLOG, print_settings::page_height, print_settings::page_width, PLOT_OP_TYPE_DASH, PLOT_OP_TYPE_DOT, PLOT_OP_TYPE_NONE, PLOT_OP_TYPE_SOLID, settings, 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_print_plot_text()

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

Definition at line 642 of file print.c.

References gtk_print_font_paint(), and text().

Here is the call graph for this function:

◆ nsgtk_print_set_colour()

static void nsgtk_print_set_colour ( colour  c)
inlinestatic

Definition at line 54 of file print.c.

References gtk_print_current_cr.

Referenced by gtk_print_font_paint(), nsgtk_print_plot_arc(), nsgtk_print_plot_disc(), nsgtk_print_plot_line(), nsgtk_print_plot_polygon(), and nsgtk_print_plot_rectangle().

Here is the caller graph for this function:

◆ nsgtk_print_set_dashed()

static void nsgtk_print_set_dashed ( void  )
inlinestatic

Set cairo context to dashed plot operation.

Definition at line 130 of file print.c.

References gtk_print_current_cr.

Referenced by nsgtk_print_plot_disc(), nsgtk_print_plot_line(), and nsgtk_print_plot_rectangle().

Here is the caller graph for this function:

◆ nsgtk_print_set_dotted()

static void nsgtk_print_set_dotted ( void  )
inlinestatic

Set cairo context to dotted plot operation.

Definition at line 123 of file print.c.

References gtk_print_current_cr.

Referenced by nsgtk_print_plot_disc(), nsgtk_print_plot_line(), and nsgtk_print_plot_rectangle().

Here is the caller graph for this function:

◆ nsgtk_print_set_solid()

static void nsgtk_print_set_solid ( void  )
inlinestatic

Set cairo context to solid plot operation.

Definition at line 116 of file print.c.

References gtk_print_current_cr.

Referenced by nsgtk_print_plot_arc(), nsgtk_print_plot_disc(), nsgtk_print_plot_line(), nsgtk_print_plot_polygon(), and nsgtk_print_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 137 of file print.c.

References gtk_print_current_cr, plot_style_fixed_to_double, and width.

Referenced by nsgtk_print_plot_disc(), nsgtk_print_plot_line(), and nsgtk_print_plot_rectangle().

Here is the caller graph for this function:

Variable Documentation

◆ cliprect

GdkRectangle cliprect
static

Definition at line 52 of file print.c.

Referenced by nsgtk_print_plot_bitmap(), nsgtk_print_plot_clip(), and nsgtk_print_plot_pixbuf().

◆ content_to_print

struct hlcache_handle* content_to_print

◆ gtk_print_current_cr

cairo_t* gtk_print_current_cr

◆ gtk_printer

const struct printer gtk_printer
static
Initial value:
= {
}
static const struct plotter_table nsgtk_print_plotters
GTK print plotter table.
Definition: print.c:654
static bool gtk_print_begin(struct print_settings *settings)
Definition: print.c:667
static void gtk_print_end(void)
Definition: print.c:677
static bool gtk_print_next_page(void)
Definition: print.c:672

Definition at line 681 of file print.c.

Referenced by gtk_print_signal_begin_print(), gtk_print_signal_draw_page(), and gtk_print_signal_end_print().

◆ nsgtk_print_plotters

const struct plotter_table nsgtk_print_plotters
static
Initial value:
= {
.option_knockout = false,
}
static nserror nsgtk_print_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: print.c:201
static nserror nsgtk_print_plot_clip(const struct redraw_context *ctx, const struct rect *clip)
Sets a clip rectangle for subsequent plot operations.
Definition: print.c:157
static nserror nsgtk_print_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: print.c:587
static nserror nsgtk_print_plot_rectangle(const struct redraw_context *ctx, const plot_style_t *style, const struct rect *rect)
Plots a rectangle.
Definition: print.c:329
static nserror nsgtk_print_plot_text(const struct redraw_context *ctx, const struct plot_font_style *fstyle, int x, int y, const char *text, size_t length)
Definition: print.c:642
static nserror nsgtk_print_plot_polygon(const struct redraw_context *ctx, const plot_style_t *style, const int *p, unsigned int n)
Definition: print.c:390
static nserror nsgtk_print_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: print.c:434
static nserror nsgtk_print_plot_disc(const struct redraw_context *ctx, const plot_style_t *style, int x, int y, int radius)
Plots a circle.
Definition: print.c:231
static nserror nsgtk_print_plot_line(const struct redraw_context *ctx, const plot_style_t *style, const struct rect *line)
Plots a line.
Definition: print.c:284

GTK print plotter table.

Definition at line 654 of file print.c.

◆ settings

struct print_settings* settings
static