Fl_Printer Class Reference

OS-independent print support. More...

#include <Fl_Printer.H>

Inheritance diagram for Fl_Printer:
Fl_Paged_Device Fl_Surface_Device Fl_Device

List of all members.

Public Member Functions

const char * class_name ()
 Returns the name of the class of this object.
Fl_Graphics_Driverdriver (void)
 Returns the graphics driver of this drawing surface.
void end_job (void)
 To be called at the end of a print job.
int end_page (void)
 To be called at the end of each page.
 Fl_Printer (void)
 The constructor.
void margins (int *left, int *top, int *right, int *bottom)
 Computes the dimensions of margins that lie between the printable page area and the full page.
void origin (int x, int y)
 Sets the position in page coordinates of the origin of graphics functions.
void origin (int *x, int *y)
 Computes the page coordinates of the current origin of graphics functions.
void print_widget (Fl_Widget *widget, int delta_x=0, int delta_y=0)
 Draws the widget on the printed page.
void print_window_part (Fl_Window *win, int x, int y, int w, int h, int delta_x=0, int delta_y=0)
 Prints a rectangular part of an on-screen window.
int printable_rect (int *w, int *h)
 Computes the width and height of the printable area of the page.
void rotate (float angle)
 Rotates the graphics operations relatively to paper.
void scale (float scale_x, float scale_y=0.)
 Changes the scaling of page coordinates.
void set_current (void)
 Make this surface the current drawing surface.
int start_job (int pagecount, int *frompage=NULL, int *topage=NULL)
 Starts a print job.
int start_page (void)
 Starts a new printed page.
void translate (int x, int y)
 Translates the current graphics origin accounting for the current rotation.
void untranslate (void)
 Undoes the effect of a previous translate() call.
 ~Fl_Printer (void)
 The destructor.

Static Public Attributes

static const char * class_id = "Fl_Printer"
 A string that identifies each subclass of Fl_Device.
These attributes are effective under the Xlib platform only.



static const char * dialog_all = "All"
 [this text may be customized at run-time]
static const char * dialog_cancel_button = "Cancel"
 [this text may be customized at run-time]
static const char * dialog_copies = "Copies"
 [this text may be customized at run-time]
static const char * dialog_copyNo = "# Copies:"
 [this text may be customized at run-time]
static const char * dialog_from = "From:"
 [this text may be customized at run-time]
static const char * dialog_pages = "Pages"
 [this text may be customized at run-time]
static const char * dialog_print_button = "Print"
 [this text may be customized at run-time]
static const char * dialog_print_to_file = "Print To File"
 [this text may be customized at run-time]
static const char * dialog_printer = "Printer:"
 [this text may be customized at run-time]
static const char * dialog_properties = "Properties..."
 [this text may be customized at run-time]
static const char * dialog_range = "Print Range"
 [this text may be customized at run-time]
static const char * dialog_title = "Print"
 [this text may be customized at run-time]
static const char * dialog_to = "To:"
 [this text may be customized at run-time]
static const char * property_cancel = "Cancel"
 [this text may be customized at run-time]
static const char * property_mode = "Output Mode:"
 [this text may be customized at run-time]
static const char * property_pagesize = "Page Size:"
 [this text may be customized at run-time]
static const char * property_save = "Save"
 [this text may be customized at run-time]
static const char * property_title = "Printer Properties"
 [this text may be customized at run-time]
static const char * property_use = "Use"
 [this text may be customized at run-time]

Detailed Description

OS-independent print support.

Fl_Printer allows to use all drawing, color, text, image, and clip FLTK functions, and to have them operate on printed page(s). There are two main, non exclusive, ways to use it.

In both cases, begin by start_job(), start_page(), printable_rect() and origin() calls and finish by end_page() and end_job() calls.

Example of use: print a widget centered in a page

 #include <FL/Fl_Printer.H>
 #include <FL/fl_draw.H>
 int width, height;
 Fl_Widget *widget = ...  // a widget we want printed
 Fl_Printer *printer = new Fl_Printer();
 if (printer->start_job(1) == 0) {
  printer->start_page();
  printer->printable_rect(&width, &height);
  fl_color(FL_BLACK);
  fl_line_style(FL_SOLID, 2);
  fl_rect(0, 0, width, height);
  fl_font(FL_COURIER, 12);
  time_t now; time(&now); fl_draw(ctime(&now), 0, fl_height());
  printer->origin(width/2, height/2);
  printer->print_widget(widget, -widget->w()/2, -widget->h()/2);
  printer->end_page();
  printer->end_job();
 }
 delete printer;

Platform specifics


Member Function Documentation

const char* Fl_Printer::class_name (  )  [inline, virtual]

Returns the name of the class of this object.

Use of the class_name() function is discouraged because it will be removed from future FLTK versions.

The class of an instance of an Fl_Device subclass can be checked with code such as:

   if ( instance->class_name() == Fl_Printer::class_id ) { ... }

Reimplemented from Fl_Paged_Device.

Fl_Graphics_Driver * Fl_Printer::driver ( void   ) 

Returns the graphics driver of this drawing surface.

Reimplemented from Fl_Surface_Device.

int Fl_Printer::end_page ( void   )  [virtual]

To be called at the end of each page.

Returns:
0 if OK, non-zero if any error.

Reimplemented from Fl_Paged_Device.

void Fl_Printer::margins ( int *  left,
int *  top,
int *  right,
int *  bottom 
) [virtual]

Computes the dimensions of margins that lie between the printable page area and the full page.

Values are in the same unit as that used by FLTK drawing functions. They are changed by scale() calls.

Parameters:
[out] left If non-null, *left is set to the left margin size.
[out] top If non-null, *top is set to the top margin size.
[out] right If non-null, *right is set to the right margin size.
[out] bottom If non-null, *bottom is set to the bottom margin size.

Reimplemented from Fl_Paged_Device.

void Fl_Printer::origin ( int  x,
int  y 
) [virtual]

Sets the position in page coordinates of the origin of graphics functions.

Arguments should be expressed relatively to the result of a previous printable_rect() call. That is, printable_rect(&w, &h); origin(w/2, 0); sets the graphics origin at the top center of the page printable area. Origin() calls are not affected by rotate() calls. Successive origin() calls don't combine their effects.

Parameters:
[in] x Horizontal position in page coordinates of the desired origin of graphics functions.
[in] y Same as above, vertically.

Reimplemented from Fl_Paged_Device.

void Fl_Printer::origin ( int *  x,
int *  y 
) [virtual]

Computes the page coordinates of the current origin of graphics functions.

Parameters:
[out] x If non-null, *x is set to the horizontal page offset of graphics origin.
[out] y Same as above, vertically.

Reimplemented from Fl_Paged_Device.

void Fl_Printer::print_widget ( Fl_Widget widget,
int  delta_x = 0,
int  delta_y = 0 
) [virtual]

Draws the widget on the printed page.

The widget's position on the printed page is determined by the last call to origin() and by the optional delta_x and delta_y arguments. Its dimensions are in points unless there was a previous call to scale().

Parameters:
[in] widget Any FLTK widget (e.g., standard, custom, window).
[in] delta_x Optional horizontal offset for positioning the widget relatively to the current origin of graphics functions.
[in] delta_y Same as above, vertically.

Reimplemented from Fl_Paged_Device.

void Fl_Printer::print_window_part ( Fl_Window win,
int  x,
int  y,
int  w,
int  h,
int  delta_x = 0,
int  delta_y = 0 
) [virtual]

Prints a rectangular part of an on-screen window.

Parameters:
win The window from where to capture.
x The rectangle left
y The rectangle top
w The rectangle width
h The rectangle height
delta_x Optional horizontal offset from current graphics origin where to print the captured rectangle.
delta_y As above, vertically.

Reimplemented from Fl_Paged_Device.

int Fl_Printer::printable_rect ( int *  w,
int *  h 
) [virtual]

Computes the width and height of the printable area of the page.

Values are in the same unit as that used by FLTK drawing functions, are unchanged by calls to origin(), but are changed by scale() calls. Values account for the user-selected paper type and print orientation.

Returns:
0 if OK, non-zero if any error

Reimplemented from Fl_Paged_Device.

void Fl_Printer::rotate ( float  angle  )  [virtual]

Rotates the graphics operations relatively to paper.

The rotation is centered on the current graphics origin. Successive rotate() calls don't combine their effects.

Parameters:
angle Rotation angle in counter-clockwise degrees.

Reimplemented from Fl_Paged_Device.

void Fl_Printer::scale ( float  scale_x,
float  scale_y = 0. 
) [virtual]

Changes the scaling of page coordinates.

This function also resets the origin of graphics functions at top left of printable page area. After a scale() call, do a printable_rect() call to get the new dimensions of the printable page area. Successive scale() calls don't combine their effects.

Parameters:
scale_x Horizontal dimensions of plot are multiplied by this quantity.
scale_y Same as above, vertically. The value 0. is equivalent to setting scale_y = scale_x. Thus, scale(factor); is equivalent to scale(factor, factor);

Reimplemented from Fl_Paged_Device.

void Fl_Printer::set_current ( void   )  [virtual]

Make this surface the current drawing surface.

This surface will receive all future graphics requests.

Reimplemented from Fl_Surface_Device.

int Fl_Printer::start_job ( int  pagecount,
int *  frompage = NULL,
int *  topage = NULL 
) [virtual]

Starts a print job.

Opens a platform-specific dialog window allowing the user to set several options including the desired printer and the page orientation. Optionally, the user can also select a range of pages to be printed. This range is returned to the caller that is in charge of sending only these pages for printing.

Parameters:
[in] pagecount the total number of pages of the job (or 0 if you don't know the number of pages)
[out] frompage if non-null, *frompage is set to the first page the user wants printed
[out] topage if non-null, *topage is set to the last page the user wants printed
Returns:
0 if OK, non-zero if any error occurred or if the user cancelled the print request.

Reimplemented from Fl_Paged_Device.

int Fl_Printer::start_page ( void   )  [virtual]

Starts a new printed page.

The page coordinates are initially in points, i.e., 1/72 inch, and with origin at the top left of the printable page area.

Returns:
0 if OK, non-zero if any error

Reimplemented from Fl_Paged_Device.

void Fl_Printer::translate ( int  x,
int  y 
) [virtual]

Translates the current graphics origin accounting for the current rotation.

This function is only useful after a rotate() call. Each translate() call must be matched by an untranslate() call. Successive translate() calls add up their effects.

Reimplemented from Fl_Paged_Device.


Member Data Documentation

const char * Fl_Printer::class_id = "Fl_Printer" [static]

A string that identifies each subclass of Fl_Device.

Function class_name() applied to a device of this class returns this string.

Reimplemented from Fl_Paged_Device.


The documentation for this class was generated from the following files: