FLTK 1.4.4: Fl_PDF_File_Surface Class Reference

FLTK 1.4.4

Loading...
Searching...
No Matches
Fl_PDF_File_Surface Class Reference

To send graphical output to a PDF file. More...

`#include <Fl_PDF_File_Surface.H>`

Inheritance diagram for Fl_PDF_File_Surface:

## Public Member Functions
int | begin_document (const char *pathname, enum Fl_Paged_Device::Page_Format format=Fl_Paged_Device::A4, enum Fl_Paged_Device::Page_Layout layout=Fl_Paged_Device::PORTRAIT, char **perr=NULL)
| Prepare to draw to a PDF document identified by its pathname.
int | begin_job (const char *defaultfilename, char **perr=NULL)
| Prepare to draw to a PDF document identified with a file chooser.
int | begin_job (int, int *, int *, char **) FL_OVERRIDE
| Don't use for this class.
int | begin_page (void) FL_OVERRIDE
| Begins a new printed page.
void | end_job (void) FL_OVERRIDE
| To be called at the end of a print job.
int | end_page (void) FL_OVERRIDE
| To be called at the end of each page.
bool | is_current () FL_OVERRIDE
| Is this surface the current drawing surface?
void | margins (int *left, int *top, int *right, int *bottom) FL_OVERRIDE
| Computes the dimensions of margins that lie between the printable page area and the full page.
void | origin (int *x, int *y) FL_OVERRIDE
| Computes the coordinates of the current origin of graphics functions.
void | origin (int x, int y) FL_OVERRIDE
| Sets the position of the origin of graphics in the drawable part of the drawing surface.
const char * | pdf_filename ()
| Returns the name of the PDF document.
int | printable_rect (int *w, int *h) FL_OVERRIDE
| Computes the width and height of the drawable area of the drawing surface.
void | rotate (float angle) FL_OVERRIDE
| Rotates the graphics operations relatively to paper.
void | scale (float s_x, float s_y=0) FL_OVERRIDE
| Changes the scaling of page coordinates.
void | set_current () FL_OVERRIDE
| Make this surface the current drawing surface.
void | translate (int x, int y) FL_OVERRIDE
| Translates the current graphics origin accounting for the current rotation.
void | untranslate () FL_OVERRIDE
| Undoes the effect of a previous translate() call.
Public Member Functions inherited from Fl_Paged_Device
void | print_widget (Fl_Widget *widget, int delta_x=0, int delta_y=0)
| Synonym of draw(Fl_Widget*, int, int).
void | print_window (Fl_Window *win, int x_off=0, int y_off=0)
| Synonym of draw_decorated_window(Fl_Window*, int, int).
int | start_job (int pagecount=0, int *frompage=NULL, int *topage=NULL, char **perr_message=NULL)
| Synonym of begin_job(int pagecount, int *frompage, int *topage, char **perr_message).
int | start_page ()
| Synonym of begin_page().
virtual | ~Fl_Paged_Device ()
| The destructor.
Public Member Functions inherited from Fl_Widget_Surface
void | draw (Fl_Widget *widget, int delta_x=0, int delta_y=0)
| Draws the widget on the drawing surface.
void | draw_decorated_window (Fl_Window *win, int x_offset=0, int y_offset=0)
| Draws a window with its title bar and frame if any.
void | print_window_part (Fl_Window *win, int x, int y, int w, int h, int delta_x=0, int delta_y=0)
| Draws a rectangular part of an on-screen window.
Public Member Functions inherited from Fl_Surface_Device
Fl_Graphics_Driver * | driver ()
| Returns the graphics driver of this drawing surface.
virtual | ~Fl_Surface_Device ()
| The destructor.

## Static Public Attributes
These attributes are useful for the Wayland/X11 platform only.
static const char * | format_dialog_title = "PDF document settings"
| Localizable text of the "PDF document settings" dialog.
static const char * | format_dialog_page_size = "Page Size:"
| Localizable text of the "PDF document settings" dialog.
static const char * | format_dialog_orientation = "Orientation:"
| Localizable text of the "PDF document settings" dialog.
static const char * | format_dialog_default = "Set as default"
| Localizable text of the "PDF document settings" dialog.
Static Public Attributes inherited from Fl_Paged_Device
static const page_format | page_formats [NO_PAGE_FORMATS]
| width, height and name of all elements of the enum Page_Format.

## Additional Inherited Members
Public Types inherited from Fl_Paged_Device
enum | Page_Format { A0 = 0 , A1 , A2 , A3 , A4 , A5 , A6 , A7 , A8 , A9 , B0 , B1 , B2 , B3 , B4 , B5 , B6 , B7 , B8 , B9 , B10 , C5E , DLE , EXECUTIVE , FOLIO , LEDGER , LEGAL , LETTER , TABLOID , ENVELOPE , MEDIA = 0x1000 }
| Possible page formats. More...
enum | Page_Layout { PORTRAIT = 0 , LANDSCAPE = 0x100 , REVERSED = 0x200 , ORIENTATION = 0x300 }
| Possible page layouts. More...
Static Public Member Functions inherited from Fl_Surface_Device
static Fl_Surface_Device * | pop_current ()
| Removes the top element from the current drawing surface stack, and makes the new top element current.
static void | push_current (Fl_Surface_Device *new_current)
| Pushes `new_current` on top of the stack of current drawing surfaces, and makes it current.
static Fl_Surface_Device * | surface ()
| The current drawing surface.
Protected Member Functions inherited from Fl_Paged_Device
| Fl_Paged_Device ()
| The constructor.
Protected Member Functions inherited from Fl_Widget_Surface
| Fl_Widget_Surface (Fl_Graphics_Driver *d)
| The constructor.
Protected Member Functions inherited from Fl_Surface_Device
void | driver (Fl_Graphics_Driver *graphics_driver)
| Sets the graphics driver of this drawing surface.
virtual void | end_current ()
| FLTK calls this each time a surface ceases to be the current drawing surface.
| Fl_Surface_Device (Fl_Graphics_Driver *graphics_driver)
| Constructor that sets the graphics driver to use for the created surface.
Protected Attributes inherited from Fl_Widget_Surface
int | x_offset
| horizontal offset to the origin of graphics coordinates
int | y_offset
| vertical offset to the origin of graphics coordinates

## Detailed Description

To send graphical output to a PDF file.

Class Fl_PDF_File_Surface is used exactly as the Fl_Printer class except for its 2 member functions begin_job() and begin_document().

Platform notes:

- Windows: requires "Microsoft Print to PDF" available in Windows 10 and later.
- Wayland/X11: requires the FLTK library was built with FLTK_USE_PANGO=1.
- macOS: requires macOS 10.9 or later.

If the running platform doesn't fulfill the requirement above, the program runs but doesn't output any PDF.

## Member Function Documentation

## ◆ begin_document()

int Fl_PDF_File_Surface::begin_document | ( | const char * | pathname,
|  | enum Fl_Paged_Device::Page_Format | format = Fl_Paged_Device::A4,
|  | enum Fl_Paged_Device::Page_Layout | layout = Fl_Paged_Device::PORTRAIT,
|  | char ** | perr = NULL )

Prepare to draw to a PDF document identified by its pathname.

Parameters

  pathname | Path name for the PDF document
  format | The paper format for the PDF document
  layout | The orientation for the PDF document
  perr | NULL or address of a string that receives a message in case of error. To be deleted[] after use.

Returns
  0 for success, 2 when an error occurred.

## ◆ begin_job() [1/2]

int Fl_PDF_File_Surface::begin_job | ( | const char * | defaultfilename,
|  | char ** | perr = NULL )

Prepare to draw to a PDF document identified with a file chooser.

A dialog opens to select the location and name of the output PDF document as well as its page format and orientation.

Parameters

  defaultfilename | Default name for the PDF document
  perr | NULL or address of a string that receives a message in case of error. To be deleted[] after use.

Returns
  0 for success, 1 when the user cancelled the operation, 2 when an error occurred.

## ◆ begin_job() [2/2]

int Fl_PDF_File_Surface::begin_job | ( | int | ,
|  | int * | ,
|  | int * | ,
|  | char ** | )
| inlinevirtual

Don't use for this class.

Reimplemented from Fl_Paged_Device.

## ◆ begin_page()

int Fl_PDF_File_Surface::begin_page | ( | void |  | ) |
| inlinevirtual

Begins 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. This function also makes this surface the current drawing surface with Fl_Surface_Device::push_current().

Note
  begin_page() calls Fl_Surface_Device::push_current() and leaves this device as the active surface. If any calls between begin_page() and end_page() open dialog boxes or will otherwise draw into FLTK windows, those calls must be put between a call to Fl_Surface_Device::pop_current() and a call to Fl_Surface_Device::push_current(), or the content of the dialog box will be rendered to the printer instead of the screen.

Returns
  0 if OK, non-zero if any error

Reimplemented from Fl_Paged_Device.

## ◆ end_job()

void Fl_PDF_File_Surface::end_job | ( | void |  | ) |
| inlinevirtual

To be called at the end of a print job.

Reimplemented from Fl_Paged_Device.

## ◆ end_page()

int Fl_PDF_File_Surface::end_page | ( | void |  | ) |
| inlinevirtual

To be called at the end of each page.

This function also stops this surface from being the current drawing surface with Fl_Surface_Device::pop_current().

Note
  end_page() calls Fl_Surface_Device::pop_current(). If any calls between begin_page() and end_page() open dialog boxes or will otherwise draw into FLTK windows, those calls must be put between a call to Fl_Surface_Device::pop_current() and a call to Fl_Surface_Device::push_current().

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

Reimplemented from Fl_Paged_Device.

## ◆ is_current()

bool Fl_PDF_File_Surface::is_current | ( |  | ) |
| inlinevirtual

Is this surface the current drawing surface?

Reimplemented from Fl_Surface_Device.

## ◆ margins()

void Fl_PDF_File_Surface::margins | ( | int * | left,
|  | int * | top,
|  | int * | right,
|  | int * | bottom )
| inlinevirtual

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.

## ◆ origin() [1/2]

void Fl_PDF_File_Surface::origin | ( | int * | x,
|  | int * | y )
| inlinevirtual

Computes the coordinates of the current origin of graphics functions.

Parameters

  [out] | x,y | If non-null, *x and *y are set to the horizontal and vertical coordinates of the graphics origin.

Reimplemented from Fl_Widget_Surface.

## ◆ origin() [2/2]

void Fl_PDF_File_Surface::origin | ( | int | x,
|  | int | y )
| inlinevirtual

Sets the position of the origin of graphics in the drawable part of the drawing surface.

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 drawable area. Successive origin() calls don't combine their effects. Origin() calls are not affected by rotate() calls (for classes derived from Fl_Paged_Device).

Parameters

  [in] | x,y | Horizontal and vertical positions in the drawing surface of the desired origin of graphics.

Reimplemented from Fl_Widget_Surface.

## ◆ printable_rect()

int Fl_PDF_File_Surface::printable_rect | ( | int * | w,
|  | int * | h )
| inlinevirtual

Computes the width and height of the drawable area of the drawing surface.

Values are in the same unit as that used by FLTK drawing functions and are unchanged by calls to origin(). If the object is derived from class Fl_Paged_Device, values account for the user-selected paper type and print orientation and are changed by scale() calls.

Returns
  0 if OK, non-zero if any error

Reimplemented from Fl_Widget_Surface.

## ◆ rotate()

void Fl_PDF_File_Surface::rotate | ( | float | angle | ) |
| inlinevirtual

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.

## ◆ scale()

void Fl_PDF_File_Surface::scale | ( | float | scale_x,
|  | float | scale_y = 0 )
| inlinevirtual

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.

## ◆ set_current()

void Fl_PDF_File_Surface::set_current | ( | void |  | ) |
| inlinevirtual

Make this surface the current drawing surface.

This surface will receive all future graphics requests.

Since FLTK 1.4.0 the preferred API to change the current drawing surface is Fl_Surface_Device::push_current( ) / Fl_Surface_Device::pop_current().

Note
  It is recommended to use this function only as follows :
  - The current drawing surface is the display;
  - make current another surface, e.g., an Fl_Printer or an Fl_Image_Surface object, calling set_current() on this object;
  - draw to that surface;
  - make the display current again with Fl_Display_Device::display_device()->set_current();
    don't do any other call to set_current() before this one.

Other scenarios of drawing surface changes should be performed via Fl_Surface_Device::push_current() and Fl_Surface_Device::pop_current().

Reimplemented from Fl_Surface_Device.

## ◆ translate()

void Fl_PDF_File_Surface::translate | ( | int | x,
|  | int | y )
| inlinevirtual

Translates the current graphics origin accounting for the current rotation.

Each translate() call must be matched by an untranslate() call. Successive translate() calls add up their effects.

Reimplemented from Fl_Widget_Surface.

## ◆ untranslate()

void Fl_PDF_File_Surface::untranslate | ( | void |  | ) |
| inlinevirtual

Undoes the effect of a previous translate() call.

Reimplemented from Fl_Widget_Surface.

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

- Fl_PDF_File_Surface.H
- Fl_Device.cxx