Class: Wx::PRT::Printout
Overview
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 #on_print_page and #has_page and to render the print image onto an associated DC. Instances of this class are passed to Wx::PRT::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.
Category: Printing Framework
Instance Method Summary collapse
- #fit_this_size_to_page(imageSize) ⇒ void
-
#fit_this_size_to_page_margins(imageSize, pageSetupData) ⇒ void
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.
- #fit_this_size_to_paper(imageSize) ⇒ void
-
#get_dc ⇒ Wx::DC
(also: #dc)
Returns the device context associated with the printout (given to the printout at start of printing or previewing).
-
#get_logical_page_margins_rect(pageSetupData) ⇒ Wx::Rect
(also: #logical_page_margins_rect)
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.
-
#get_logical_page_rect ⇒ Wx::Rect
(also: #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.
-
#get_logical_paper_rect ⇒ Wx::Rect
(also: #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.
-
#get_page_info ⇒ Array(Integer,Integer,Integer,Integer)
(also: #page_info)
Called by the framework to obtain information from the application about minimum and maximum page numbers to print.
-
#get_page_size_mm ⇒ Array(Integer,Integer)
(also: #page_size_mm)
Returns the size of the printer page in millimetres.
-
#get_page_size_pixels ⇒ Array(Integer,Integer)
(also: #page_size_pixels)
Returns the size of the printer page in pixels, called the page rectangle.
-
#get_pages_info(ranges) ⇒ Wx::PRT::PrintPageRange
(also: #pages_info)
Called by the framework to obtain information from the application about the entire range of pages and sub-ranges to be printed.
-
#get_paper_rect_pixels ⇒ Wx::Rect
(also: #paper_rect_pixels)
Returns the rectangle that corresponds to the entire paper in pixels, called the paper rectangle.
-
#get_ppi_printer ⇒ Array(Integer,Integer)
(also: #ppi_printer)
Returns the number of pixels per logical inch of the printer device context.
-
#get_ppi_screen ⇒ Array(Integer,Integer)
(also: #ppi_screen)
Returns the number of pixels per logical inch of the screen device context.
-
#get_preview ⇒ Wx::PRT::PrintPreview
(also: #preview)
Returns the associated preview object if any.
-
#get_title ⇒ String
(also: #title)
Returns the title of the printout.
-
#has_page(pageNum) ⇒ Boolean
(also: #has_page?)
Should be overridden to return true if the document has this page, or false if not.
-
#initialize(title = ("Wx::PRT::Printout")) ⇒ Wx::PRT::Printout
constructor
Constructor.
-
#is_preview ⇒ Boolean
(also: #preview?)
Returns true if the printout is currently being used for previewing.
- #map_screen_size_to_device ⇒ void
-
#map_screen_size_to_page ⇒ void
This sets the user scale of the DC associated 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.
-
#map_screen_size_to_page_margins(pageSetupData) ⇒ void
This sets the user scale of the DC associated 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.
- #map_screen_size_to_paper ⇒ void
-
#offset_logical_origin(xoff, yoff) ⇒ void
Shift the device origin by an amount specified in logical coordinates.
-
#on_begin_document(startPage, endPage) ⇒ Boolean
Called by the framework at the start of document printing.
-
#on_begin_printing ⇒ void
Called by the framework at the start of printing.
-
#on_end_document ⇒ void
Called by the framework at the end of document printing.
-
#on_end_printing ⇒ void
Called by the framework at the end of printing.
-
#on_prepare_printing ⇒ void
Called once by the framework before any other demands are made of the Printout object.
-
#on_print_page(pageNum) ⇒ Boolean
Called by the framework when a page should be printed.
-
#set_logical_origin(x, y) ⇒ void
Set the device origin of the associated DC so that the current logical point becomes the new logical origin.
Methods inherited from Object
#clone, #dup, #is_same_as, #un_share
Constructor Details
#initialize(title = ("Wx::PRT::Printout")) ⇒ Wx::PRT::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)
117 |
# File 'lib/wx/doc/gen/prt/printer.rb', line 117 def initialize(title=("Wx::PRT::Printout")) end |
Instance Method Details
#fit_this_size_to_page(imageSize) ⇒ void
This method returns an undefined value.
Set the user scale and device origin of the DC associated with this Wx::PRT::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.
125 |
# File 'lib/wx/doc/gen/prt/printer.rb', line 125 def fit_this_size_to_page(imageSize) end |
#fit_this_size_to_page_margins(imageSize, pageSetupData) ⇒ void
This method returns an undefined value.
Set the user scale and device origin of the DC associated with this Wx::PRT::Printout so that the given image size fits entirely within the page margins set in the given Wx::PRT::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.
On Mac, the native Wx::PRT::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 WXOSX.
139 |
# File 'lib/wx/doc/gen/prt/printer.rb', line 139 def fit_this_size_to_page_margins(imageSize, pageSetupData) end |
#fit_this_size_to_paper(imageSize) ⇒ void
This method returns an undefined value.
Set the user scale and device origin of the DC associated with this Wx::PRT::Printout so that the given image size fits entirely within the paper and the origin is at the top left corner of the paper.
Use this if you’re managing your own page margins.
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.
152 |
# File 'lib/wx/doc/gen/prt/printer.rb', line 152 def fit_this_size_to_paper(imageSize) end |
#get_dc ⇒ Wx::DC Also known as: dc
Returns the device context associated with the printout (given to the printout at start of printing or previewing).
The application can use #get_dc to obtain a device context to draw on. This will be a Wx::PRT::PrinterDC if printing under Windows or Mac, a Wx::PRT::PostScriptDC if printing on other platforms, and a MemoryDC if previewing.
159 |
# File 'lib/wx/doc/gen/prt/printer.rb', line 159 def get_dc; end |
#get_logical_page_margins_rect(pageSetupData) ⇒ Wx::Rect Also known as: logical_page_margins_rect
Return the rectangle corresponding to the page margins specified by the given Wx::PRT::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.
167 |
# File 'lib/wx/doc/gen/prt/printer.rb', line 167 def get_logical_page_margins_rect(pageSetupData) end |
#get_logical_page_rect ⇒ Wx::Rect Also known as: 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.
174 |
# File 'lib/wx/doc/gen/prt/printer.rb', line 174 def get_logical_page_rect; end |
#get_logical_paper_rect ⇒ Wx::Rect Also known as: 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.
179 |
# File 'lib/wx/doc/gen/prt/printer.rb', line 179 def get_logical_paper_rect; end |
#get_page_info ⇒ Array(Integer,Integer,Integer,Integer) Also known as: page_info
Called by the framework to obtain information from the application about minimum and maximum page numbers to print.
This function is only called if #get_pages_info is not overridden and new code should override that function instead of this one.
The values returned in pageFrom and pageTo are ignored, and the page ranges selected by user in the print dialog are always used instead. Override #get_pages_info if you need to customize the page ranges to be printed. By default returns (1, 32000) for the page minimum and maximum values. minPage must be greater than zero and maxPage must be greater than minPage, otherwise printing is aborted.
210 |
# File 'lib/wx/doc/gen/prt/printer.rb', line 210 def get_page_info; end |
#get_page_size_mm ⇒ Array(Integer,Integer) Also known as: page_size_mm
Returns the size of the printer page in millimetres.
226 |
# File 'lib/wx/doc/gen/prt/printer.rb', line 226 def get_page_size_mm; end |
#get_page_size_pixels ⇒ Array(Integer,Integer) Also known as: page_size_pixels
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.
233 |
# File 'lib/wx/doc/gen/prt/printer.rb', line 233 def get_page_size_pixels; end |
#get_pages_info(ranges) ⇒ Wx::PRT::PrintPageRange Also known as: pages_info
Called by the framework to obtain information from the application about the entire range of pages and sub-ranges to be printed.
The implementation of this function in the derived class should return the total range of pages and may also return one or more ranges of pages to print. Note that ranges vector is filled with the values selected by the user in the print dialog on entry to this function, so in many cases it shouldn’t be changed to respect the user’s choice. However, you may override it if desired and you should set the range if the associated Wx::PRT::PrintDialogData indicates that only the current or only the selected pages should be printed, e.g. when printing the current page you need to clear ranges vector and add a single range with both fromPage and toPage set to the current page index to it. As a special case, if ranges is empty on return from this function, all pages are printed. The default implementation forwards to #get_page_info for compatibility but it is recommended to override this function in the new code, and this is required to support printing the current page or selection.
221 |
# File 'lib/wx/doc/gen/prt/printer.rb', line 221 def get_pages_info(ranges) end |
#get_paper_rect_pixels ⇒ Wx::Rect Also known as: 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 DC#get_paper_rect_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.
242 |
# File 'lib/wx/doc/gen/prt/printer.rb', line 242 def get_paper_rect_pixels; end |
#get_ppi_printer ⇒ Array(Integer,Integer) Also known as: ppi_printer
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.
187 |
# File 'lib/wx/doc/gen/prt/printer.rb', line 187 def get_ppi_printer; end |
#get_ppi_screen ⇒ Array(Integer,Integer) Also known as: ppi_screen
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.
195 |
# File 'lib/wx/doc/gen/prt/printer.rb', line 195 def get_ppi_screen; end |
#get_preview ⇒ Wx::PRT::PrintPreview Also known as: preview
Returns the associated preview object if any.
If this printout object is used for previewing, returns the associated Wx::PRT::PrintPreview. Otherwise returns nil. The returned pointer is not owned by the printout and must not be deleted.
274 |
# File 'lib/wx/doc/gen/prt/printer.rb', line 274 def get_preview; end |
#get_title ⇒ String Also known as: title
Returns the title of the printout.
Todothe python note here was wrong
249 |
# File 'lib/wx/doc/gen/prt/printer.rb', line 249 def get_title; end |
#has_page(pageNum) ⇒ Boolean Also known as: has_page?
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.
257 |
# File 'lib/wx/doc/gen/prt/printer.rb', line 257 def has_page(pageNum) end |
#is_preview ⇒ Boolean Also known as: preview?
Returns true if the printout is currently being used for previewing.
265 |
# File 'lib/wx/doc/gen/prt/printer.rb', line 265 def is_preview; end |
#map_screen_size_to_device ⇒ void
This method returns an undefined value.
Set the user scale and device origin of the DC associated with this Wx::PRT::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. You can use the GetLogicalXXXRect() routines below to obtain the paper rectangle, page rectangle, or page margins rectangle to perform your own scaling.
While the underlying drawing model of macOS is floating-point, wxWidgets's drawing model scales from integer coordinates.
289 |
# File 'lib/wx/doc/gen/prt/printer.rb', line 289 def map_screen_size_to_device; end |
#map_screen_size_to_page ⇒ void
This method returns an undefined value.
This sets the user scale of the DC associated with this Wx::PRT::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.
293 |
# File 'lib/wx/doc/gen/prt/printer.rb', line 293 def map_screen_size_to_page; end |
#map_screen_size_to_page_margins(pageSetupData) ⇒ void
This method returns an undefined value.
This sets the user scale of the DC associated with this Wx::PRT::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 Wx::PRT::PageSetupDialogData object.
298 |
# File 'lib/wx/doc/gen/prt/printer.rb', line 298 def map_screen_size_to_page_margins(pageSetupData) end |
#map_screen_size_to_paper ⇒ void
This method returns an undefined value.
Set the user scale and device origin of the DC associated with this Wx::PRT::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 behaviour, e.g., in a text editor.
305 |
# File 'lib/wx/doc/gen/prt/printer.rb', line 305 def map_screen_size_to_paper; end |
#offset_logical_origin(xoff, yoff) ⇒ void
This method returns an undefined value.
Shift the device origin by an amount specified in logical coordinates.
311 |
# File 'lib/wx/doc/gen/prt/printer.rb', line 311 def offset_logical_origin(xoff, yoff) end |
#on_begin_document(startPage, endPage) ⇒ Boolean
Called by the framework at the start of document printing.
Return false from this function cancels the print job. #on_begin_document is called once for every copy printed.
The base #on_begin_document must be called (and the return value checked) from within the overridden function, since it calls DC#start_doc.
326 |
# File 'lib/wx/doc/gen/prt/printer.rb', line 326 def on_begin_document(startPage, endPage) end |
#on_begin_printing ⇒ void
This method returns an undefined value.
Called by the framework at the start of printing.
#on_begin_printing is called once for every print job (regardless of how many copies are being printed).
332 |
# File 'lib/wx/doc/gen/prt/printer.rb', line 332 def on_begin_printing; end |
#on_end_document ⇒ void
This method returns an undefined value.
Called by the framework at the end of document printing.
#on_end_document is called once for every copy printed.
The base #on_end_document must be called from within the overridden function, since it calls DC#end_doc.
344 |
# File 'lib/wx/doc/gen/prt/printer.rb', line 344 def on_end_document; end |
#on_end_printing ⇒ void
This method returns an undefined value.
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).
350 |
# File 'lib/wx/doc/gen/prt/printer.rb', line 350 def on_end_printing; end |
#on_prepare_printing ⇒ void
This method returns an undefined value.
Called once by the framework before any other demands are made of the Wx::PRT::Printout object.
This gives the object an opportunity to calculate the number of pages in the document, for example.
356 |
# File 'lib/wx/doc/gen/prt/printer.rb', line 356 def on_prepare_printing; end |
#on_print_page(pageNum) ⇒ Boolean
Called by the framework when a page should be printed.
Returning false cancels the print job.
363 |
# File 'lib/wx/doc/gen/prt/printer.rb', line 363 def on_print_page(pageNum) end |
#set_logical_origin(x, y) ⇒ void
This method returns an undefined value.
Set the device origin of the associated DC so that the current logical point becomes the new logical origin.
369 |
# File 'lib/wx/doc/gen/prt/printer.rb', line 369 def set_logical_origin(x, y) end |