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.
How to correctly set the device scale to inches
In other frameworks it is common to set the device scale to inches or centimeters and work from there. It would be useful to know how to do this in wxWidgets.
// Init the device scale to inches. int ppiPrinterX, ppiPrinterY; GetPPIPrinter(&ppiPrinterX, &ppiPrinterY); int pageWidth, pageHeight; GetPageSizePixels(&pageWidth, &pageHeight); int w, h; dc->GetSize(&w, &h); dc->SetUserScale(1.0f/ppiPrinterX * (float)(w/(float)pageWidth), 1.0f/ppiPrinterY * (float)(h/(float)pageHeight));