wxPrintout(3)
π wxPrintout β Erlang Module Definition π
bestie. sit down. we are printing today. β¨
β¨ NAME β¨
wxPrintout β this class encapsulates the functionality of printing out an application document. π¨οΈ π
π¦ DESCRIPTION π¦
okay so here's the tea, bestie: you don't just use wxPrintout, you derive from it. A new class must be derived and members overridden to respond to calls such as OnPrintPage() (not implemented in wx) and HasPage() (not implemented in wx) and to render the print image onto an associated wxDC. Instances of this class are passed to wxPrinter:print/4 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 β and this is the part nobody tells you β 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. one drawing routine, three destinations, iconic behavior fr fr π
See:
- Overview printing
wxPrintDialogwxPageSetupDialogwxPrinterwxPrintPreview
wxWidgets docs: wxPrintout π«Ά
π DATA TYPES π
wxPrintout() :: wx:wx_object().
β FUNCTIONS β
π destroy
destroy(This :: wxPrintout()) -> ok.
Destroys the object. that's it. that's the whole lore. π
πΈ fitThisSizeToPage
fitThisSizeToPage(This, ImageSize) -> ok
when
This :: wxPrintout(),
ImageSize ::
{W :: integer(), H :: integer()}.
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. π¬ (big image energy, but at what cost)
π fitThisSizeToPageMargins
fitThisSizeToPageMargins(This, ImageSize, PageSetupData) -> ok
when
This :: wxPrintout(),
ImageSize ::
{W :: integer(),
H :: integer()},
PageSetupData ::
wxPageSetupDialogData:wxPageSetupDialogData().
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. portable queen behavior π
Remark: 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. π
π¦ fitThisSizeToPaper
fitThisSizeToPaper(This, ImageSize) -> ok
when
This :: wxPrintout(),
ImageSize ::
{W :: integer(), H :: integer()}.
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. πβ¨
Use this if you're managing your own page margins. independent. self-sufficient. we love to see it.
Note: 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. π
π¨οΈ getDC
getDC(This) -> wxDC:wxDC() when This :: wxPrintout().
Returns the device context associated with the printout (given to the printout at start of printing or previewing). π«Ά
The application can use getDC/1 to obtain a device context to draw on.
This will be a wxPrinterDC (not implemented in wx) if printing under Windows or Mac, a wxPostScriptDC if printing on other platforms, and a wxMemoryDC if previewing. three moods, one function π
π getLogicalPageMarginsRect
getLogicalPageMarginsRect(This, PageSetupData) ->
{X :: integer(),
Y :: integer(),
W :: integer(),
H :: integer()}
when
This :: wxPrintout(),
PageSetupData ::
wxPageSetupDialogData:wxPageSetupDialogData().
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. π
π getLogicalPageRect
getLogicalPageRect(This) ->
{X :: integer(),
Y :: integer(),
W :: integer(),
H :: integer()}
when This :: wxPrintout().
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. π¦
ποΈ getLogicalPaperRect
getLogicalPaperRect(This) ->
{X :: integer(),
Y :: integer(),
W :: integer(),
H :: integer()}
when This :: wxPrintout().
Return the rectangle corresponding to the paper in the associated wxDC's logical coordinates for the current user scale and device origin. πβ¨
π getPPIPrinter
getPPIPrinter(This) -> {W :: integer(), H :: integer()}
when This :: wxPrintout().
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. let the library cook π₯
π₯οΈ getPPIScreen
getPPIScreen(This) -> {W :: integer(), H :: integer()}
when This :: wxPrintout().
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. do NOT forget this one bestie π
π getPageSizeMM
getPageSizeMM(This) -> {W :: integer(), H :: integer()}
when This :: wxPrintout().
Returns the size of the printer page in millimetres. π metric girlies rise
π’ getPageSizePixels
getPageSizePixels(This) -> {W :: integer(), H :: integer()}
when This :: wxPrintout().
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/1; 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. π¬β¨
πΌοΈ getPaperRectPixels
getPaperRectPixels(This) ->
{X :: integer(),
Y :: integer(),
W :: integer(),
H :: integer()}
when This :: wxPrintout().
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 wxDC::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(). negative coordinates?? yes bestie, that's the whole point. π
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. π
π·οΈ getTitle
getTitle(This) -> unicode:charlist() when This :: wxPrintout().
Returns the title of the printout. π short, sweet, iconic
π isPreview
isPreview(This) -> boolean() when This :: wxPrintout().
Returns true if the printout is currently being used for previewing. β¨
π«§ mapScreenSizeToDevice
mapScreenSizeToDevice(This) -> ok when This :: wxPrintout().
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 before you call any wxDC drawing calls β like when your underlying model is floating-point and you're chasing maximum drawing precision on high-resolution printers. β¨
You can use the GetLogicalXXXRect() routines below to get the paper rectangle, the page rectangle, or the page margins rectangle, so you can do your own scaling. π
Note: While the underlying drawing model of macOS is floating-point, wxWidgets's drawing model scales from integer coordinates. (Not me picking favorites, just the facts. π)
Next up: mapScreenSizeToPage β she's giving precision. π
mapScreenSizeToPage(This) -> ok when This :: wxPrintout().
This sets the user scale of the wxDC associated with this wxPrintout to the same scale as mapScreenSizeToPaper/1, but it sets the logical origin to the top left corner of the page rectangle. Slay. π
mapScreenSizeToPageMargins β now with margins, bestie. π
mapScreenSizeToPageMargins(This, PageSetupData) -> ok
when
This :: wxPrintout(),
PageSetupData ::
wxPageSetupDialogData:wxPageSetupDialogData().
This sets the user scale of the wxDC associated with this wxPrintout to the same scale as mapScreenSizeToPageMargins/2, but it sets the logical origin to the top left corner of the page margins specified by the given wxPageSetupDialogData object. Periodt. π
mapScreenSizeToPaper β WYSIWYG girlies, this one's for you. π¦
mapScreenSizeToPaper(This) -> ok when This :: wxPrintout().
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 behaviour, e.g., in a text editor. π
new β the constructor, and she's got options. π
new(Title :: string(), OnPrintPage, [Option]) ->
wxPrintout:wxPrintout()
when
OnPrintPage ::
fun((wxPrintout(), Page :: integer()) ->
boolean()),
Option ::
{onPreparePrinting, fun((wxPrintout()) -> ok)} |
{onBeginPrinting, fun((wxPrintout()) -> ok)} |
{onEndPrinting, fun((wxPrintout()) -> ok)} |
{onBeginDocument,
fun((wxPrintout(),
StartPage :: integer(),
EndPage :: integer()) ->
boolean())} |
{onEndDocument, fun((wxPrintout()) -> ok)} |
{hasPage,
fun((wxPrintout(), Page :: integer()) -> ok)} |
{getPageInfo,
fun((wxPrintout()) ->
{MinPage :: integer(),
MaxPage :: integer(),
PageFrom :: integer(),
PageTo :: integer()})}.
Constructor. π«Ά
Creates a wxPrintout object with a callback fun and optionally other callback funs. The This argument is the wxPrintout object reference to this object. (Yes, it's giving recursion but make it fashion. π
)
Notice: The callbacks may not call other processes. π«
offsetLogicalOrigin β shift that origin, but make it logical. π
offsetLogicalOrigin(This, Xoff, Yoff) -> ok
when
This :: wxPrintout(),
Xoff :: integer(),
Yoff :: integer().
Shift the device origin by an amount specified in logical coordinates. Lowkey simple, highkey useful. π
setLogicalOrigin β set the vibe, set the origin. π
setLogicalOrigin(This, X, Y) -> ok
when
This :: wxPrintout(),
X :: integer(),
Y :: integer().
Set the device origin of the associated wxDC so that the current logical point becomes the new logical origin. Iconic. β¨
And that's the whole wxPrintout(3) saga, bestie. Shoutout to Ericsson AB and wx 2.6 β no date on this one, she's timeless. π
π
π¦ where this page comes from
- ubuntu stonking: erlang-doc 1:29.0.6+dfsg-1 Β· Apache-2.0
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms