1 /////////////////////////////////////////////////////////////////////////////
2 // Name: src/html/htmprint.cpp
3 // Purpose: html printing classes
4 // Author: Vaclav Slavik
7 // Copyright: (c) Vaclav Slavik, 1999
8 // Licence: wxWindows licence
9 /////////////////////////////////////////////////////////////////////////////
11 // For compilers that support precompilation, includes "wx/wx.h".
12 #include "wx/wxprec.h"
18 #if wxUSE_HTML && wxUSE_PRINTING_ARCHITECTURE && wxUSE_STREAMS
24 #include "wx/settings.h"
25 #include "wx/msgdlg.h"
26 #include "wx/module.h"
31 #include "wx/printdlg.h"
32 #include "wx/html/htmprint.h"
33 #include "wx/wxhtml.h"
34 #include "wx/wfstream.h"
35 #include "wx/infobar.h"
38 // default font size of normal text (HTML font size 0) for printing, in points:
39 #define DEFAULT_PRINT_FONT_SIZE 12
42 // CSS specification offer following guidance on dealing with pixel sizes
44 // http://www.w3.org/TR/2004/CR-CSS21-20040225/syndata.html#length-units:
46 // Pixel units are relative to the resolution of the viewing device, i.e.,
47 // most often a computer display. If the pixel density of the output
48 // device is very different from that of a typical computer display, the
49 // user agent should rescale pixel values. It is recommended that the [
50 // reference pixel] be the visual angle of one pixel on a device with a
51 // pixel density of 96dpi and a distance from the reader of an arm's
52 // length. For a nominal arm's length of 28 inches, the visual angle is
53 // therefore about 0.0213 degrees.
55 // For reading at arm's length, 1px thus corresponds to about 0.26 mm
56 // (1/96 inch). When printed on a laser printer, meant for reading at a
57 // little less than arm's length (55 cm, 21 inches), 1px is about 0.20 mm.
58 // On a 300 dots-per-inch (dpi) printer, that may be rounded up to 3 dots
59 // (0.25 mm); on a 600 dpi printer, it can be rounded to 5 dots.
61 // See also http://trac.wxwidgets.org/ticket/10942.
62 #define TYPICAL_SCREEN_DPI 96.0
64 //--------------------------------------------------------------------------------
66 //--------------------------------------------------------------------------------
69 wxHtmlDCRenderer::wxHtmlDCRenderer() : wxObject()
72 m_Width
= m_Height
= 0;
74 m_Parser
= new wxHtmlWinParser();
75 m_FS
= new wxFileSystem();
76 m_Parser
->SetFS(m_FS
);
77 SetStandardFonts(DEFAULT_PRINT_FONT_SIZE
);
82 wxHtmlDCRenderer::~wxHtmlDCRenderer()
84 if (m_Cells
) delete m_Cells
;
85 if (m_Parser
) delete m_Parser
;
86 if (m_FS
) delete m_FS
;
91 void wxHtmlDCRenderer::SetDC(wxDC
*dc
, double pixel_scale
, double font_scale
)
94 m_Parser
->SetDC(m_DC
, pixel_scale
, font_scale
);
99 void wxHtmlDCRenderer::SetSize(int width
, int height
)
101 wxCHECK_RET( width
, "width must be non-zero" );
102 wxCHECK_RET( height
, "height must be non-zero" );
109 void wxHtmlDCRenderer::SetHtmlText(const wxString
& html
, const wxString
& basepath
, bool isdir
)
111 wxCHECK_RET( m_DC
, "SetDC() must be called before SetHtmlText()" );
112 wxCHECK_RET( m_Width
, "SetSize() must be called before SetHtmlText()" );
116 m_FS
->ChangePathTo(basepath
, isdir
);
117 m_Cells
= (wxHtmlContainerCell
*) m_Parser
->Parse(html
);
118 m_Cells
->SetIndent(0, wxHTML_INDENT_ALL
, wxHTML_UNITS_PIXELS
);
119 m_Cells
->Layout(m_Width
);
123 void wxHtmlDCRenderer::SetFonts(const wxString
& normal_face
, const wxString
& fixed_face
,
126 m_Parser
->SetFonts(normal_face
, fixed_face
, sizes
);
129 m_Cells
->Layout(m_Width
);
130 // else: SetHtmlText() not yet called, no need for relayout
133 void wxHtmlDCRenderer::SetStandardFonts(int size
,
134 const wxString
& normal_face
,
135 const wxString
& fixed_face
)
137 m_Parser
->SetStandardFonts(size
, normal_face
, fixed_face
);
140 m_Cells
->Layout(m_Width
);
141 // else: SetHtmlText() not yet called, no need for relayout
144 int wxHtmlDCRenderer::Render(int x
, int y
,
145 wxArrayInt
& known_pagebreaks
,
146 int from
, int dont_render
, int to
)
148 wxCHECK_MSG( m_Cells
, 0, "SetHtmlText() must be called before Render()" );
149 wxCHECK_MSG( m_DC
, 0, "SetDC() must be called before Render()" );
153 pbreak
= (int)(from
+ m_Height
);
154 while (m_Cells
->AdjustPagebreak(&pbreak
, known_pagebreaks
)) {}
155 hght
= pbreak
- from
;
161 wxHtmlRenderingInfo rinfo
;
162 wxDefaultHtmlRenderingStyle rstyle
;
163 rinfo
.SetStyle(&rstyle
);
164 m_DC
->SetBrush(*wxWHITE_BRUSH
);
165 m_DC
->SetClippingRegion(x
, y
, m_Width
, hght
);
170 m_DC
->DestroyClippingRegion();
173 if (pbreak
< m_Cells
->GetHeight()) return pbreak
;
174 else return GetTotalHeight();
177 int wxHtmlDCRenderer::GetTotalWidth() const
179 return m_Cells
? m_Cells
->GetWidth() : 0;
182 int wxHtmlDCRenderer::GetTotalHeight() const
184 return m_Cells
? m_Cells
->GetHeight() : 0;
188 //--------------------------------------------------------------------------------
190 //--------------------------------------------------------------------------------
193 wxList
wxHtmlPrintout::m_Filters
;
195 wxHtmlPrintout::wxHtmlPrintout(const wxString
& title
) : wxPrintout(title
)
197 m_Renderer
= new wxHtmlDCRenderer
;
198 m_RendererHdr
= new wxHtmlDCRenderer
;
199 m_NumPages
= wxHTML_PRINT_MAX_PAGES
;
200 m_Document
= m_BasePath
= wxEmptyString
; m_BasePathIsDir
= true;
201 m_Headers
[0] = m_Headers
[1] = wxEmptyString
;
202 m_Footers
[0] = m_Footers
[1] = wxEmptyString
;
203 m_HeaderHeight
= m_FooterHeight
= 0;
204 SetMargins(); // to default values
205 SetStandardFonts(DEFAULT_PRINT_FONT_SIZE
);
210 wxHtmlPrintout::~wxHtmlPrintout()
213 delete m_RendererHdr
;
216 void wxHtmlPrintout::CleanUpStatics()
218 WX_CLEAR_LIST(wxList
, m_Filters
);
222 void wxHtmlPrintout::AddFilter(wxHtmlFilter
*filter
)
224 m_Filters
.Append(filter
);
228 wxHtmlPrintout::CheckFit(const wxSize
& pageArea
, const wxSize
& docArea
) const
230 // Nothing to do if the contents fits horizontally.
231 if ( docArea
.x
<= pageArea
.x
)
234 // Otherwise warn the user more or less intrusively depending on whether
235 // we're previewing or printing:
236 if ( wxPrintPreview
* const preview
= GetPreview() )
238 // Don't annoy the user too much when previewing by using info bar
239 // instead of a dialog box.
241 wxFrame
* const parent
= preview
->GetFrame();
242 wxCHECK_MSG( parent
, false, "No parent preview frame?" );
244 wxSizer
* const sizer
= parent
->GetSizer();
245 wxCHECK_MSG( sizer
, false, "Preview frame should be using sizers" );
247 wxInfoBar
* const bar
= new wxInfoBar(parent
);
248 sizer
->Add(bar
, wxSizerFlags().Expand());
250 // Note that the message here is similar to the one below but not
251 // exactly the same, notably we don't use the document title here
252 // because it's already clear which document it pertains to and the
253 // title may be long enough to make the text not fit in the window.
256 _("This document doesn't fit on the page horizontally and "
257 "will be truncated when it is printed."),
260 #endif // wxUSE_INFOBAR
262 else // We're going to really print and not just preview.
264 // This is our last chance to warn the user that the output will be
265 // mangled so do show a message box.
272 _("The document \"%s\" doesn't fit on the page "
273 "horizontally and will be truncated if printed.\n"
275 "Would you like to proceed with printing it nevertheless?"),
279 wxOK
| wxCANCEL
| wxCANCEL_DEFAULT
| wxICON_QUESTION
281 dlg
.SetExtendedMessage
283 _("If possible, try changing the layout parameters to "
284 "make the printout more narrow.")
286 dlg
.SetOKLabel(wxID_PRINT
);
288 if ( dlg
.ShowModal() == wxID_CANCEL
)
295 void wxHtmlPrintout::OnPreparePrinting()
297 int pageWidth
, pageHeight
, mm_w
, mm_h
, dc_w
, dc_h
;
298 float ppmm_h
, ppmm_v
;
300 GetPageSizePixels(&pageWidth
, &pageHeight
);
301 GetPageSizeMM(&mm_w
, &mm_h
);
302 ppmm_h
= (float)pageWidth
/ mm_w
;
303 ppmm_v
= (float)pageHeight
/ mm_h
;
305 int ppiPrinterX
, ppiPrinterY
;
306 GetPPIPrinter(&ppiPrinterX
, &ppiPrinterY
);
307 wxUnusedVar(ppiPrinterX
);
308 int ppiScreenX
, ppiScreenY
;
309 GetPPIScreen(&ppiScreenX
, &ppiScreenY
);
310 wxUnusedVar(ppiScreenX
);
312 GetDC()->GetSize(&dc_w
, &dc_h
);
314 GetDC()->SetUserScale((double)dc_w
/ (double)pageWidth
,
315 (double)dc_h
/ (double)pageHeight
);
317 /* prepare headers/footers renderer: */
319 m_RendererHdr
->SetDC(GetDC(),
320 (double)ppiPrinterY
/ TYPICAL_SCREEN_DPI
,
321 (double)ppiPrinterY
/ (double)ppiScreenY
);
322 m_RendererHdr
->SetSize((int) (ppmm_h
* (mm_w
- m_MarginLeft
- m_MarginRight
)),
323 (int) (ppmm_v
* (mm_h
- m_MarginTop
- m_MarginBottom
)));
324 if (m_Headers
[0] != wxEmptyString
)
326 m_RendererHdr
->SetHtmlText(TranslateHeader(m_Headers
[0], 1));
327 m_HeaderHeight
= m_RendererHdr
->GetTotalHeight();
329 else if (m_Headers
[1] != wxEmptyString
)
331 m_RendererHdr
->SetHtmlText(TranslateHeader(m_Headers
[1], 1));
332 m_HeaderHeight
= m_RendererHdr
->GetTotalHeight();
334 if (m_Footers
[0] != wxEmptyString
)
336 m_RendererHdr
->SetHtmlText(TranslateHeader(m_Footers
[0], 1));
337 m_FooterHeight
= m_RendererHdr
->GetTotalHeight();
339 else if (m_Footers
[1] != wxEmptyString
)
341 m_RendererHdr
->SetHtmlText(TranslateHeader(m_Footers
[1], 1));
342 m_FooterHeight
= m_RendererHdr
->GetTotalHeight();
345 /* prepare main renderer: */
346 m_Renderer
->SetDC(GetDC(),
347 (double)ppiPrinterY
/ TYPICAL_SCREEN_DPI
,
348 (double)ppiPrinterY
/ (double)ppiScreenY
);
350 const int printAreaW
= int(ppmm_h
* (mm_w
- m_MarginLeft
- m_MarginRight
));
351 int printAreaH
= int(ppmm_v
* (mm_h
- m_MarginTop
- m_MarginBottom
));
352 if ( m_HeaderHeight
)
353 printAreaH
-= int(m_HeaderHeight
+ m_MarginSpace
* ppmm_v
);
354 if ( m_FooterHeight
)
355 printAreaH
-= int(m_FooterHeight
+ m_MarginSpace
* ppmm_v
);
357 m_Renderer
->SetSize(printAreaW
, printAreaH
);
358 m_Renderer
->SetHtmlText(m_Document
, m_BasePath
, m_BasePathIsDir
);
360 if ( CheckFit(wxSize(printAreaW
, printAreaH
),
361 wxSize(m_Renderer
->GetTotalWidth(),
362 m_Renderer
->GetTotalHeight())) || IsPreview() )
364 // do paginate the document
367 //else: if we don't call CountPages() m_PageBreaks remains empty and our
368 // GetPageInfo() will return 0 as max page and so nothing will be
372 bool wxHtmlPrintout::OnBeginDocument(int startPage
, int endPage
)
374 if (!wxPrintout::OnBeginDocument(startPage
, endPage
)) return false;
380 bool wxHtmlPrintout::OnPrintPage(int page
)
383 if (dc
&& dc
->IsOk())
386 RenderPage(dc
, page
);
393 void wxHtmlPrintout::GetPageInfo(int *minPage
, int *maxPage
, int *selPageFrom
, int *selPageTo
)
396 if ( m_NumPages
>= (signed)m_PageBreaks
.GetCount()-1)
397 *maxPage
= m_NumPages
;
399 *maxPage
= (signed)m_PageBreaks
.GetCount()-1;
401 *selPageTo
= (signed)m_PageBreaks
.GetCount()-1;
406 bool wxHtmlPrintout::HasPage(int pageNum
)
408 return pageNum
> 0 && (unsigned)pageNum
< m_PageBreaks
.GetCount();
413 void wxHtmlPrintout::SetHtmlText(const wxString
& html
, const wxString
&basepath
, bool isdir
)
416 m_BasePath
= basepath
;
417 m_BasePathIsDir
= isdir
;
420 void wxHtmlPrintout::SetHtmlFile(const wxString
& htmlfile
)
425 if (wxFileExists(htmlfile
))
426 ff
= fs
.OpenFile(wxFileSystem::FileNameToURL(htmlfile
));
428 ff
= fs
.OpenFile(htmlfile
);
432 wxLogError(htmlfile
+ _(": file does not exist!"));
437 wxHtmlFilterHTML defaultFilter
;
440 wxList::compatibility_iterator node
= m_Filters
.GetFirst();
443 wxHtmlFilter
*h
= (wxHtmlFilter
*) node
->GetData();
446 doc
= h
->ReadFile(*ff
);
450 node
= node
->GetNext();
454 doc
= defaultFilter
.ReadFile(*ff
);
456 SetHtmlText(doc
, htmlfile
, false);
462 void wxHtmlPrintout::SetHeader(const wxString
& header
, int pg
)
464 if (pg
== wxPAGE_ALL
|| pg
== wxPAGE_EVEN
)
465 m_Headers
[0] = header
;
466 if (pg
== wxPAGE_ALL
|| pg
== wxPAGE_ODD
)
467 m_Headers
[1] = header
;
472 void wxHtmlPrintout::SetFooter(const wxString
& footer
, int pg
)
474 if (pg
== wxPAGE_ALL
|| pg
== wxPAGE_EVEN
)
475 m_Footers
[0] = footer
;
476 if (pg
== wxPAGE_ALL
|| pg
== wxPAGE_ODD
)
477 m_Footers
[1] = footer
;
482 void wxHtmlPrintout::CountPages()
485 int pageWidth
, pageHeight
, mm_w
, mm_h
;
486 float ppmm_h
, ppmm_v
;
488 GetPageSizePixels(&pageWidth
, &pageHeight
);
489 GetPageSizeMM(&mm_w
, &mm_h
);
490 ppmm_h
= (float)pageWidth
/ mm_w
;
491 ppmm_v
= (float)pageHeight
/ mm_h
;
495 // m_PageBreaks[0] = 0;
497 m_PageBreaks
.Clear();
498 m_PageBreaks
.Add( 0);
501 pos
= m_Renderer
->Render((int)( ppmm_h
* m_MarginLeft
),
502 (int) (ppmm_v
* (m_MarginTop
+ (m_HeaderHeight
== 0 ? 0 : m_MarginSpace
)) + m_HeaderHeight
),
505 m_PageBreaks
.Add( pos
);
506 if( m_PageBreaks
.GetCount() > wxHTML_PRINT_MAX_PAGES
)
508 wxMessageBox( _("HTML pagination algorithm generated more than the allowed maximum number of pages and it can't continue any longer!"),
509 _("Warning"), wxCANCEL
| wxICON_ERROR
);
512 } while (pos
< m_Renderer
->GetTotalHeight());
517 void wxHtmlPrintout::RenderPage(wxDC
*dc
, int page
)
521 int pageWidth
, pageHeight
, mm_w
, mm_h
, dc_w
, dc_h
;
522 float ppmm_h
, ppmm_v
;
524 GetPageSizePixels(&pageWidth
, &pageHeight
);
525 GetPageSizeMM(&mm_w
, &mm_h
);
526 ppmm_h
= (float)pageWidth
/ mm_w
;
527 ppmm_v
= (float)pageHeight
/ mm_h
;
528 dc
->GetSize(&dc_w
, &dc_h
);
530 int ppiPrinterX
, ppiPrinterY
;
531 GetPPIPrinter(&ppiPrinterX
, &ppiPrinterY
);
532 wxUnusedVar(ppiPrinterX
);
533 int ppiScreenX
, ppiScreenY
;
534 GetPPIScreen(&ppiScreenX
, &ppiScreenY
);
535 wxUnusedVar(ppiScreenX
);
537 dc
->SetUserScale((double)dc_w
/ (double)pageWidth
,
538 (double)dc_h
/ (double)pageHeight
);
540 m_Renderer
->SetDC(dc
,
541 (double)ppiPrinterY
/ TYPICAL_SCREEN_DPI
,
542 (double)ppiPrinterY
/ (double)ppiScreenY
);
544 dc
->SetBackgroundMode(wxBRUSHSTYLE_TRANSPARENT
);
546 m_Renderer
->Render((int) (ppmm_h
* m_MarginLeft
),
547 (int) (ppmm_v
* (m_MarginTop
+ (m_HeaderHeight
== 0 ? 0 : m_MarginSpace
)) + m_HeaderHeight
), m_PageBreaks
,
548 m_PageBreaks
[page
-1], false, m_PageBreaks
[page
]-m_PageBreaks
[page
-1]);
551 m_RendererHdr
->SetDC(dc
,
552 (double)ppiPrinterY
/ TYPICAL_SCREEN_DPI
,
553 (double)ppiPrinterY
/ (double)ppiScreenY
);
554 if (m_Headers
[page
% 2] != wxEmptyString
)
556 m_RendererHdr
->SetHtmlText(TranslateHeader(m_Headers
[page
% 2], page
));
557 m_RendererHdr
->Render((int) (ppmm_h
* m_MarginLeft
), (int) (ppmm_v
* m_MarginTop
), m_PageBreaks
);
559 if (m_Footers
[page
% 2] != wxEmptyString
)
561 m_RendererHdr
->SetHtmlText(TranslateHeader(m_Footers
[page
% 2], page
));
562 m_RendererHdr
->Render((int) (ppmm_h
* m_MarginLeft
), (int) (pageHeight
- ppmm_v
* m_MarginBottom
- m_FooterHeight
), m_PageBreaks
);
568 wxString
wxHtmlPrintout::TranslateHeader(const wxString
& instr
, int page
)
573 num
.Printf(wxT("%i"), page
);
574 r
.Replace(wxT("@PAGENUM@"), num
);
576 num
.Printf(wxT("%lu"), (unsigned long)(m_PageBreaks
.GetCount() - 1));
577 r
.Replace(wxT("@PAGESCNT@"), num
);
579 const wxDateTime now
= wxDateTime::Now();
580 r
.Replace(wxT("@DATE@"), now
.FormatDate());
581 r
.Replace(wxT("@TIME@"), now
.FormatTime());
583 r
.Replace(wxT("@TITLE@"), GetTitle());
590 void wxHtmlPrintout::SetMargins(float top
, float bottom
, float left
, float right
, float spaces
)
593 m_MarginBottom
= bottom
;
595 m_MarginRight
= right
;
596 m_MarginSpace
= spaces
;
602 void wxHtmlPrintout::SetFonts(const wxString
& normal_face
, const wxString
& fixed_face
,
605 m_Renderer
->SetFonts(normal_face
, fixed_face
, sizes
);
606 m_RendererHdr
->SetFonts(normal_face
, fixed_face
, sizes
);
609 void wxHtmlPrintout::SetStandardFonts(int size
,
610 const wxString
& normal_face
,
611 const wxString
& fixed_face
)
613 m_Renderer
->SetStandardFonts(size
, normal_face
, fixed_face
);
614 m_RendererHdr
->SetStandardFonts(size
, normal_face
, fixed_face
);
619 //----------------------------------------------------------------------------
620 // wxHtmlEasyPrinting
621 //----------------------------------------------------------------------------
624 wxHtmlEasyPrinting::wxHtmlEasyPrinting(const wxString
& name
, wxWindow
*parentWindow
)
626 m_ParentWindow
= parentWindow
;
629 m_PageSetupData
= new wxPageSetupDialogData
;
630 m_Headers
[0] = m_Headers
[1] = m_Footers
[0] = m_Footers
[1] = wxEmptyString
;
632 m_PageSetupData
->EnableMargins(true);
633 m_PageSetupData
->SetMarginTopLeft(wxPoint(25, 25));
634 m_PageSetupData
->SetMarginBottomRight(wxPoint(25, 25));
636 SetStandardFonts(DEFAULT_PRINT_FONT_SIZE
);
641 wxHtmlEasyPrinting::~wxHtmlEasyPrinting()
644 delete m_PageSetupData
;
648 wxPrintData
*wxHtmlEasyPrinting::GetPrintData()
650 if (m_PrintData
== NULL
)
651 m_PrintData
= new wxPrintData();
656 bool wxHtmlEasyPrinting::PreviewFile(const wxString
&htmlfile
)
658 wxHtmlPrintout
*p1
= CreatePrintout();
659 p1
->SetHtmlFile(htmlfile
);
660 wxHtmlPrintout
*p2
= CreatePrintout();
661 p2
->SetHtmlFile(htmlfile
);
662 return DoPreview(p1
, p2
);
667 bool wxHtmlEasyPrinting::PreviewText(const wxString
&htmltext
, const wxString
&basepath
)
669 wxHtmlPrintout
*p1
= CreatePrintout();
670 p1
->SetHtmlText(htmltext
, basepath
, true);
671 wxHtmlPrintout
*p2
= CreatePrintout();
672 p2
->SetHtmlText(htmltext
, basepath
, true);
673 return DoPreview(p1
, p2
);
678 bool wxHtmlEasyPrinting::PrintFile(const wxString
&htmlfile
)
680 wxHtmlPrintout
*p
= CreatePrintout();
681 p
->SetHtmlFile(htmlfile
);
682 bool ret
= DoPrint(p
);
689 bool wxHtmlEasyPrinting::PrintText(const wxString
&htmltext
, const wxString
&basepath
)
691 wxHtmlPrintout
*p
= CreatePrintout();
692 p
->SetHtmlText(htmltext
, basepath
, true);
693 bool ret
= DoPrint(p
);
700 bool wxHtmlEasyPrinting::DoPreview(wxHtmlPrintout
*printout1
, wxHtmlPrintout
*printout2
)
702 // Pass two printout objects: for preview, and possible printing.
703 wxPrintDialogData
printDialogData(*GetPrintData());
704 wxPrintPreview
*preview
= new wxPrintPreview(printout1
, printout2
, &printDialogData
);
711 wxPreviewFrame
*frame
= new wxPreviewFrame(preview
, m_ParentWindow
,
712 m_Name
+ _(" Preview"),
713 wxPoint(100, 100), wxSize(650, 500));
714 frame
->Centre(wxBOTH
);
722 bool wxHtmlEasyPrinting::DoPrint(wxHtmlPrintout
*printout
)
724 wxPrintDialogData
printDialogData(*GetPrintData());
725 wxPrinter
printer(&printDialogData
);
727 if (!printer
.Print(m_ParentWindow
, printout
, true))
732 (*GetPrintData()) = printer
.GetPrintDialogData().GetPrintData();
739 void wxHtmlEasyPrinting::PageSetup()
741 if (!GetPrintData()->Ok())
743 wxLogError(_("There was a problem during page setup: you may need to set a default printer."));
747 m_PageSetupData
->SetPrintData(*GetPrintData());
748 wxPageSetupDialog
pageSetupDialog(m_ParentWindow
, m_PageSetupData
);
750 if (pageSetupDialog
.ShowModal() == wxID_OK
)
752 (*GetPrintData()) = pageSetupDialog
.GetPageSetupData().GetPrintData();
753 (*m_PageSetupData
) = pageSetupDialog
.GetPageSetupData();
759 void wxHtmlEasyPrinting::SetHeader(const wxString
& header
, int pg
)
761 if (pg
== wxPAGE_ALL
|| pg
== wxPAGE_EVEN
)
762 m_Headers
[0] = header
;
763 if (pg
== wxPAGE_ALL
|| pg
== wxPAGE_ODD
)
764 m_Headers
[1] = header
;
769 void wxHtmlEasyPrinting::SetFooter(const wxString
& footer
, int pg
)
771 if (pg
== wxPAGE_ALL
|| pg
== wxPAGE_EVEN
)
772 m_Footers
[0] = footer
;
773 if (pg
== wxPAGE_ALL
|| pg
== wxPAGE_ODD
)
774 m_Footers
[1] = footer
;
778 void wxHtmlEasyPrinting::SetFonts(const wxString
& normal_face
, const wxString
& fixed_face
,
781 m_fontMode
= FontMode_Explicit
;
782 m_FontFaceNormal
= normal_face
;
783 m_FontFaceFixed
= fixed_face
;
787 m_FontsSizes
= m_FontsSizesArr
;
788 for (int i
= 0; i
< 7; i
++) m_FontsSizes
[i
] = sizes
[i
];
794 void wxHtmlEasyPrinting::SetStandardFonts(int size
,
795 const wxString
& normal_face
,
796 const wxString
& fixed_face
)
798 m_fontMode
= FontMode_Standard
;
799 m_FontFaceNormal
= normal_face
;
800 m_FontFaceFixed
= fixed_face
;
801 m_FontsSizesArr
[0] = size
;
805 wxHtmlPrintout
*wxHtmlEasyPrinting::CreatePrintout()
807 wxHtmlPrintout
*p
= new wxHtmlPrintout(m_Name
);
809 if (m_fontMode
== FontMode_Explicit
)
811 p
->SetFonts(m_FontFaceNormal
, m_FontFaceFixed
, m_FontsSizes
);
813 else // FontMode_Standard
815 p
->SetStandardFonts(m_FontsSizesArr
[0],
816 m_FontFaceNormal
, m_FontFaceFixed
);
819 p
->SetHeader(m_Headers
[0], wxPAGE_EVEN
);
820 p
->SetHeader(m_Headers
[1], wxPAGE_ODD
);
821 p
->SetFooter(m_Footers
[0], wxPAGE_EVEN
);
822 p
->SetFooter(m_Footers
[1], wxPAGE_ODD
);
824 p
->SetMargins(m_PageSetupData
->GetMarginTopLeft().y
,
825 m_PageSetupData
->GetMarginBottomRight().y
,
826 m_PageSetupData
->GetMarginTopLeft().x
,
827 m_PageSetupData
->GetMarginBottomRight().x
);
832 // A module to allow initialization/cleanup
833 // without calling these functions from app.cpp or from
834 // the user's application.
836 class wxHtmlPrintingModule
: public wxModule
838 DECLARE_DYNAMIC_CLASS(wxHtmlPrintingModule
)
840 wxHtmlPrintingModule() : wxModule() {}
841 bool OnInit() { return true; }
842 void OnExit() { wxHtmlPrintout::CleanUpStatics(); }
845 IMPLEMENT_DYNAMIC_CLASS(wxHtmlPrintingModule
, wxModule
)
848 // This hack forces the linker to always link in m_* files
849 // (wxHTML doesn't work without handlers from these files)
850 #include "wx/html/forcelnk.h"
851 FORCE_WXHTML_MODULES()
853 #endif // wxUSE_HTML & wxUSE_PRINTING_ARCHITECTURE