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