]> git.saurik.com Git - wxWidgets.git/blob - src/html/htmprint.cpp
Corrected mime types docs
[wxWidgets.git] / src / html / htmprint.cpp
1 /////////////////////////////////////////////////////////////////////////////
2 // Name: src/html/htmprint.cpp
3 // Purpose: html printing classes
4 // Author: Vaclav Slavik
5 // Created: 25/09/99
6 // RCS-ID: $Id$
7 // Copyright: (c) Vaclav Slavik, 1999
8 // Licence: wxWindows licence
9 /////////////////////////////////////////////////////////////////////////////
10
11 // For compilers that support precompilation, includes "wx/wx.h".
12 #include "wx/wxprec.h"
13
14 #ifdef __BORLANDC__
15 #pragma hdrstop
16 #endif
17
18 #if wxUSE_HTML && wxUSE_PRINTING_ARCHITECTURE && wxUSE_STREAMS
19
20 #ifndef WX_PRECOMP
21 #include "wx/log.h"
22 #include "wx/intl.h"
23 #include "wx/dc.h"
24 #include "wx/settings.h"
25 #include "wx/msgdlg.h"
26 #include "wx/module.h"
27 #endif
28
29 #include "wx/print.h"
30 #include "wx/printdlg.h"
31 #include "wx/html/htmprint.h"
32 #include "wx/wxhtml.h"
33 #include "wx/wfstream.h"
34
35
36 // default font size of normal text (HTML font size 0) for printing, in points:
37 #define DEFAULT_PRINT_FONT_SIZE 12
38
39
40 //--------------------------------------------------------------------------------
41 // wxHtmlDCRenderer
42 //--------------------------------------------------------------------------------
43
44
45 wxHtmlDCRenderer::wxHtmlDCRenderer() : wxObject()
46 {
47 m_DC = NULL;
48 m_Width = m_Height = 0;
49 m_Cells = NULL;
50 m_Parser = new wxHtmlWinParser();
51 m_FS = new wxFileSystem();
52 m_Parser->SetFS(m_FS);
53 SetStandardFonts(DEFAULT_PRINT_FONT_SIZE);
54 }
55
56
57
58 wxHtmlDCRenderer::~wxHtmlDCRenderer()
59 {
60 if (m_Cells) delete m_Cells;
61 if (m_Parser) delete m_Parser;
62 if (m_FS) delete m_FS;
63 }
64
65
66
67 void wxHtmlDCRenderer::SetDC(wxDC *dc, double pixel_scale)
68 {
69 m_DC = dc;
70 m_Parser->SetDC(m_DC, pixel_scale);
71 }
72
73
74
75 void wxHtmlDCRenderer::SetSize(int width, int height)
76 {
77 m_Width = width;
78 m_Height = height;
79 }
80
81
82 void wxHtmlDCRenderer::SetHtmlText(const wxString& html, const wxString& basepath, bool isdir)
83 {
84 if (m_DC == NULL) return;
85
86 if (m_Cells != NULL) delete m_Cells;
87
88 m_FS->ChangePathTo(basepath, isdir);
89 m_Cells = (wxHtmlContainerCell*) m_Parser->Parse(html);
90 m_Cells->SetIndent(0, wxHTML_INDENT_ALL, wxHTML_UNITS_PIXELS);
91 m_Cells->Layout(m_Width);
92 }
93
94
95 void wxHtmlDCRenderer::SetFonts(const wxString& normal_face, const wxString& fixed_face,
96 const int *sizes)
97 {
98 m_Parser->SetFonts(normal_face, fixed_face, sizes);
99 if (m_DC == NULL && m_Cells != NULL)
100 m_Cells->Layout(m_Width);
101 }
102
103 void wxHtmlDCRenderer::SetStandardFonts(int size,
104 const wxString& normal_face,
105 const wxString& fixed_face)
106 {
107 m_Parser->SetStandardFonts(size, normal_face, fixed_face);
108 if (m_DC == NULL && m_Cells != NULL)
109 m_Cells->Layout(m_Width);
110 }
111
112 int wxHtmlDCRenderer::Render(int x, int y,
113 wxArrayInt& known_pagebreaks,
114 int from, int dont_render, int to)
115 {
116 int pbreak, hght;
117
118 if (m_Cells == NULL || m_DC == NULL) return 0;
119
120 pbreak = (int)(from + m_Height);
121 while (m_Cells->AdjustPagebreak(&pbreak, known_pagebreaks)) {}
122 hght = pbreak - from;
123 if(to < hght)
124 hght = to;
125
126 if (!dont_render)
127 {
128 wxHtmlRenderingInfo rinfo;
129 wxDefaultHtmlRenderingStyle rstyle;
130 rinfo.SetStyle(&rstyle);
131 m_DC->SetBrush(*wxWHITE_BRUSH);
132 m_DC->SetClippingRegion(x, y, m_Width, hght);
133 m_Cells->Draw(*m_DC,
134 x, (y - from),
135 y, pbreak + (y /*- from*/),
136 rinfo);
137 m_DC->DestroyClippingRegion();
138 }
139
140 if (pbreak < m_Cells->GetHeight()) return pbreak;
141 else return GetTotalHeight();
142 }
143
144
145 int wxHtmlDCRenderer::GetTotalHeight()
146 {
147 if (m_Cells) return m_Cells->GetHeight();
148 else return 0;
149 }
150
151
152 //--------------------------------------------------------------------------------
153 // wxHtmlPrintout
154 //--------------------------------------------------------------------------------
155
156
157 wxList wxHtmlPrintout::m_Filters;
158
159 wxHtmlPrintout::wxHtmlPrintout(const wxString& title) : wxPrintout(title)
160 {
161 m_Renderer = new wxHtmlDCRenderer;
162 m_RendererHdr = new wxHtmlDCRenderer;
163 m_NumPages = wxHTML_PRINT_MAX_PAGES;
164 m_Document = m_BasePath = wxEmptyString; m_BasePathIsDir = true;
165 m_Headers[0] = m_Headers[1] = wxEmptyString;
166 m_Footers[0] = m_Footers[1] = wxEmptyString;
167 m_HeaderHeight = m_FooterHeight = 0;
168 SetMargins(); // to default values
169 SetStandardFonts(DEFAULT_PRINT_FONT_SIZE);
170 }
171
172
173
174 wxHtmlPrintout::~wxHtmlPrintout()
175 {
176 delete m_Renderer;
177 delete m_RendererHdr;
178 }
179
180 void wxHtmlPrintout::CleanUpStatics()
181 {
182 WX_CLEAR_LIST(wxList, m_Filters);
183 }
184
185 // Adds input filter
186 void wxHtmlPrintout::AddFilter(wxHtmlFilter *filter)
187 {
188 m_Filters.Append(filter);
189 }
190
191 void wxHtmlPrintout::OnPreparePrinting()
192 {
193 int pageWidth, pageHeight, mm_w, mm_h, scr_w, scr_h, dc_w, dc_h;
194 float ppmm_h, ppmm_v;
195
196 GetPageSizePixels(&pageWidth, &pageHeight);
197 GetPageSizeMM(&mm_w, &mm_h);
198 ppmm_h = (float)pageWidth / mm_w;
199 ppmm_v = (float)pageHeight / mm_h;
200
201 int ppiPrinterX, ppiPrinterY;
202 GetPPIPrinter(&ppiPrinterX, &ppiPrinterY);
203 int ppiScreenX, ppiScreenY;
204 GetPPIScreen(&ppiScreenX, &ppiScreenY);
205
206 wxDisplaySize(&scr_w, &scr_h);
207 GetDC()->GetSize(&dc_w, &dc_h);
208
209 GetDC()->SetUserScale((double)dc_w / (double)pageWidth,
210 (double)dc_h / (double)pageHeight);
211
212 /* prepare headers/footers renderer: */
213
214 m_RendererHdr->SetDC(GetDC(), (double)ppiPrinterY / (double)ppiScreenY);
215 m_RendererHdr->SetSize((int) (ppmm_h * (mm_w - m_MarginLeft - m_MarginRight)),
216 (int) (ppmm_v * (mm_h - m_MarginTop - m_MarginBottom)));
217 if (m_Headers[0] != wxEmptyString)
218 {
219 m_RendererHdr->SetHtmlText(TranslateHeader(m_Headers[0], 1));
220 m_HeaderHeight = m_RendererHdr->GetTotalHeight();
221 }
222 else if (m_Headers[1] != wxEmptyString)
223 {
224 m_RendererHdr->SetHtmlText(TranslateHeader(m_Headers[1], 1));
225 m_HeaderHeight = m_RendererHdr->GetTotalHeight();
226 }
227 if (m_Footers[0] != wxEmptyString)
228 {
229 m_RendererHdr->SetHtmlText(TranslateHeader(m_Footers[0], 1));
230 m_FooterHeight = m_RendererHdr->GetTotalHeight();
231 }
232 else if (m_Footers[1] != wxEmptyString)
233 {
234 m_RendererHdr->SetHtmlText(TranslateHeader(m_Footers[1], 1));
235 m_FooterHeight = m_RendererHdr->GetTotalHeight();
236 }
237
238 /* prepare main renderer: */
239 m_Renderer->SetDC(GetDC(), (double)ppiPrinterY / (double)ppiScreenY);
240 m_Renderer->SetSize((int) (ppmm_h * (mm_w - m_MarginLeft - m_MarginRight)),
241 (int) (ppmm_v * (mm_h - m_MarginTop - m_MarginBottom) -
242 m_FooterHeight - m_HeaderHeight -
243 ((m_HeaderHeight == 0) ? 0 : m_MarginSpace * ppmm_v) -
244 ((m_FooterHeight == 0) ? 0 : m_MarginSpace * ppmm_v)
245 ));
246 m_Renderer->SetHtmlText(m_Document, m_BasePath, m_BasePathIsDir);
247 CountPages();
248 }
249
250 bool wxHtmlPrintout::OnBeginDocument(int startPage, int endPage)
251 {
252 if (!wxPrintout::OnBeginDocument(startPage, endPage)) return false;
253
254 return true;
255 }
256
257
258 bool wxHtmlPrintout::OnPrintPage(int page)
259 {
260 wxDC *dc = GetDC();
261 if (dc && dc->IsOk())
262 {
263 if (HasPage(page))
264 RenderPage(dc, page);
265 return true;
266 }
267 else return false;
268 }
269
270
271 void wxHtmlPrintout::GetPageInfo(int *minPage, int *maxPage, int *selPageFrom, int *selPageTo)
272 {
273 *minPage = 1;
274 if ( m_NumPages >= (signed)m_PageBreaks.GetCount()-1)
275 *maxPage = m_NumPages;
276 else
277 *maxPage = (signed)m_PageBreaks.GetCount()-1;
278 *selPageFrom = 1;
279 *selPageTo = (signed)m_PageBreaks.GetCount()-1;
280 }
281
282
283
284 bool wxHtmlPrintout::HasPage(int pageNum)
285 {
286 return pageNum > 0 && (unsigned)pageNum < m_PageBreaks.GetCount();
287 }
288
289
290
291 void wxHtmlPrintout::SetHtmlText(const wxString& html, const wxString &basepath, bool isdir)
292 {
293 m_Document = html;
294 m_BasePath = basepath;
295 m_BasePathIsDir = isdir;
296 }
297
298 void wxHtmlPrintout::SetHtmlFile(const wxString& htmlfile)
299 {
300 wxFileSystem fs;
301 wxFSFile *ff;
302
303 if (wxFileExists(htmlfile))
304 ff = fs.OpenFile(wxFileSystem::FileNameToURL(htmlfile));
305 else
306 ff = fs.OpenFile(htmlfile);
307
308 if (ff == NULL)
309 {
310 wxLogError(htmlfile + _(": file does not exist!"));
311 return;
312 }
313
314 bool done = false;
315 wxHtmlFilterHTML defaultFilter;
316 wxString doc;
317
318 wxList::compatibility_iterator node = m_Filters.GetFirst();
319 while (node)
320 {
321 wxHtmlFilter *h = (wxHtmlFilter*) node->GetData();
322 if (h->CanRead(*ff))
323 {
324 doc = h->ReadFile(*ff);
325 done = true;
326 break;
327 }
328 node = node->GetNext();
329 }
330
331 if (!done)
332 doc = defaultFilter.ReadFile(*ff);
333
334 SetHtmlText(doc, htmlfile, false);
335 delete ff;
336 }
337
338
339
340 void wxHtmlPrintout::SetHeader(const wxString& header, int pg)
341 {
342 if (pg == wxPAGE_ALL || pg == wxPAGE_EVEN)
343 m_Headers[0] = header;
344 if (pg == wxPAGE_ALL || pg == wxPAGE_ODD)
345 m_Headers[1] = header;
346 }
347
348
349
350 void wxHtmlPrintout::SetFooter(const wxString& footer, int pg)
351 {
352 if (pg == wxPAGE_ALL || pg == wxPAGE_EVEN)
353 m_Footers[0] = footer;
354 if (pg == wxPAGE_ALL || pg == wxPAGE_ODD)
355 m_Footers[1] = footer;
356 }
357
358
359
360 void wxHtmlPrintout::CountPages()
361 {
362 wxBusyCursor wait;
363 int pageWidth, pageHeight, mm_w, mm_h;
364 float ppmm_h, ppmm_v;
365
366 GetPageSizePixels(&pageWidth, &pageHeight);
367 GetPageSizeMM(&mm_w, &mm_h);
368 ppmm_h = (float)pageWidth / mm_w;
369 ppmm_v = (float)pageHeight / mm_h;
370
371 int pos = 0;
372 m_NumPages = 0;
373 // m_PageBreaks[0] = 0;
374
375 m_PageBreaks.Clear();
376 m_PageBreaks.Add( 0);
377 do
378 {
379 pos = m_Renderer->Render((int)( ppmm_h * m_MarginLeft),
380 (int) (ppmm_v * (m_MarginTop + (m_HeaderHeight == 0 ? 0 : m_MarginSpace)) + m_HeaderHeight),
381 m_PageBreaks,
382 pos, true, INT_MAX);
383 m_PageBreaks.Add( pos);
384 if( m_PageBreaks.GetCount() > wxHTML_PRINT_MAX_PAGES)
385 {
386 wxMessageBox( _("HTML pagination algorithm generated more than the allowed maximum number of pages and it can't continue any longer!"),
387 _("Warning"), wxCANCEL | wxICON_ERROR );
388 break;
389 }
390 } while (pos < m_Renderer->GetTotalHeight());
391 }
392
393
394
395 void wxHtmlPrintout::RenderPage(wxDC *dc, int page)
396 {
397 wxBusyCursor wait;
398
399 int pageWidth, pageHeight, mm_w, mm_h, scr_w, scr_h, dc_w, dc_h;
400 float ppmm_h, ppmm_v;
401
402 GetPageSizePixels(&pageWidth, &pageHeight);
403 GetPageSizeMM(&mm_w, &mm_h);
404 ppmm_h = (float)pageWidth / mm_w;
405 ppmm_v = (float)pageHeight / mm_h;
406 wxDisplaySize(&scr_w, &scr_h);
407 dc->GetSize(&dc_w, &dc_h);
408
409 int ppiPrinterX, ppiPrinterY;
410 GetPPIPrinter(&ppiPrinterX, &ppiPrinterY);
411 wxUnusedVar(ppiPrinterX);
412 int ppiScreenX, ppiScreenY;
413 GetPPIScreen(&ppiScreenX, &ppiScreenY);
414 wxUnusedVar(ppiScreenX);
415
416 dc->SetUserScale((double)dc_w / (double)pageWidth,
417 (double)dc_h / (double)pageHeight);
418
419 m_Renderer->SetDC(dc, (double)ppiPrinterY / (double)ppiScreenY);
420
421 dc->SetBackgroundMode(wxBRUSHSTYLE_TRANSPARENT);
422
423 m_Renderer->Render((int) (ppmm_h * m_MarginLeft),
424 (int) (ppmm_v * (m_MarginTop + (m_HeaderHeight == 0 ? 0 : m_MarginSpace)) + m_HeaderHeight), m_PageBreaks,
425 m_PageBreaks[page-1], false, m_PageBreaks[page]-m_PageBreaks[page-1]);
426
427
428 m_RendererHdr->SetDC(dc, (double)ppiPrinterY / (double)ppiScreenY);
429 if (m_Headers[page % 2] != wxEmptyString)
430 {
431 m_RendererHdr->SetHtmlText(TranslateHeader(m_Headers[page % 2], page));
432 m_RendererHdr->Render((int) (ppmm_h * m_MarginLeft), (int) (ppmm_v * m_MarginTop), m_PageBreaks);
433 }
434 if (m_Footers[page % 2] != wxEmptyString)
435 {
436 m_RendererHdr->SetHtmlText(TranslateHeader(m_Footers[page % 2], page));
437 m_RendererHdr->Render((int) (ppmm_h * m_MarginLeft), (int) (pageHeight - ppmm_v * m_MarginBottom - m_FooterHeight), m_PageBreaks);
438 }
439 }
440
441
442
443 wxString wxHtmlPrintout::TranslateHeader(const wxString& instr, int page)
444 {
445 wxString r = instr;
446 wxString num;
447
448 num.Printf(wxT("%i"), page);
449 r.Replace(wxT("@PAGENUM@"), num);
450
451 num.Printf(wxT("%lu"), (unsigned long)(m_PageBreaks.GetCount() - 1));
452 r.Replace(wxT("@PAGESCNT@"), num);
453
454 const wxDateTime now = wxDateTime::Now();
455 r.Replace(wxT("@DATE@"), now.FormatDate());
456 r.Replace(wxT("@TIME@"), now.FormatTime());
457
458 r.Replace(wxT("@TITLE@"), GetTitle());
459
460 return r;
461 }
462
463
464
465 void wxHtmlPrintout::SetMargins(float top, float bottom, float left, float right, float spaces)
466 {
467 m_MarginTop = top;
468 m_MarginBottom = bottom;
469 m_MarginLeft = left;
470 m_MarginRight = right;
471 m_MarginSpace = spaces;
472 }
473
474
475
476
477 void wxHtmlPrintout::SetFonts(const wxString& normal_face, const wxString& fixed_face,
478 const int *sizes)
479 {
480 m_Renderer->SetFonts(normal_face, fixed_face, sizes);
481 m_RendererHdr->SetFonts(normal_face, fixed_face, sizes);
482 }
483
484 void wxHtmlPrintout::SetStandardFonts(int size,
485 const wxString& normal_face,
486 const wxString& fixed_face)
487 {
488 m_Renderer->SetStandardFonts(size, normal_face, fixed_face);
489 m_RendererHdr->SetStandardFonts(size, normal_face, fixed_face);
490 }
491
492
493
494 //----------------------------------------------------------------------------
495 // wxHtmlEasyPrinting
496 //----------------------------------------------------------------------------
497
498
499 wxHtmlEasyPrinting::wxHtmlEasyPrinting(const wxString& name, wxWindow *parentWindow)
500 {
501 m_ParentWindow = parentWindow;
502 m_Name = name;
503 m_PrintData = NULL;
504 m_PageSetupData = new wxPageSetupDialogData;
505 m_Headers[0] = m_Headers[1] = m_Footers[0] = m_Footers[1] = wxEmptyString;
506
507 m_PageSetupData->EnableMargins(true);
508 m_PageSetupData->SetMarginTopLeft(wxPoint(25, 25));
509 m_PageSetupData->SetMarginBottomRight(wxPoint(25, 25));
510
511 SetStandardFonts(DEFAULT_PRINT_FONT_SIZE);
512 }
513
514
515
516 wxHtmlEasyPrinting::~wxHtmlEasyPrinting()
517 {
518 delete m_PrintData;
519 delete m_PageSetupData;
520 }
521
522
523 wxPrintData *wxHtmlEasyPrinting::GetPrintData()
524 {
525 if (m_PrintData == NULL)
526 m_PrintData = new wxPrintData();
527 return m_PrintData;
528 }
529
530
531 bool wxHtmlEasyPrinting::PreviewFile(const wxString &htmlfile)
532 {
533 wxHtmlPrintout *p1 = CreatePrintout();
534 p1->SetHtmlFile(htmlfile);
535 wxHtmlPrintout *p2 = CreatePrintout();
536 p2->SetHtmlFile(htmlfile);
537 return DoPreview(p1, p2);
538 }
539
540
541
542 bool wxHtmlEasyPrinting::PreviewText(const wxString &htmltext, const wxString &basepath)
543 {
544 wxHtmlPrintout *p1 = CreatePrintout();
545 p1->SetHtmlText(htmltext, basepath, true);
546 wxHtmlPrintout *p2 = CreatePrintout();
547 p2->SetHtmlText(htmltext, basepath, true);
548 return DoPreview(p1, p2);
549 }
550
551
552
553 bool wxHtmlEasyPrinting::PrintFile(const wxString &htmlfile)
554 {
555 wxHtmlPrintout *p = CreatePrintout();
556 p->SetHtmlFile(htmlfile);
557 bool ret = DoPrint(p);
558 delete p;
559 return ret;
560 }
561
562
563
564 bool wxHtmlEasyPrinting::PrintText(const wxString &htmltext, const wxString &basepath)
565 {
566 wxHtmlPrintout *p = CreatePrintout();
567 p->SetHtmlText(htmltext, basepath, true);
568 bool ret = DoPrint(p);
569 delete p;
570 return ret;
571 }
572
573
574
575 bool wxHtmlEasyPrinting::DoPreview(wxHtmlPrintout *printout1, wxHtmlPrintout *printout2)
576 {
577 // Pass two printout objects: for preview, and possible printing.
578 wxPrintDialogData printDialogData(*GetPrintData());
579 wxPrintPreview *preview = new wxPrintPreview(printout1, printout2, &printDialogData);
580 if (!preview->Ok())
581 {
582 delete preview;
583 return false;
584 }
585
586 wxPreviewFrame *frame = new wxPreviewFrame(preview, m_ParentWindow,
587 m_Name + _(" Preview"),
588 wxPoint(100, 100), wxSize(650, 500));
589 frame->Centre(wxBOTH);
590 frame->Initialize();
591 frame->Show(true);
592 return true;
593 }
594
595
596
597 bool wxHtmlEasyPrinting::DoPrint(wxHtmlPrintout *printout)
598 {
599 wxPrintDialogData printDialogData(*GetPrintData());
600 wxPrinter printer(&printDialogData);
601
602 if (!printer.Print(m_ParentWindow, printout, true))
603 {
604 return false;
605 }
606
607 (*GetPrintData()) = printer.GetPrintDialogData().GetPrintData();
608 return true;
609 }
610
611
612
613
614 void wxHtmlEasyPrinting::PageSetup()
615 {
616 if (!GetPrintData()->Ok())
617 {
618 wxLogError(_("There was a problem during page setup: you may need to set a default printer."));
619 return;
620 }
621
622 m_PageSetupData->SetPrintData(*GetPrintData());
623 wxPageSetupDialog pageSetupDialog(m_ParentWindow, m_PageSetupData);
624
625 if (pageSetupDialog.ShowModal() == wxID_OK)
626 {
627 (*GetPrintData()) = pageSetupDialog.GetPageSetupData().GetPrintData();
628 (*m_PageSetupData) = pageSetupDialog.GetPageSetupData();
629 }
630 }
631
632
633
634 void wxHtmlEasyPrinting::SetHeader(const wxString& header, int pg)
635 {
636 if (pg == wxPAGE_ALL || pg == wxPAGE_EVEN)
637 m_Headers[0] = header;
638 if (pg == wxPAGE_ALL || pg == wxPAGE_ODD)
639 m_Headers[1] = header;
640 }
641
642
643
644 void wxHtmlEasyPrinting::SetFooter(const wxString& footer, int pg)
645 {
646 if (pg == wxPAGE_ALL || pg == wxPAGE_EVEN)
647 m_Footers[0] = footer;
648 if (pg == wxPAGE_ALL || pg == wxPAGE_ODD)
649 m_Footers[1] = footer;
650 }
651
652
653 void wxHtmlEasyPrinting::SetFonts(const wxString& normal_face, const wxString& fixed_face,
654 const int *sizes)
655 {
656 m_fontMode = FontMode_Explicit;
657 m_FontFaceNormal = normal_face;
658 m_FontFaceFixed = fixed_face;
659
660 if (sizes)
661 {
662 m_FontsSizes = m_FontsSizesArr;
663 for (int i = 0; i < 7; i++) m_FontsSizes[i] = sizes[i];
664 }
665 else
666 m_FontsSizes = NULL;
667 }
668
669 void wxHtmlEasyPrinting::SetStandardFonts(int size,
670 const wxString& normal_face,
671 const wxString& fixed_face)
672 {
673 m_fontMode = FontMode_Standard;
674 m_FontFaceNormal = normal_face;
675 m_FontFaceFixed = fixed_face;
676 m_FontsSizesArr[0] = size;
677 }
678
679
680 wxHtmlPrintout *wxHtmlEasyPrinting::CreatePrintout()
681 {
682 wxHtmlPrintout *p = new wxHtmlPrintout(m_Name);
683
684 if (m_fontMode == FontMode_Explicit)
685 {
686 p->SetFonts(m_FontFaceNormal, m_FontFaceFixed, m_FontsSizes);
687 }
688 else // FontMode_Standard
689 {
690 p->SetStandardFonts(m_FontsSizesArr[0],
691 m_FontFaceNormal, m_FontFaceFixed);
692 }
693
694 p->SetHeader(m_Headers[0], wxPAGE_EVEN);
695 p->SetHeader(m_Headers[1], wxPAGE_ODD);
696 p->SetFooter(m_Footers[0], wxPAGE_EVEN);
697 p->SetFooter(m_Footers[1], wxPAGE_ODD);
698
699 p->SetMargins(m_PageSetupData->GetMarginTopLeft().y,
700 m_PageSetupData->GetMarginBottomRight().y,
701 m_PageSetupData->GetMarginTopLeft().x,
702 m_PageSetupData->GetMarginBottomRight().x);
703
704 return p;
705 }
706
707 // A module to allow initialization/cleanup
708 // without calling these functions from app.cpp or from
709 // the user's application.
710
711 class wxHtmlPrintingModule: public wxModule
712 {
713 DECLARE_DYNAMIC_CLASS(wxHtmlPrintingModule)
714 public:
715 wxHtmlPrintingModule() : wxModule() {}
716 bool OnInit() { return true; }
717 void OnExit() { wxHtmlPrintout::CleanUpStatics(); }
718 };
719
720 IMPLEMENT_DYNAMIC_CLASS(wxHtmlPrintingModule, wxModule)
721
722
723 // This hack forces the linker to always link in m_* files
724 // (wxHTML doesn't work without handlers from these files)
725 #include "wx/html/forcelnk.h"
726 FORCE_WXHTML_MODULES()
727
728 #endif // wxUSE_HTML & wxUSE_PRINTING_ARCHITECTURE