contents up previous next

wxprintout

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 wxdc. instances of this class are passed to wxprinter::print or to a wxprintpreview object to initiate printing or previewing.

your derived wxprintout 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 wxprintout subclass to draw the printout image. you may also add additional drawing elements within your wxprintout 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 wxprintout 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

wxobject

include files

<wx/print.h>

see also

printing framework overview, wxprinterdc, wxprintdialog, wxpagesetupdialog, wxprinter, wxprintpreview

members

wxprintout::wxprintout
wxprintout::~wxprintout
wxprintout::getdc
wxprintout::getpageinfo
wxprintout::getpagesizemm
wxprintout::getpagesizepixels
wxprintout::getpaperrectpixels
wxprintout::getppiprinter
wxprintout::getppiscreen
wxprintout::gettitle
wxprintout::haspage
wxprintout::ispreview
wxprintout::fitthissizetopaper
wxprintout::fitthissizetopage
wxprintout::fitthissizetopagemargins
wxprintout::mapscreensizetopaper
wxprintout::mapscreensizetopage
wxprintout::mapscreensizetopagemargins
wxprintout::mapscreensizetodevice
wxprintout::getlogicalpaperrect
wxprintout::getlogicalpagerect
wxprintout::getlogicalpagemarginsrect
wxprintout::setlogicalorigin
wxprintout::offsetlogicalorigin
wxprintout::onbegindocument
wxprintout::onenddocument
wxprintout::onbeginprinting
wxprintout::onendprinting
wxprintout::onprepareprinting
wxprintout::onprintpage


wxprintout::wxprintout

wxprintout(const wxstring& 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)


wxprintout::~wxprintout

~wxprintout()

destructor.


wxprintout::getdc

wxdc * getdc()

returns the device context associated with the printout (given to the printout at start of printing or previewing). this will be a wxprinterdc if printing under windows or mac, a wxpostscriptdc if printing on other platforms, and a wxmemorydc if previewing.


wxprintout::getpageinfo

void getpageinfo(int *minpage, int *maxpage, int *pagefrom, int *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.

wxpython note: when this method is implemented in a derived python class, it should be designed to take no parameters (other than the self reference) and to return a tuple of four integers.

wxperl note: when this method is overridden in a derived class, it must not take any parameters, and returns a 4-element list.


wxprintout::getpagesizemm

void getpagesizemm(int *w, int *h)

returns the size of the printer page in millimetres.

wxpython note: this method returns the output-only parameters as a tuple.

wxperl note: in wxperl this method takes no arguments and returns a 2-element list ( w, h )


wxprintout::getpagesizepixels

void getpagesizepixels(int *w, int *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 wxdc::getsize; 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.

wxpython note: this method returns the output-only parameters as a tuple.

wxperl note: in wxperl this method takes no arguments and returns a 2-element list ( w, h )


wxprintout::getpaperrectpixels

wxrect getpaperrectpixels()

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 wxdc::getpagesizepixels. 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 wxdc::getpagesizepixels. 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.


wxprintout::getppiprinter

void getppiprinter(int *w, int *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.

wxpython note: this method returns the output-only parameters as a tuple.

wxperl note: in wxperl this method takes no arguments and returns a 2-element list ( w, h )


wxprintout::getppiscreen

void getppiscreen(int *w, int *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.


wxprintout::gettitle

wxstring gettitle()

returns the title of the printout

wxpython note: this method returns the output-only parameters as a tuple.

wxperl note: in wxperl this method takes no arguments and returns a 2-element list ( w, h )


wxprintout::haspage

bool haspage(int 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.


wxprintout::ispreview

bool ispreview()

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


wxprintout::fitthissizetopaper

void fitthissizetopaper(const wxsize& imagesize)

set the user scale and device origin of the wxdc associated with this wxprintout 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.


wxprintout::fitthissizetopage

void fitthissizetopage(const wxsize& imagesize)

set the user scale and device origin of the wxdc associated with this wxprintout 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.


wxprintout::fitthissizetopagemargins

void fitthissizetopagemargins(const wxsize& imagesize, const wxpagesetupdialogdata& pagesetupdata)

set the user scale and device origin of the wxdc associated with this wxprintout so that the given image size fits entirely within the page margins set in the given wxpagesetupdialogdata 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 wxpagesetupdialog does not let you set the page margins; you'll have to provide your own mechanism, or you can use the mac-only class wxmacpagemarginsdialog.


wxprintout::mapscreensizetopaper

void mapscreensizetopaper()

set the user scale and device origin of the wxdc associated with this wxprintout 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.


wxprintout::mapscreensizetopage

void mapscreensizetopage()

this sets the user scale of the wxdc assocated with this wxprintout to the same scale as mapscreensizetopaper but sets the logical origin to the top left corner of the page rectangle.


wxprintout::mapscreensizetopagemargins

void mapscreensizetopagemargins(const wxpagesetupdialogdata& pagesetupdata)

this sets the user scale of the wxdc assocated with this wxprintout to the same scale as mapscreensizetopagemargins but sets the logical origin to the top left corner of the page margins specified by the given wxpagesetupdialogdata object.


wxprintout::mapscreensizetodevice

void mapscreensizetodevice()

set the user scale and device origin of the wxdc associated with this wxprintout 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 wxdc 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, wxwidgets'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.


wxprintout::getlogicalpaperrect

wxrect getlogicalpaperrect()

return the rectangle corresponding to the paper in the associated wxdc's logical coordinates for the current user scale and device origin.


wxprintout::getlogicalpagerect

wxrect getlogicalpagerect()

return the rectangle corresponding to the page in the associated wxdc'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.


wxprintout::getlogicalpagemarginsrect

wxrect getlogicalpagemarginsrect(const wxpagesetupdialogdata& pagesetupdata)

return the rectangle corresponding to the page margins specified by the given wxpagesetupdialogdata object in the associated wxdc'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.


wxprintout::setlogicalorigin

void setlogicalorigin(wxcoord x, wxcoord y)

set the device origin of the associated wxdc so that the current logical point becomes the new logical origin.


wxprintout::offsetlogicalorigin

void offsetlogicalorigin(wxcoord xoff, wxcoord yoff)

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


wxprintout::onbegindocument

bool onbegindocument(int startpage, int 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 wxprintout::onbegindocument must be called (and the return value checked) from within the overridden function, since it calls wxdc::startdoc.

wxpython note: if this method is overridden in a python class then the base class version can be called by using the method base_onbegindocument(startpage, endpage).


wxprintout::onenddocument

void onenddocument()

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

the base wxprintout::onenddocument must be called from within the overridden function, since it calls wxdc::enddoc.


wxprintout::onbeginprinting

void onbeginprinting()

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).


wxprintout::onendprinting

void onendprinting()

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).


wxprintout::onprepareprinting

void onprepareprinting()

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


wxprintout::onprintpage

bool onprintpage(int pagenum)

called by the framework when a page should be printed. returning false cancels the print job. the application can use wxprintout::getdc to obtain a device context to draw on.