]>
Commit | Line | Data |
---|---|---|
704a4b75 VS |
1 | \membersection{Printing}\label{printing} |
2 | ||
3 | The wxHTML library provides printing facilities. | |
4 | ||
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 | |
7 | more details) : | |
8 | ||
9 | \begin{verbatim} | |
10 | // | |
11 | // This method prints page number one to dc: | |
12 | // | |
13 | ||
14 | void MyPrintout::DrawPageOne(wxDC *dc) | |
15 | { | |
16 | int leftMargin = 20; | |
17 | int topMargin = 50; | |
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. | |
21 | // (see bellow) | |
22 | ||
23 | // Here we obtain internal cell representation of HTML document: | |
24 | // (html is our pointer to wxHtmlWindow object) | |
25 | wxHtmlContainerCell *cell = html -> GetInternalRepresentation(); | |
26 | ||
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; | |
30 | int w, h; | |
31 | dc->GetSize(&w, &h); // DC size | |
32 | GetPageSizePixels(&pageWidth, &pageHeight); // real size | |
33 | ||
34 | // Now we must scale it. This equation will map wxHtmlWindow | |
35 | // to page in this way: | |
36 | // |--this is whole page as printed---------| | |
37 | // | | | | | |
38 | // | | | | | |
39 | // |-margin-|-----wxHtmlWindow-----|-margin-| | |
40 | // | |
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)( | |
46 | (float)(pageWidth) / | |
47 | (float)(2 * leftMargin + cell -> GetMaxLineWidth())); | |
48 | ||
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); | |
52 | ||
53 | // Set the user scale so that our computations take effect: | |
54 | dc->SetUserScale(overallScale, overallScale); | |
55 | dc->SetBackgroundMode(wxTRANSPARENT); | |
56 | ||
57 | // And this is - finally - HTML stuff: | |
58 | cell -> Draw(*dc, leftMargin, topMargin, 0, cell -> GetHeight()); | |
59 | } | |
60 | \end{verbatim} | |
61 | ||
62 | (Thanks to Julian Smart for sample) | |
22d6efa8 | 63 |