NetSurf
Macros | Functions | Variables
print.c File Reference
#include "utils/config.h"
#include <assert.h>
#include <string.h>
#include <swis.h>
#include <oslib/font.h>
#include <oslib/hourglass.h>
#include <oslib/osfile.h>
#include <oslib/osfind.h>
#include <oslib/pdriver.h>
#include <oslib/wimp.h>
#include <rufl.h>
#include <limits.h>
#include "utils/log.h"
#include "utils/messages.h"
#include "utils/nsoption.h"
#include "netsurf/browser_window.h"
#include "netsurf/plotters.h"
#include "netsurf/content.h"
#include "content/content.h"
#include "riscos/gui.h"
#include "riscos/window.h"
#include "riscos/dialog.h"
#include "riscos/menus.h"
#include "riscos/print.h"
#include "riscos/wimp.h"
#include "riscos/wimp_event.h"
#include "riscos/filetype.h"
#include "riscos/font.h"
Include dependency graph for print.c:

Go to the source code of this file.

Macros

#define ICON_PRINT_TO_BOTTOM   1
 
#define ICON_PRINT_SHEETS   2
 
#define ICON_PRINT_SHEETS_VALUE   3
 
#define ICON_PRINT_SHEETS_DOWN   4
 
#define ICON_PRINT_SHEETS_UP   5
 
#define ICON_PRINT_SHEETS_TEXT   6
 
#define ICON_PRINT_FG_IMAGES   7
 
#define ICON_PRINT_BG_IMAGES   8
 
#define ICON_PRINT_IN_BACKGROUND   9
 
#define ICON_PRINT_UPRIGHT   10
 
#define ICON_PRINT_SIDEWAYS   11
 
#define ICON_PRINT_COPIES   12
 
#define ICON_PRINT_COPIES_DOWN   13
 
#define ICON_PRINT_COPIES_UP   14
 
#define ICON_PRINT_CANCEL   15
 
#define ICON_PRINT_PRINT   16
 
#define ICON_PRINT_TEXT_BLACK   20
 

Functions

static bool ro_gui_print_click (wimp_pointer *pointer)
 Handle mouse clicks in print dialog. More...
 
static bool ro_gui_print_apply (wimp_w w)
 Handle click on the Print button in the print dialog. More...
 
static void print_update_sheets_shaded_state (bool on)
 Set shaded state of sheets. More...
 
static void print_send_printsave (struct hlcache_handle *h)
 Send a message_PRINT_SAVE. More...
 
static bool print_send_printtypeknown (wimp_message *m)
 Send a message_PRINT_TYPE_KNOWN. More...
 
static bool print_document (struct gui_window *g, const char *filename)
 Print a document. More...
 
static const char * print_declare_fonts (struct hlcache_handle *h)
 Declare fonts to the printer driver. More...
 
static void print_fonts_callback (void *context, const char *font_name, unsigned int font_size, const uint8_t *s8, const uint32_t *s32, unsigned int n, int x, int y)
 Callback for print_fonts_plot_text(). More...
 
void ro_gui_print_init (void)
 Initialise the print dialog. More...
 
void ro_gui_print_prepare (struct gui_window *g)
 Prepares all aspects of the print dialog prior to opening. More...
 
void ro_print_save_bounce (wimp_message *m)
 Handle a bounced message_PRINT_SAVE. More...
 
void ro_print_error (wimp_message *m)
 Handle message_PRINT_ERROR. More...
 
void ro_print_type_odd (wimp_message *m)
 Handle message_PRINT_TYPE_ODD. More...
 
bool ro_print_ack (wimp_message *m)
 Handle message_DATASAVE_ACK for the printing protocol. More...
 
void ro_print_dataload_bounce (wimp_message *m)
 Handle a bounced dataload message. More...
 
void ro_print_cleanup (void)
 Cleanup after printing. More...
 
static nserror print_fonts_plot_clip (const struct redraw_context *ctx, const struct rect *clip)
 
static nserror print_fonts_plot_arc (const struct redraw_context *ctx, const plot_style_t *style, int x, int y, int radius, int angle1, int angle2)
 
static nserror print_fonts_plot_disc (const struct redraw_context *ctx, const plot_style_t *style, int x, int y, int radius)
 
static nserror print_fonts_plot_line (const struct redraw_context *ctx, const plot_style_t *style, const struct rect *line)
 
static nserror print_fonts_plot_rectangle (const struct redraw_context *ctx, const plot_style_t *style, const struct rect *rect)
 
static nserror print_fonts_plot_polygon (const struct redraw_context *ctx, const plot_style_t *style, const int *p, unsigned int n)
 
static nserror print_fonts_plot_path (const struct redraw_context *ctx, const plot_style_t *pstyle, const float *p, unsigned int n, const float transform[6])
 
static nserror print_fonts_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 nserror print_fonts_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 during RO print font listing. More...
 

Variables

struct gui_windowro_print_current_window = NULL
 
bool print_text_black = false
 
bool print_active = false
 
static int print_prev_message = 0
 
static bool print_in_background = false
 
static float print_scale = 1.0
 
static int print_num_copies = 1
 
static bool print_bg_images = false
 
static int print_max_sheets = -1
 
static bool print_sideways = false
 
static char ** print_fonts_list = 0
 List of fonts in current print. More...
 
static unsigned int print_fonts_count
 Number of entries in print_fonts_list. More...
 
static const char * print_fonts_error
 Error in print_fonts_plot_text() or print_fonts_callback(). More...
 
static const struct plotter_table print_fonts_plotters
 Plotter table for print_declare_fonts(). More...
 

Macro Definition Documentation

◆ ICON_PRINT_BG_IMAGES

#define ICON_PRINT_BG_IMAGES   8

Definition at line 61 of file print.c.

◆ ICON_PRINT_CANCEL

#define ICON_PRINT_CANCEL   15

Definition at line 68 of file print.c.

◆ ICON_PRINT_COPIES

#define ICON_PRINT_COPIES   12

Definition at line 65 of file print.c.

◆ ICON_PRINT_COPIES_DOWN

#define ICON_PRINT_COPIES_DOWN   13

Definition at line 66 of file print.c.

◆ ICON_PRINT_COPIES_UP

#define ICON_PRINT_COPIES_UP   14

Definition at line 67 of file print.c.

◆ ICON_PRINT_FG_IMAGES

#define ICON_PRINT_FG_IMAGES   7

Definition at line 60 of file print.c.

◆ ICON_PRINT_IN_BACKGROUND

#define ICON_PRINT_IN_BACKGROUND   9

Definition at line 62 of file print.c.

◆ ICON_PRINT_PRINT

#define ICON_PRINT_PRINT   16

Definition at line 69 of file print.c.

◆ ICON_PRINT_SHEETS

#define ICON_PRINT_SHEETS   2

Definition at line 55 of file print.c.

◆ ICON_PRINT_SHEETS_DOWN

#define ICON_PRINT_SHEETS_DOWN   4

Definition at line 57 of file print.c.

◆ ICON_PRINT_SHEETS_TEXT

#define ICON_PRINT_SHEETS_TEXT   6

Definition at line 59 of file print.c.

◆ ICON_PRINT_SHEETS_UP

#define ICON_PRINT_SHEETS_UP   5

Definition at line 58 of file print.c.

◆ ICON_PRINT_SHEETS_VALUE

#define ICON_PRINT_SHEETS_VALUE   3

Definition at line 56 of file print.c.

◆ ICON_PRINT_SIDEWAYS

#define ICON_PRINT_SIDEWAYS   11

Definition at line 64 of file print.c.

◆ ICON_PRINT_TEXT_BLACK

#define ICON_PRINT_TEXT_BLACK   20

Definition at line 70 of file print.c.

◆ ICON_PRINT_TO_BOTTOM

#define ICON_PRINT_TO_BOTTOM   1

Definition at line 54 of file print.c.

◆ ICON_PRINT_UPRIGHT

#define ICON_PRINT_UPRIGHT   10

Definition at line 63 of file print.c.

Function Documentation

◆ print_declare_fonts()

const char * print_declare_fonts ( struct hlcache_handle h)
static

Declare fonts to the printer driver.

Parameters
hhandle to content being printed
Returns
0 on success, error message on error

Definition at line 926 of file print.c.

References content_redraw_data::background_colour, clip(), content_get_height(), content_get_width(), content_redraw(), content_redraw_data::height, redraw_context::interactive, NSLOG, print_fonts_count, print_fonts_error, print_fonts_list, print_fonts_plotters, content_redraw_data::repeat_x, content_redraw_data::repeat_y, content_redraw_data::scale, content_redraw_data::width, content_redraw_data::x, and content_redraw_data::y.

Referenced by print_document().

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

◆ print_document()

bool print_document ( struct gui_window g,
const char *  filename 
)
static

Print a document.

Parameters
ggui_window containing the document to print
filenamename of file to print to
Returns
true on success, false on error and error reported

Definition at line 521 of file print.c.

References content_redraw_data::background_colour, browser_window_get_content(), gui_window::bw, clip(), content_get_height(), content_get_type(), content_get_width(), CONTENT_HTML, content_redraw(), content_reformat(), height, content_redraw_data::height, redraw_context::interactive, NSLOG, print_active, print_bg_images, print_declare_fonts(), print_max_sheets, print_num_copies, print_scale, print_sideways, content_redraw_data::repeat_x, content_redraw_data::repeat_y, ro_gui_current_redraw_gui, ro_gui_window_invalidate_area(), ro_plot_origin_x, ro_plot_origin_y, ro_plotters, ro_warn_user(), content_redraw_data::scale, width, content_redraw_data::width, content_redraw_data::x, and content_redraw_data::y.

Referenced by ro_print_ack(), ro_print_save_bounce(), and ro_print_type_odd().

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

◆ print_fonts_callback()

void print_fonts_callback ( void *  context,
const char *  font_name,
unsigned int  font_size,
const uint8_t *  s8,
const uint32_t *  s32,
unsigned int  n,
int  x,
int  y 
)
static

Callback for print_fonts_plot_text().

The font name is added to print_fonts_list.

Definition at line 999 of file print.c.

References messages_get(), print_fonts_count, print_fonts_error, and print_fonts_list.

Referenced by print_fonts_plot_text().

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

◆ print_fonts_plot_arc()

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

Definition at line 789 of file print.c.

References NSERROR_OK.

◆ print_fonts_plot_bitmap()

static nserror print_fonts_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

Definition at line 840 of file print.c.

References NSERROR_OK.

◆ print_fonts_plot_clip()

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

Definition at line 783 of file print.c.

References NSERROR_OK.

◆ print_fonts_plot_disc()

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

Definition at line 797 of file print.c.

References NSERROR_OK.

◆ print_fonts_plot_line()

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

Definition at line 805 of file print.c.

References NSERROR_OK.

◆ print_fonts_plot_path()

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

Definition at line 830 of file print.c.

References NSERROR_OK.

◆ print_fonts_plot_polygon()

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

Definition at line 821 of file print.c.

References NSERROR_OK.

◆ print_fonts_plot_rectangle()

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

Definition at line 813 of file print.c.

References NSERROR_OK.

◆ print_fonts_plot_text()

static nserror print_fonts_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 during RO print font listing.

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 863 of file print.c.

References NSERROR_INVALID, NSERROR_OK, nsfont_read_style(), NSLOG, print_fonts_callback(), print_fonts_error, and text().

Here is the call graph for this function:

◆ print_send_printsave()

void print_send_printsave ( struct hlcache_handle h)
static

Send a message_PRINT_SAVE.

Parameters
hhandle to content to print.

Definition at line 288 of file print.c.

References content_get_title(), NSLOG, print_prev_message, ro_content_filetype(), ro_print_cleanup(), and ro_warn_user().

Referenced by ro_gui_print_apply().

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

◆ print_send_printtypeknown()

bool print_send_printtypeknown ( wimp_message *  m)
static

Send a message_PRINT_TYPE_KNOWN.

Parameters
mmessage to reply to
Returns
true on success, false otherwise

Definition at line 326 of file print.c.

References NSLOG, and ro_warn_user().

Referenced by ro_print_type_odd().

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

◆ print_update_sheets_shaded_state()

void print_update_sheets_shaded_state ( bool  on)
static

Set shaded state of sheets.

Parameters
onwhether to turn shading on or off

Definition at line 272 of file print.c.

References dialog_print, ICON_PRINT_SHEETS_DOWN, ICON_PRINT_SHEETS_TEXT, ICON_PRINT_SHEETS_UP, ICON_PRINT_SHEETS_VALUE, ro_gui_set_caret_first(), and ro_gui_set_icon_shaded_state().

Referenced by ro_gui_print_click(), and ro_gui_print_prepare().

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

◆ ro_gui_print_apply()

bool ro_gui_print_apply ( wimp_w  w)
static

Handle click on the Print button in the print dialog.

Definition at line 238 of file print.c.

References browser_window_get_content(), gui_window::bw, dialog_print, ICON_PRINT_BG_IMAGES, ICON_PRINT_COPIES, ICON_PRINT_IN_BACKGROUND, ICON_PRINT_SHEETS, ICON_PRINT_SHEETS_VALUE, ICON_PRINT_SIDEWAYS, ICON_PRINT_TEXT_BLACK, print_bg_images, print_in_background, print_max_sheets, print_num_copies, print_send_printsave(), print_sideways, print_text_black, ro_gui_get_icon_selected_state(), ro_gui_get_icon_string(), and ro_print_current_window.

Referenced by ro_gui_print_init().

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

◆ ro_gui_print_click()

bool ro_gui_print_click ( wimp_pointer *  pointer)
static

Handle mouse clicks in print dialog.

Parameters
pointerwimp_pointer block

Definition at line 218 of file print.c.

References ICON_PRINT_SHEETS, ICON_PRINT_TO_BOTTOM, and print_update_sheets_shaded_state().

Referenced by ro_gui_print_init().

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

◆ ro_gui_print_init()

void ro_gui_print_init ( void  )

◆ ro_gui_print_prepare()

void ro_gui_print_prepare ( struct gui_window g)

Prepares all aspects of the print dialog prior to opening.

Parameters
gparent window

Definition at line 158 of file print.c.

References dialog_print, ICON_PRINT_BG_IMAGES, ICON_PRINT_COPIES, ICON_PRINT_FG_IMAGES, ICON_PRINT_IN_BACKGROUND, ICON_PRINT_PRINT, ICON_PRINT_SHEETS, ICON_PRINT_SHEETS_VALUE, ICON_PRINT_SIDEWAYS, ICON_PRINT_TEXT_BLACK, ICON_PRINT_TO_BOTTOM, ICON_PRINT_UPRIGHT, NSLOG, print_bg_images, print_prev_message, print_update_sheets_shaded_state(), ro_gui_set_icon_integer(), ro_gui_set_icon_selected_state(), ro_gui_set_icon_shaded_state(), ro_gui_set_window_title(), ro_gui_wimp_event_memorise(), and ro_print_current_window.

Referenced by ro_gui_window_action_print(), and ro_gui_window_menu_warning().

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

◆ ro_print_ack()

bool ro_print_ack ( wimp_message *  m)

Handle message_DATASAVE_ACK for the printing protocol.

Parameters
mthe message to handle
Returns
true if message successfully handled, false otherwise

We cheat here and, instead of giving Printers what it asked for (a copy of the file so it can poke us later via a broadcast of PrintTypeOdd), we give it a file that it can print itself without having to bother us further. For PostScript printers (type 0) we give it a PostScript file. Otherwise, we give it a PrintOut file.

This method has a couple of advantages:

  • we can reuse this code for background printing (we simply ignore the PrintTypeOdd reply)
  • there's no need to ensure all components of a page queued to be printed still exist when it reaches the top of the queue. (which reduces complexity a fair bit)

Definition at line 429 of file print.c.

References NSLOG, print_document(), print_prev_message, ro_print_cleanup(), ro_print_current_window, ro_warn_user(), and type.

Referenced by ro_msg_datasave_ack().

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

◆ ro_print_cleanup()

void ro_print_cleanup ( void  )

Cleanup after printing.

Definition at line 502 of file print.c.

References dialog_print, print_max_sheets, print_prev_message, print_text_black, ro_gui_dialog_close(), ro_gui_menu_destroy(), and ro_print_current_window.

Referenced by print_send_printsave(), ro_gui_user_message(), ro_print_ack(), ro_print_dataload_bounce(), ro_print_error(), ro_print_save_bounce(), and ro_print_type_odd().

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

◆ ro_print_dataload_bounce()

void ro_print_dataload_bounce ( wimp_message *  m)

Handle a bounced dataload message.

Parameters
mthe message to handle

Definition at line 488 of file print.c.

References print_prev_message, and ro_print_cleanup().

Referenced by ro_gui_user_message().

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

◆ ro_print_error()

void ro_print_error ( wimp_message *  m)

Handle message_PRINT_ERROR.

Parameters
mthe message containing the error

Definition at line 370 of file print.c.

References print_prev_message, ro_print_cleanup(), and ro_warn_user().

Referenced by ro_gui_user_message().

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

◆ ro_print_save_bounce()

void ro_print_save_bounce ( wimp_message *  m)

Handle a bounced message_PRINT_SAVE.

Parameters
mthe bounced message

Definition at line 351 of file print.c.

References print_document(), print_prev_message, ro_print_cleanup(), and ro_print_current_window.

Referenced by ro_gui_user_message().

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

◆ ro_print_type_odd()

void ro_print_type_odd ( wimp_message *  m)

Handle message_PRINT_TYPE_ODD.

Parameters
mthe message to handle

Definition at line 391 of file print.c.

References print_document(), print_in_background, print_prev_message, print_send_printtypeknown(), ro_print_cleanup(), and ro_print_current_window.

Referenced by ro_gui_user_message().

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

Variable Documentation

◆ print_active

bool print_active = false

Definition at line 81 of file print.c.

Referenced by image_redraw_tinct(), nsfont_paint(), and print_document().

◆ print_bg_images

bool print_bg_images = false
static

Definition at line 89 of file print.c.

Referenced by print_document(), ro_gui_print_apply(), and ro_gui_print_prepare().

◆ print_fonts_count

unsigned int print_fonts_count
static

Number of entries in print_fonts_list.

Definition at line 95 of file print.c.

Referenced by print_declare_fonts(), and print_fonts_callback().

◆ print_fonts_error

const char* print_fonts_error
static

◆ print_fonts_list

char** print_fonts_list = 0
static

List of fonts in current print.

Definition at line 93 of file print.c.

Referenced by print_declare_fonts(), and print_fonts_callback().

◆ print_fonts_plotters

const struct plotter_table print_fonts_plotters
static
Initial value:
= {
.option_knockout = false,
}
static nserror print_fonts_plot_disc(const struct redraw_context *ctx, const plot_style_t *style, int x, int y, int radius)
Definition: print.c:797
static nserror print_fonts_plot_clip(const struct redraw_context *ctx, const struct rect *clip)
Definition: print.c:783
static nserror print_fonts_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 during RO print font listing.
Definition: print.c:863
static nserror print_fonts_plot_line(const struct redraw_context *ctx, const plot_style_t *style, const struct rect *line)
Definition: print.c:805
static nserror print_fonts_plot_arc(const struct redraw_context *ctx, const plot_style_t *style, int x, int y, int radius, int angle1, int angle2)
Definition: print.c:789
static nserror print_fonts_plot_polygon(const struct redraw_context *ctx, const plot_style_t *style, const int *p, unsigned int n)
Definition: print.c:821
static nserror print_fonts_plot_bitmap(const struct redraw_context *ctx, struct bitmap *bitmap, int x, int y, int width, int height, colour bg, bitmap_flags_t flags)
Definition: print.c:840
static nserror print_fonts_plot_rectangle(const struct redraw_context *ctx, const plot_style_t *style, const struct rect *rect)
Definition: print.c:813
static nserror print_fonts_plot_path(const struct redraw_context *ctx, const plot_style_t *pstyle, const float *p, unsigned int n, const float transform[6])
Definition: print.c:830

Plotter table for print_declare_fonts().

All the functions do nothing except for print_fonts_plot_text, which records the fonts used.

Definition at line 905 of file print.c.

Referenced by print_declare_fonts().

◆ print_in_background

bool print_in_background = false
static

Definition at line 86 of file print.c.

Referenced by ro_gui_print_apply(), and ro_print_type_odd().

◆ print_max_sheets

int print_max_sheets = -1
static

Definition at line 90 of file print.c.

Referenced by print_document(), ro_gui_print_apply(), and ro_print_cleanup().

◆ print_num_copies

int print_num_copies = 1
static

Definition at line 88 of file print.c.

Referenced by print_document(), and ro_gui_print_apply().

◆ print_prev_message

int print_prev_message = 0
static

◆ print_scale

float print_scale = 1.0
static

Definition at line 87 of file print.c.

Referenced by ami_print(), ami_print_event(), ami_print_ui(), and print_document().

◆ print_sideways

bool print_sideways = false
static

Definition at line 91 of file print.c.

Referenced by print_document(), and ro_gui_print_apply().

◆ print_text_black

bool print_text_black = false

Definition at line 80 of file print.c.

Referenced by ro_gui_print_apply(), and ro_print_cleanup().

◆ ro_print_current_window

struct gui_window* ro_print_current_window = NULL
Todo:

landscape format pages

be somewhat more intelligent and try not to crop pages half way up a line of text

make use of print stylesheets

Definition at line 79 of file print.c.

Referenced by ro_gui_print_apply(), ro_gui_print_prepare(), ro_gui_user_message(), ro_print_ack(), ro_print_cleanup(), ro_print_save_bounce(), and ro_print_type_odd().