1 /////////////////////////////////////////////////////////////////////////////
2 // Name: src/html/htmprint.cpp
3 // Purpose: html printing classes
4 // Author: Vaclav Slavik
6 // Copyright: (c) Vaclav Slavik, 1999
7 // Licence: wxWindows licence
8 /////////////////////////////////////////////////////////////////////////////
10 // For compilers that support precompilation, includes "wx/wx.h".
11 #include "wx/wxprec.h"
17 #if wxUSE_HTML && wxUSE_PRINTING_ARCHITECTURE && wxUSE_STREAMS
23 #include "wx/settings.h"
24 #include "wx/msgdlg.h"
25 #include "wx/module.h"
30 #include "wx/printdlg.h"
31 #include "wx/html/htmprint.h"
32 #include "wx/wxhtml.h"
33 #include "wx/wfstream.h"
34 #include "wx/infobar.h"
37 // default font size of normal text (HTML font size 0) for printing, in points:
38 #define DEFAULT_PRINT_FONT_SIZE 12
41 // CSS specification offer following guidance on dealing with pixel sizes
43 // http://www.w3.org/TR/2004/CR-CSS21-20040225/syndata.html#length-units:
45 // Pixel units are relative to the resolution of the viewing device, i.e.,
46 // most often a computer display. If the pixel density of the output
47 // device is very different from that of a typical computer display, the
48 // user agent should rescale pixel values. It is recommended that the [
49 // reference pixel] be the visual angle of one pixel on a device with a
50 // pixel density of 96dpi and a distance from the reader of an arm's
51 // length. For a nominal arm's length of 28 inches, the visual angle is
52 // therefore about 0.0213 degrees.
54 // For reading at arm's length, 1px thus corresponds to about 0.26 mm
55 // (1/96 inch). When printed on a laser printer, meant for reading at a
56 // little less than arm's length (55 cm, 21 inches), 1px is about 0.20 mm.
57 // On a 300 dots-per-inch (dpi) printer, that may be rounded up to 3 dots
58 // (0.25 mm); on a 600 dpi printer, it can be rounded to 5 dots.
60 // See also http://trac.wxwidgets.org/ticket/10942.
61 #define TYPICAL_SCREEN_DPI 96.0
63 //--------------------------------------------------------------------------------
65 //--------------------------------------------------------------------------------
68 wxHtmlDCRenderer::wxHtmlDCRenderer() : wxObject()
71 m_Width
= m_Height
= 0;
73 m_Parser
= new wxHtmlWinParser();
74 m_FS
= new wxFileSystem();
75 m_Parser
->SetFS(m_FS
);
76 SetStandardFonts(DEFAULT_PRINT_FONT_SIZE
);
81 wxHtmlDCRenderer::~wxHtmlDCRenderer()
83 if (m_Cells
) delete m_Cells
;
84 if (m_Parser
) delete m_Parser
;
85 if (m_FS
) delete m_FS
;
90 void wxHtmlDCRenderer::SetDC(wxDC
*dc
, double pixel_scale
, double font_scale
)
93 m_Parser
->SetDC(m_DC
, pixel_scale
, font_scale
);
98 void wxHtmlDCRenderer::SetSize(int width
, int height
)
100 wxCHECK_RET( width
, "width must be non-zero" );
101 wxCHECK_RET( height
, "height must be non-zero" );
108 void wxHtmlDCRenderer::SetHtmlText(const wxString
& html
, const wxString
& basepath
, bool isdir
)
110 wxCHECK_RET( m_DC
, "SetDC() must be called before SetHtmlText()" );
111 wxCHECK_RET( m_Width
, "SetSize() must be called before SetHtmlText()" );
115 m_FS
->ChangePathTo(basepath
, isdir
);
116 m_Cells
= (wxHtmlContainerCell
*) m_Parser
->Parse(html
);
117 m_Cells
->SetIndent(0, wxHTML_INDENT_ALL
, wxHTML_UNITS_PIXELS
);
118 m_Cells
->Layout(m_Width
);
122 void wxHtmlDCRenderer::SetFonts(const wxString
& normal_face
, const wxString
& fixed_face
,
125 m_Parser
->SetFonts(normal_face
, fixed_face
, sizes
);
128 m_Cells
->Layout(m_Width
);
129 // else: SetHtmlText() not yet called, no need for relayout
132 void wxHtmlDCRenderer::SetStandardFonts(int size
,
133 const wxString
& normal_face
,
134 const wxString
& fixed_face
)
136 m_Parser
->SetStandardFonts(size
, normal_face
, fixed_face
);
139 m_Cells
->Layout(m_Width
);
140 // else: SetHtmlText() not yet called, no need for relayout
143 int wxHtmlDCRenderer::Render(int x
, int y
,
144 wxArrayInt
& known_pagebreaks
,
145 int from
, int dont_render
, int to
)
147 wxCHECK_MSG( m_Cells
, 0, "SetHtmlText() must be called before Render()" );
148 wxCHECK_MSG( m_DC
, 0, "SetDC() must be called before Render()" );
152 pbreak
= (int)(from
+ m_Height
);
153 while (m_Cells
->AdjustPagebreak(&pbreak
, known_pagebreaks
, m_Height
)) {}
154 hght
= pbreak
- from
;
160 wxHtmlRenderingInfo rinfo
;
161 wxDefaultHtmlRenderingStyle rstyle
;
162 rinfo
.SetStyle(&rstyle
);
163 m_DC
->SetBrush(*wxWHITE_BRUSH
);
164 m_DC
->SetClippingRegion(x
, y
, m_Width
, hght
);
169 m_DC
->DestroyClippingRegion();
172 if (pbreak
< m_Cells
->GetHeight()) return pbreak
;
173 else return GetTotalHeight();
176 int wxHtmlDCRenderer::GetTotalWidth() const
178 return m_Cells
? m_Cells
->GetWidth() : 0;
181 int wxHtmlDCRenderer::GetTotalHeight() const
183 return m_Cells
? m_Cells
->GetHeight() : 0;
187 //--------------------------------------------------------------------------------
189 //--------------------------------------------------------------------------------
192 wxList
wxHtmlPrintout::m_Filters
;
194 wxHtmlPrintout::wxHtmlPrintout(const wxString
& title
) : wxPrintout(title
)
196 m_Renderer
= new wxHtmlDCRenderer
;
197 m_RendererHdr
= new wxHtmlDCRenderer
;
198 m_NumPages
= INT_MAX
;
199 m_Document
= m_BasePath
= wxEmptyString
; m_BasePathIsDir
= true;
200 m_Headers
[0] = m_Headers
[1] = wxEmptyString
;
201 m_Footers
[0] = m_Footers
[1] = wxEmptyString
;
202 m_HeaderHeight
= m_FooterHeight
= 0;
203 SetMargins(); // to default values
204 SetStandardFonts(DEFAULT_PRINT_FONT_SIZE
);
209 wxHtmlPrintout::~wxHtmlPrintout()
212 delete m_RendererHdr
;
215 void wxHtmlPrintout::CleanUpStatics()
217 WX_CLEAR_LIST(wxList
, m_Filters
);
221 void wxHtmlPrintout::AddFilter(wxHtmlFilter
*filter
)
223 m_Filters
.Append(filter
);
227 wxHtmlPrintout::CheckFit(const wxSize
& pageArea
, const wxSize
& docArea
) const
229 // Nothing to do if the contents fits horizontally.
230 if ( docArea
.x
<= pageArea
.x
)
233 // Otherwise warn the user more or less intrusively depending on whether
234 // we're previewing or printing:
235 if ( wxPrintPreview
* const preview
= GetPreview() )
237 // Don't annoy the user too much when previewing by using info bar
238 // instead of a dialog box.
240 wxFrame
* const parent
= preview
->GetFrame();
241 wxCHECK_MSG( parent
, false, "No parent preview frame?" );
243 wxSizer
* const sizer
= parent
->GetSizer();
244 wxCHECK_MSG( sizer
, false, "Preview frame should be using sizers" );
246 wxInfoBar
* const bar
= new wxInfoBar(parent
);
247 sizer
->Add(bar
, wxSizerFlags().Expand());
249 // Note that the message here is similar to the one below but not
250 // exactly the same, notably we don't use the document title here
251 // because it's already clear which document it pertains to and the
252 // title may be long enough to make the text not fit in the window.
255 _("This document doesn't fit on the page horizontally and "
256 "will be truncated when it is printed."),
259 #endif // wxUSE_INFOBAR
261 else // We're going to really print and not just preview.
263 // This is our last chance to warn the user that the output will be
264 // mangled so do show a message box.
271 _("The document \"%s\" doesn't fit on the page "
272 "horizontally and will be truncated if printed.\n"
274 "Would you like to proceed with printing it nevertheless?"),
278 wxOK
| wxCANCEL
| wxCANCEL_DEFAULT
| wxICON_QUESTION
280 dlg
.SetExtendedMessage
282 _("If possible, try changing the layout parameters to "
283 "make the printout more narrow.")
285 dlg
.SetOKLabel(wxID_PRINT
);
287 if ( dlg
.ShowModal() == wxID_CANCEL
)
294 void wxHtmlPrintout::OnPreparePrinting()
296 int pageWidth
, pageHeight
, mm_w
, mm_h
, dc_w
, dc_h
;
297 float ppmm_h
, ppmm_v
;
299 GetPageSizePixels(&pageWidth
, &pageHeight
);
300 GetPageSizeMM(&mm_w
, &mm_h
);
301 ppmm_h
= (float)pageWidth
/ mm_w
;
302 ppmm_v
= (float)pageHeight
/ mm_h
;
304 int ppiPrinterX
, ppiPrinterY
;
305 GetPPIPrinter(&ppiPrinterX
, &ppiPrinterY
);
306 wxUnusedVar(ppiPrinterX
);
307 int ppiScreenX
, ppiScreenY
;
308 GetPPIScreen(&ppiScreenX
, &ppiScreenY
);
309 wxUnusedVar(ppiScreenX
);
311 GetDC()->GetSize(&dc_w
, &dc_h
);
313 GetDC()->SetUserScale((double)dc_w
/ (double)pageWidth
,
314 (double)dc_h
/ (double)pageHeight
);
316 /* prepare headers/footers renderer: */
318 m_RendererHdr
->SetDC(GetDC(),
319 (double)ppiPrinterY
/ TYPICAL_SCREEN_DPI
,
320 (double)ppiPrinterY
/ (double)ppiScreenY
);
321 m_RendererHdr
->SetSize((int) (ppmm_h
* (mm_w
- m_MarginLeft
- m_MarginRight
)),
322 (int) (ppmm_v
* (mm_h
- m_MarginTop
- m_MarginBottom
)));
323 if (m_Headers
[0] != wxEmptyString
)
325 m_RendererHdr
->SetHtmlText(TranslateHeader(m_Headers
[0], 1));
326 m_HeaderHeight
= m_RendererHdr
->GetTotalHeight();
328 else if (m_Headers
[1] != wxEmptyString
)
330 m_RendererHdr
->SetHtmlText(TranslateHeader(m_Headers
[1], 1));
331 m_HeaderHeight
= m_RendererHdr
->GetTotalHeight();
333 if (m_Footers
[0] != wxEmptyString
)
335 m_RendererHdr
->SetHtmlText(TranslateHeader(m_Footers
[0], 1));
336 m_FooterHeight
= m_RendererHdr
->GetTotalHeight();
338 else if (m_Footers
[1] != wxEmptyString
)
340 m_RendererHdr
->SetHtmlText(TranslateHeader(m_Footers
[1], 1));
341 m_FooterHeight
= m_RendererHdr
->GetTotalHeight();
344 /* prepare main renderer: */
345 m_Renderer
->SetDC(GetDC(),
346 (double)ppiPrinterY
/ TYPICAL_SCREEN_DPI
,
347 (double)ppiPrinterY
/ (double)ppiScreenY
);
349 const int printAreaW
= int(ppmm_h
* (mm_w
- m_MarginLeft
- m_MarginRight
));
350 int printAreaH
= int(ppmm_v
* (mm_h
- m_MarginTop
- m_MarginBottom
));
351 if ( m_HeaderHeight
)
352 printAreaH
-= int(m_HeaderHeight
+ m_MarginSpace
* ppmm_v
);
353 if ( m_FooterHeight
)
354 printAreaH
-= int(m_FooterHeight
+ m_MarginSpace
* ppmm_v
);
356 m_Renderer
->SetSize(printAreaW
, printAreaH
);
357 m_Renderer
->SetHtmlText(m_Document
, m_BasePath
, m_BasePathIsDir
);
359 if ( CheckFit(wxSize(printAreaW
, printAreaH
),
360 wxSize(m_Renderer
->GetTotalWidth(),
361 m_Renderer
->GetTotalHeight())) || IsPreview() )
363 // do paginate the document
366 //else: if we don't call CountPages() m_PageBreaks remains empty and our
367 // GetPageInfo() will return 0 as max page and so nothing will be
371 bool wxHtmlPrintout::OnBeginDocument(int startPage
, int endPage
)
373 if (!wxPrintout::OnBeginDocument(startPage
, endPage
)) return false;
379 bool wxHtmlPrintout::OnPrintPage(int page
)
382 if (dc
&& dc
->IsOk())
385 RenderPage(dc
, page
);
392 void wxHtmlPrintout::GetPageInfo(int *minPage
, int *maxPage
, int *selPageFrom
, int *selPageTo
)
395 if ( m_NumPages
>= (signed)m_PageBreaks
.GetCount()-1)
396 *maxPage
= m_NumPages
;
398 *maxPage
= (signed)m_PageBreaks
.GetCount()-1;
400 *selPageTo
= (signed)m_PageBreaks
.GetCount()-1;
405 bool wxHtmlPrintout::HasPage(int pageNum
)
407 return pageNum
> 0 && (unsigned)pageNum
< m_PageBreaks
.GetCount();
412 void wxHtmlPrintout::SetHtmlText(const wxString
& html
, const wxString
&basepath
, bool isdir
)
415 m_BasePath
= basepath
;
416 m_BasePathIsDir
= isdir
;
419 void wxHtmlPrintout::SetHtmlFile(const wxString
& htmlfile
)
424 if (wxFileExists(htmlfile
))
425 ff
= fs
.OpenFile(wxFileSystem::FileNameToURL(htmlfile
));
427 ff
= fs
.OpenFile(htmlfile
);
431 wxLogError(htmlfile
+ _(": file does not exist!"));
436 wxHtmlFilterHTML defaultFilter
;
439 wxList::compatibility_iterator node
= m_Filters
.GetFirst();
442 wxHtmlFilter
*h
= (wxHtmlFilter
*) node
->GetData();
445 doc
= h
->ReadFile(*ff
);
449 node
= node
->GetNext();
453 doc
= defaultFilter
.ReadFile(*ff
);
455 SetHtmlText(doc
, htmlfile
, false);
461 void wxHtmlPrintout::SetHeader(const wxString
& header
, int pg
)
463 if (pg
== wxPAGE_ALL
|| pg
== wxPAGE_EVEN
)
464 m_Headers
[0] = header
;
465 if (pg
== wxPAGE_ALL
|| pg
== wxPAGE_ODD
)
466 m_Headers
[1] = header
;
471 void wxHtmlPrintout::SetFooter(const wxString
& footer
, int pg
)
473 if (pg
== wxPAGE_ALL
|| pg
== wxPAGE_EVEN
)
474 m_Footers
[0] = footer
;
475 if (pg
== wxPAGE_ALL
|| pg
== wxPAGE_ODD
)
476 m_Footers
[1] = footer
;
481 void wxHtmlPrintout::CountPages()
484 int pageWidth
, pageHeight
, mm_w
, mm_h
;
485 float ppmm_h
, ppmm_v
;
487 GetPageSizePixels(&pageWidth
, &pageHeight
);
488 GetPageSizeMM(&mm_w
, &mm_h
);
489 ppmm_h
= (float)pageWidth
/ mm_w
;
490 ppmm_v
= (float)pageHeight
/ mm_h
;
495 m_PageBreaks
.Clear();
496 m_PageBreaks
.Add( 0);
499 pos
= m_Renderer
->Render((int)( ppmm_h
* m_MarginLeft
),
500 (int) (ppmm_v
* (m_MarginTop
+ (m_HeaderHeight
== 0 ? 0 : m_MarginSpace
)) + m_HeaderHeight
),
503 m_PageBreaks
.Add( pos
);
504 } while (pos
< m_Renderer
->GetTotalHeight());
509 void wxHtmlPrintout::RenderPage(wxDC
*dc
, int page
)
513 int pageWidth
, pageHeight
, mm_w
, mm_h
, dc_w
, dc_h
;
514 float ppmm_h
, ppmm_v
;
516 GetPageSizePixels(&pageWidth
, &pageHeight
);
517 GetPageSizeMM(&mm_w
, &mm_h
);
518 ppmm_h
= (float)pageWidth
/ mm_w
;
519 ppmm_v
= (float)pageHeight
/ mm_h
;
520 dc
->GetSize(&dc_w
, &dc_h
);
522 int ppiPrinterX
, ppiPrinterY
;
523 GetPPIPrinter(&ppiPrinterX
, &ppiPrinterY
);
524 wxUnusedVar(ppiPrinterX
);
525 int ppiScreenX
, ppiScreenY
;
526 GetPPIScreen(&ppiScreenX
, &ppiScreenY
);
527 wxUnusedVar(ppiScreenX
);
529 dc
->SetUserScale((double)dc_w
/ (double)pageWidth
,
530 (double)dc_h
/ (double)pageHeight
);
532 m_Renderer
->SetDC(dc
,
533 (double)ppiPrinterY
/ TYPICAL_SCREEN_DPI
,
534 (double)ppiPrinterY
/ (double)ppiScreenY
);
536 dc
->SetBackgroundMode(wxTRANSPARENT
);
538 m_Renderer
->Render((int) (ppmm_h
* m_MarginLeft
),
539 (int) (ppmm_v
* (m_MarginTop
+ (m_HeaderHeight
== 0 ? 0 : m_MarginSpace
)) + m_HeaderHeight
), m_PageBreaks
,
540 m_PageBreaks
[page
-1], false, m_PageBreaks
[page
]-m_PageBreaks
[page
-1]);
543 m_RendererHdr
->SetDC(dc
,
544 (double)ppiPrinterY
/ TYPICAL_SCREEN_DPI
,
545 (double)ppiPrinterY
/ (double)ppiScreenY
);
546 if (m_Headers
[page
% 2] != wxEmptyString
)
548 m_RendererHdr
->SetHtmlText(TranslateHeader(m_Headers
[page
% 2], page
));
549 m_RendererHdr
->Render((int) (ppmm_h
* m_MarginLeft
), (int) (ppmm_v
* m_MarginTop
), m_PageBreaks
);
551 if (m_Footers
[page
% 2] != wxEmptyString
)
553 m_RendererHdr
->SetHtmlText(TranslateHeader(m_Footers
[page
% 2], page
));
554 m_RendererHdr
->Render((int) (ppmm_h
* m_MarginLeft
), (int) (pageHeight
- ppmm_v
* m_MarginBottom
- m_FooterHeight
), m_PageBreaks
);
560 wxString
wxHtmlPrintout::TranslateHeader(const wxString
& instr
, int page
)
565 num
.Printf(wxT("%i"), page
);
566 r
.Replace(wxT("@PAGENUM@"), num
);
568 num
.Printf(wxT("%lu"), (unsigned long)(m_PageBreaks
.GetCount() - 1));
569 r
.Replace(wxT("@PAGESCNT@"), num
);
571 const wxDateTime now
= wxDateTime::Now();
572 r
.Replace(wxT("@DATE@"), now
.FormatDate());
573 r
.Replace(wxT("@TIME@"), now
.FormatTime());
575 r
.Replace(wxT("@TITLE@"), GetTitle());
582 void wxHtmlPrintout::SetMargins(float top
, float bottom
, float left
, float right
, float spaces
)
585 m_MarginBottom
= bottom
;
587 m_MarginRight
= right
;
588 m_MarginSpace
= spaces
;
594 void wxHtmlPrintout::SetFonts(const wxString
& normal_face
, const wxString
& fixed_face
,
597 m_Renderer
->SetFonts(normal_face
, fixed_face
, sizes
);
598 m_RendererHdr
->SetFonts(normal_face
, fixed_face
, sizes
);
601 void wxHtmlPrintout::SetStandardFonts(int size
,
602 const wxString
& normal_face
,
603 const wxString
& fixed_face
)
605 m_Renderer
->SetStandardFonts(size
, normal_face
, fixed_face
);
606 m_RendererHdr
->SetStandardFonts(size
, normal_face
, fixed_face
);
611 //----------------------------------------------------------------------------
612 // wxHtmlEasyPrinting
613 //----------------------------------------------------------------------------
616 wxHtmlEasyPrinting::wxHtmlEasyPrinting(const wxString
& name
, wxWindow
*parentWindow
)
618 m_ParentWindow
= parentWindow
;
621 m_PageSetupData
= new wxPageSetupDialogData
;
622 m_Headers
[0] = m_Headers
[1] = m_Footers
[0] = m_Footers
[1] = wxEmptyString
;
624 m_PageSetupData
->EnableMargins(true);
625 m_PageSetupData
->SetMarginTopLeft(wxPoint(25, 25));
626 m_PageSetupData
->SetMarginBottomRight(wxPoint(25, 25));
628 SetStandardFonts(DEFAULT_PRINT_FONT_SIZE
);
633 wxHtmlEasyPrinting::~wxHtmlEasyPrinting()
636 delete m_PageSetupData
;
640 wxPrintData
*wxHtmlEasyPrinting::GetPrintData()
642 if (m_PrintData
== NULL
)
643 m_PrintData
= new wxPrintData();
648 bool wxHtmlEasyPrinting::PreviewFile(const wxString
&htmlfile
)
650 wxHtmlPrintout
*p1
= CreatePrintout();
651 p1
->SetHtmlFile(htmlfile
);
652 wxHtmlPrintout
*p2
= CreatePrintout();
653 p2
->SetHtmlFile(htmlfile
);
654 return DoPreview(p1
, p2
);
659 bool wxHtmlEasyPrinting::PreviewText(const wxString
&htmltext
, const wxString
&basepath
)
661 wxHtmlPrintout
*p1
= CreatePrintout();
662 p1
->SetHtmlText(htmltext
, basepath
, true);
663 wxHtmlPrintout
*p2
= CreatePrintout();
664 p2
->SetHtmlText(htmltext
, basepath
, true);
665 return DoPreview(p1
, p2
);
670 bool wxHtmlEasyPrinting::PrintFile(const wxString
&htmlfile
)
672 wxHtmlPrintout
*p
= CreatePrintout();
673 p
->SetHtmlFile(htmlfile
);
674 bool ret
= DoPrint(p
);
681 bool wxHtmlEasyPrinting::PrintText(const wxString
&htmltext
, const wxString
&basepath
)
683 wxHtmlPrintout
*p
= CreatePrintout();
684 p
->SetHtmlText(htmltext
, basepath
, true);
685 bool ret
= DoPrint(p
);
692 bool wxHtmlEasyPrinting::DoPreview(wxHtmlPrintout
*printout1
, wxHtmlPrintout
*printout2
)
694 // Pass two printout objects: for preview, and possible printing.
695 wxPrintDialogData
printDialogData(*GetPrintData());
696 wxPrintPreview
*preview
= new wxPrintPreview(printout1
, printout2
, &printDialogData
);
697 if (!preview
->IsOk())
703 wxPreviewFrame
*frame
= new wxPreviewFrame(preview
, m_ParentWindow
,
704 m_Name
+ _(" Preview"),
705 wxPoint(100, 100), wxSize(650, 500));
706 frame
->Centre(wxBOTH
);
714 bool wxHtmlEasyPrinting::DoPrint(wxHtmlPrintout
*printout
)
716 wxPrintDialogData
printDialogData(*GetPrintData());
717 wxPrinter
printer(&printDialogData
);
719 if (!printer
.Print(m_ParentWindow
, printout
, true))
724 (*GetPrintData()) = printer
.GetPrintDialogData().GetPrintData();
731 void wxHtmlEasyPrinting::PageSetup()
733 if (!GetPrintData()->IsOk())
735 wxLogError(_("There was a problem during page setup: you may need to set a default printer."));
739 m_PageSetupData
->SetPrintData(*GetPrintData());
740 wxPageSetupDialog
pageSetupDialog(m_ParentWindow
, m_PageSetupData
);
742 if (pageSetupDialog
.ShowModal() == wxID_OK
)
744 (*GetPrintData()) = pageSetupDialog
.GetPageSetupData().GetPrintData();
745 (*m_PageSetupData
) = pageSetupDialog
.GetPageSetupData();
751 void wxHtmlEasyPrinting::SetHeader(const wxString
& header
, int pg
)
753 if (pg
== wxPAGE_ALL
|| pg
== wxPAGE_EVEN
)
754 m_Headers
[0] = header
;
755 if (pg
== wxPAGE_ALL
|| pg
== wxPAGE_ODD
)
756 m_Headers
[1] = header
;
761 void wxHtmlEasyPrinting::SetFooter(const wxString
& footer
, int pg
)
763 if (pg
== wxPAGE_ALL
|| pg
== wxPAGE_EVEN
)
764 m_Footers
[0] = footer
;
765 if (pg
== wxPAGE_ALL
|| pg
== wxPAGE_ODD
)
766 m_Footers
[1] = footer
;
770 void wxHtmlEasyPrinting::SetFonts(const wxString
& normal_face
, const wxString
& fixed_face
,
773 m_fontMode
= FontMode_Explicit
;
774 m_FontFaceNormal
= normal_face
;
775 m_FontFaceFixed
= fixed_face
;
779 m_FontsSizes
= m_FontsSizesArr
;
780 for (int i
= 0; i
< 7; i
++) m_FontsSizes
[i
] = sizes
[i
];
786 void wxHtmlEasyPrinting::SetStandardFonts(int size
,
787 const wxString
& normal_face
,
788 const wxString
& fixed_face
)
790 m_fontMode
= FontMode_Standard
;
791 m_FontFaceNormal
= normal_face
;
792 m_FontFaceFixed
= fixed_face
;
793 m_FontsSizesArr
[0] = size
;
797 wxHtmlPrintout
*wxHtmlEasyPrinting::CreatePrintout()
799 wxHtmlPrintout
*p
= new wxHtmlPrintout(m_Name
);
801 if (m_fontMode
== FontMode_Explicit
)
803 p
->SetFonts(m_FontFaceNormal
, m_FontFaceFixed
, m_FontsSizes
);
805 else // FontMode_Standard
807 p
->SetStandardFonts(m_FontsSizesArr
[0],
808 m_FontFaceNormal
, m_FontFaceFixed
);
811 p
->SetHeader(m_Headers
[0], wxPAGE_EVEN
);
812 p
->SetHeader(m_Headers
[1], wxPAGE_ODD
);
813 p
->SetFooter(m_Footers
[0], wxPAGE_EVEN
);
814 p
->SetFooter(m_Footers
[1], wxPAGE_ODD
);
816 p
->SetMargins(m_PageSetupData
->GetMarginTopLeft().y
,
817 m_PageSetupData
->GetMarginBottomRight().y
,
818 m_PageSetupData
->GetMarginTopLeft().x
,
819 m_PageSetupData
->GetMarginBottomRight().x
);
824 // A module to allow initialization/cleanup
825 // without calling these functions from app.cpp or from
826 // the user's application.
828 class wxHtmlPrintingModule
: public wxModule
830 DECLARE_DYNAMIC_CLASS(wxHtmlPrintingModule
)
832 wxHtmlPrintingModule() : wxModule() {}
833 bool OnInit() { return true; }
834 void OnExit() { wxHtmlPrintout::CleanUpStatics(); }
837 IMPLEMENT_DYNAMIC_CLASS(wxHtmlPrintingModule
, wxModule
)
840 // This hack forces the linker to always link in m_* files
841 // (wxHTML doesn't work without handlers from these files)
842 #include "wx/html/forcelnk.h"
843 FORCE_WXHTML_MODULES()
845 #endif // wxUSE_HTML & wxUSE_PRINTING_ARCHITECTURE