1 \membersection{Printing
}\label{printing
}
3 The wxHTML library provides printing facilities.
5 You can redirect output displayed by
\helpref{wxHtmlWindow
}{wxhtmlwindow
}
6 to the printer DC using this (or similar) code (see
{\bf printing
} sample for
11 // This method prints page number one to dc:
14 void MyPrintout::DrawPageOne(wxDC *dc)
18 // You must compute the margins there.
19 // Caution! These values are NOT in printer DC's units.
20 // These values are in screen pixels.
23 // Here we obtain internal cell representation of HTML
document:
24 // (html is our pointer to wxHtmlWindow object)
25 wxHtmlContainerCell *cell = html -> GetInternalRepresentation();
27 // Now we have to check in case our real page size is reduced
28 // (e.g. because we're drawing to a print preview memory DC)
29 int pageWidth, pageHeight;
31 dc->GetSize(&w, &h); // DC size
32 GetPageSizePixels(&pageWidth, &pageHeight); // real size
34 // Now we must scale it. This equation will map wxHtmlWindow
35 // to page in this way:
36 // |--this is whole page as printed---------|
39 // |-margin-|-----wxHtmlWindow-----|-margin-|
41 // So page width is
2*leftMargin +
[wxHtmlWindow size
]
42 // (measured in screen pixels).
43 // We will scale the printer DC so that wxHtmlWindow's content
44 // spreads from left to right:
45 float scale = (float)(
47 (float)(
2 * leftMargin + cell -> GetMaxLineWidth()));
49 // If printer pageWidth == current DC width, then this doesn't
50 // change. But w might be the preview bitmap width, so scale down.
51 float overallScale = scale * (float)(w/(float)pageWidth);
53 // Set the user scale so that our computations take effect:
54 dc->SetUserScale(overallScale, overallScale);
55 dc->SetBackgroundMode(wxTRANSPARENT);
57 // And this is - finally - HTML stuff:
58 cell -> Draw
(*dc, leftMargin, topMargin, 0, cell -> GetHeight());
62 (Thanks to Julian Smart for sample)