wxRuby Documentation Home

# Wx::Printout

This class encapsulates the functionality of printing out an application
document. A new class must be derived and members overridden to respond to calls
such as OnPrintPage and HasPage and to render the print image onto an associated
DC. Instances of this class are passed to Printer::Print or
to a PrintPreview object to initiate printing or previewing.

Your derived Printout is responsible for drawing both the preview image and
the printed page. If your windows’ drawing routines accept an arbitrary DC as an
argument, you can re-use those routines within your Printout subclass to draw
the printout image. You may also add additional drawing elements within your
Printout subclass, like headers, footers, and/or page numbers. However, the
image on the printed page will often differ from the image drawn on the screen,
as will the print preview image — not just in the presence of headers and
footers, but typically in scale. A high-resolution printer presents a much
larger drawing surface (i.e., a higher-resolution DC); a zoomed-out preview
image presents a much smaller drawing surface (lower-resolution DC). By using
the routines FitThisSizeToXXX() and/or MapScreenSizeToXXX() within your
Printout subclass to set the user scale and origin of the associated DC, you
can easily use a single drawing routine to draw on your application’s windows,
to create the print preview image, and to create the printed paper image, and
achieve a common appearance to the preview image and the printed page.

## Derived from

Object

## See also

PrinterDC,
PrintDialog,
PageSetupDialog,
Printer,
PrintPreview

## Methods

- Printout.new
- Printout#get_dc
- Printout#get_page_info
- Printout#get_page_size_mm
- Printout#get_page_size_pixels
- Printout#get_paper_rect_pixels
- Printout#get_ppi_printer
- Printout#get_ppi_screen
- Printout#get_title
- Printout#has_page
- Printout#is_preview
- Printout#fit_this_size_to_paper
- Printout#fit_this_size_to_page
- Printout#fit_this_size_to_page_margins
- Printout#map_screen_size_to_paper
- Printout#map_screen_size_to_page
- Printout#map_screen_size_to_page_margins
- Printout#map_screen_size_to_device
- Printout#get_logical_paper_rect
- Printout#get_logical_page_rect
- Printout#get_logical_page_margins_rect
- Printout#set_logical_origin
- Printout#offset_logical_origin
- Printout#on_begin_document
- Printout#on_end_document
- Printout#on_begin_printing
- Printout#on_end_printing
- Printout#on_prepare_printing
- Printout#on_print_page

### Printout.new

Printout.new(%(arg-type)String% title = “Printout”)

Constructor. Pass an optional title argument – the current filename would be a good idea. This will appear in the printing list
(at least in MSW)

destructor()

Destructor.

### Printout#get_dc

DC get_dc()

Returns the device context associated with the printout (given to the printout at start of
printing or previewing). This will be a PrinterDC if printing under Windows or Mac,
a PostScriptDC if printing on other platforms, and a MemoryDC if previewing.

### Printout#get_page_info

get_page_info(%(arg-type)Integer% minPage, Integer maxPage, Integer pageFrom, Integer pageTo)

Called by the framework to obtain information from the application about minimum
and maximum page values that the user can select, and the required page range to
be printed. By default this returns 1, 32000 for the page minimum and maximum
values, and 1, 1 for the required page range.

If minPage is zero, the page number controls in the print dialog will be disabled.

### Printout#get_page_size_mm

get_page_size_mm(%(arg-type)Integer% w, Integer h)

Returns the size of the printer page in millimetres.

### Printout#get_page_size_pixels

get_page_size_pixels(%(arg-type)Integer% w, Integer h)

Returns the size of the printer page in pixels, called the page rectangle.
The page rectangle has a top left corner at (0,0) and a bottom right corner at
(w,h). These values may not be the same as the values returned from
DC#get_size; if the printout is being used for
previewing, a memory device context is used, which uses a bitmap size reflecting
the current preview zoom. The application must take this discrepancy into
account if previewing is to be supported.

### Printout#get_paper_rect_pixels

Rect get_paper_rect_pixels()

Returns the rectangle that corresponds to the entire paper in pixels, called the
paper rectangle. This distinction between paper rectangle and page
rectangle reflects the fact that most printers cannot print all the way to the
edge of the paper. The page rectangle is a rectangle whose top left corner is at
(0,0) and whose width and height are given by
DC#get_page_size_pixels. On MSW and Mac,
the page rectangle gives the printable area of the paper, while the paper
rectangle represents the entire paper, including non-printable borders. Thus,
the rectangle returned by GetPaperRectPixels will have a top left corner whose
coordinates are small negative numbers and the bottom right corner will have
values somewhat larger than the width and height given by
DC#get_page_size_pixels. On other
platforms and for PostScript printing, the paper is treated as if its entire
area were printable, so this function will return the same rectangle as the page
rectangle.

### Printout#get_ppi_printer

get_ppi_printer(%(arg-type)Integer% w, Integer h)

Returns the number of pixels per logical inch of the printer device context.
Dividing the printer PPI by the screen PPI can give a suitable scaling factor
for drawing text onto the printer. Remember to multiply this by a scaling factor
to take the preview DC size into account. Or you can just use the
FitThisSizeToXXX() and MapScreenSizeToXXX routines below, which do most of the
scaling calculations for you.

### Printout#get_ppi_screen

get_ppi_screen(%(arg-type)Integer% w, Integer h)

Returns the number of pixels per logical inch of the screen device context.
Dividing the printer PPI by the screen PPI can give a suitable scaling factor
for drawing text onto the printer. If you are doing your own scaling, remember
to multiply this by a scaling factor to take the preview DC size into account.

### Printout#get_title

String get_title()

Returns the title of the printout

### Printout#has_page

Boolean has_page(%(arg-type)Integer% pageNum)

Should be overridden to return true if the document has this page, or false
if not. Returning false signifies the end of the document. By default,
HasPage behaves as if the document has only one page.

### Printout#is_preview

Boolean is_preview()

Returns true if the printout is currently being used for previewing.

### Printout#fit_this_size_to_paper

fit_this_size_to_paper(%(arg-type)Size% imageSize)

Set the user scale and device origin of the DC associated with this Printout
so that the given image size fits entirely within the paper and the origin is at
the top left corner of the paper. Note that with most printers, the region
around the edges of the paper are not printable so that the edges of the image
could be cut off. Use this if you’re managing your own page margins.

### Printout#fit_this_size_to_page

fit_this_size_to_page(%(arg-type)Size% imageSize)

Set the user scale and device origin of the DC associated with this Printout
so that the given image size fits entirely within the page rectangle and the
origin is at the top left corner of the page rectangle. On MSW and Mac, the page
rectangle is the printable area of the page. On other platforms and PostScript
printing, the page rectangle is the entire paper. Use this if you want your
printed image as large as possible, but with the caveat that on some platforms,
portions of the image might be cut off at the edges.

### Printout#fit_this_size_to_page_margins

fit_this_size_to_page_margins(%(arg-type)Size% imageSize, PageSetupDialogData pageSetupData)

Set the user scale and device origin of the DC associated with this Printout
so that the given image size fits entirely within the page margins set in the
given PageSetupDialogData object. This function provides the greatest
consistency across all platforms because it does not depend on having access to
the printable area of the paper. Note that on Mac, the native PageSetupDialog
does not let you set the page margins; you’ll have to provide your own mechanism,
or you can use the Mac-only class MacPageMarginsDialog.

### Printout#map_screen_size_to_paper

map_screen_size_to_paper()

Set the user scale and device origin of the DC associated with this Printout
so that the printed page matches the screen size as closely as possible
and the logical origin is in the top left corner of the paper rectangle.
That is,
a 100-pixel object on screen should appear at the same size on the printed page. (It
will, of course, be larger or smaller in the preview image, depending on the zoom
factor.) Use this if you want WYSIWYG behavior, e.g., in a text editor.

### Printout#map_screen_size_to_page

map_screen_size_to_page()

This sets the user scale of the DC assocated with this Printout to the same
scale as map_screen_size_to_paper but sets
the logical origin to the top left corner of the page rectangle.

### Printout#map_screen_size_to_page_margins

map_screen_size_to_page_margins(%(arg-type)PageSetupDialogData% pageSetupData)

This sets the user scale of the DC assocated with this Printout to the same
scale as
map_screen_size_to_page_margins but
sets the logical origin to the top left corner of the page margins specified by
the given PageSetupDialogData object.

### Printout#map_screen_size_to_device

map_screen_size_to_device()

Set the user scale and device origin of the DC associated with this Printout
so that one screen pixel maps to one device pixel on the DC. That is, the user
scale is set to (1,1) and the device origin is set to (0,0). Use this if you
want to do your own scaling prior to calling DC drawing calls, for example, if
your underlying model is floating-point and you want to achieve maximum drawing
precision on high-resolution printers. (Note that while the underlying drawing
model of Mac OS X is floating-point, Widgets’s drawing model scales from integer
coordinates.) You can use the GetLogicalXXXRect() routines below to obtain the
paper rectangle, page rectangle, or page margins rectangle to perform your own scaling.

### Printout#get_logical_paper_rect

Rect get_logical_paper_rect()

Return the rectangle corresponding to the paper in the associated DC’s
logical coordinates for the current user scale and device origin.

### Printout#get_logical_page_rect

Rect get_logical_page_rect()

Return the rectangle corresponding to the page in the associated DC’s
logical coordinates for the current user scale and device origin.
On MSW and Mac, this will be the printable area of the paper. On other platforms
and PostScript printing, this will be the full paper rectangle.

### Printout#get_logical_page_margins_rect

Rect get_logical_page_margins_rect(%(arg-type)PageSetupDialogData% pageSetupData)

Return the rectangle corresponding to the page margins specified by the given
PageSetupDialogData object in the associated DC’s logical coordinates for the
current user scale and device origin. The page margins are specified
with respect to the edges of the paper on all platforms.

### Printout#set_logical_origin

set_logical_origin(%(arg-type)Coord% x, Coord y)

Set the device origin of the associated DC so that the current logical point
becomes the new logical origin.

### Printout#offset_logical_origin

offset_logical_origin(%(arg-type)Coord% xoff, Coord yoff)

Shift the device origin by an amount specified in logical coordinates.

### Printout#on_begin_document

Boolean on_begin_document(%(arg-type)Integer% startPage, Integer endPage)

Called by the framework at the start of document printing. Return false from
this function cancels the print job. OnBeginDocument is called once for every
copy printed.

The base Printout::OnBeginDocument must be called (and the return value
checked) from within the overridden function, since it calls DC::StartDoc.

### Printout#on_end_document

on_end_document()

Called by the framework at the end of document printing. OnEndDocument
is called once for every copy printed.

The base Printout::OnEndDocument must be called
from within the overridden function, since it calls DC::EndDoc.

### Printout#on_begin_printing

on_begin_printing()

Called by the framework at the start of printing. OnBeginPrinting is called once for every
print job (regardless of how many copies are being printed).

### Printout#on_end_printing

on_end_printing()

Called by the framework at the end of printing. OnEndPrinting
is called once for every print job (regardless of how many copies are being printed).

### Printout#on_prepare_printing

on_prepare_printing()

Called once by the framework before any other demands are made of the
Printout object. This gives the object an opportunity to calculate the
number of pages in the document, for example.

### Printout#on_print_page

Boolean on_print_page(%(arg-type)Integer% pageNum)

Called by the framework when a page should be printed. Returning false cancels
the print job. The application can use Printout::GetDC to obtain a device
context to draw on.

[This page automatically generated from the Textile source at 2023-06-09 00:45:33 +0000]