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"
30 #include "wx/printdlg.h"
31 #include "wx/html/htmprint.h"
32 #include "wx/wxhtml.h"
33 #include "wx/wfstream.h"
36 // default font size of normal text (HTML font size 0) for printing, in points:
37 #define DEFAULT_PRINT_FONT_SIZE 12
40 // CSS specification offer following guidance on dealing with pixel sizes
42 // http://www.w3.org/TR/2004/CR-CSS21-20040225/syndata.html#length-units:
44 // Pixel units are relative to the resolution of the viewing device, i.e.,
45 // most often a computer display. If the pixel density of the output
46 // device is very different from that of a typical computer display, the
47 // user agent should rescale pixel values. It is recommended that the [
48 // reference pixel] be the visual angle of one pixel on a device with a
49 // pixel density of 96dpi and a distance from the reader of an arm's
50 // length. For a nominal arm's length of 28 inches, the visual angle is
51 // therefore about 0.0213 degrees.
53 // For reading at arm's length, 1px thus corresponds to about 0.26 mm
54 // (1/96 inch). When printed on a laser printer, meant for reading at a
55 // little less than arm's length (55 cm, 21 inches), 1px is about 0.20 mm.
56 // On a 300 dots-per-inch (dpi) printer, that may be rounded up to 3 dots
57 // (0.25 mm); on a 600 dpi printer, it can be rounded to 5 dots.
59 // See also http://trac.wxwidgets.org/ticket/10942.
60 #define TYPICAL_SCREEN_DPI 96.0
62 //--------------------------------------------------------------------------------
64 //--------------------------------------------------------------------------------
67 wxHtmlDCRenderer::wxHtmlDCRenderer() : wxObject()
70 m_Width
= m_Height
= 0;
72 m_Parser
= new wxHtmlWinParser();
73 m_FS
= new wxFileSystem();
74 m_Parser
->SetFS(m_FS
);
75 SetStandardFonts(DEFAULT_PRINT_FONT_SIZE
);
80 wxHtmlDCRenderer::~wxHtmlDCRenderer()
82 if (m_Cells
) delete m_Cells
;
83 if (m_Parser
) delete m_Parser
;
84 if (m_FS
) delete m_FS
;
89 void wxHtmlDCRenderer::SetDC(wxDC
*dc
, double pixel_scale
, double font_scale
)
92 m_Parser
->SetDC(m_DC
, pixel_scale
, font_scale
);
97 void wxHtmlDCRenderer::SetSize(int width
, int height
)
99 wxCHECK_RET( width
, "width must be non-zero" );
100 wxCHECK_RET( height
, "height must be non-zero" );
107 void wxHtmlDCRenderer::SetHtmlText(const wxString
& html
, const wxString
& basepath
, bool isdir
)
109 wxCHECK_RET( m_DC
, "SetDC() must be called before SetHtmlText()" );
110 wxCHECK_RET( m_Width
, "SetSize() must be called before SetHtmlText()" );
114 m_FS
->ChangePathTo(basepath
, isdir
);
115 m_Cells
= (wxHtmlContainerCell
*) m_Parser
->Parse(html
);
116 m_Cells
->SetIndent(0, wxHTML_INDENT_ALL
, wxHTML_UNITS_PIXELS
);
117 m_Cells
->Layout(m_Width
);
121 void wxHtmlDCRenderer::SetFonts(const wxString
& normal_face
, const wxString
& fixed_face
,
124 m_Parser
->SetFonts(normal_face
, fixed_face
, sizes
);
127 m_Cells
->Layout(m_Width
);
128 // else: SetHtmlText() not yet called, no need for relayout
131 void wxHtmlDCRenderer::SetStandardFonts(int size
,
132 const wxString
& normal_face
,
133 const wxString
& fixed_face
)
135 m_Parser
->SetStandardFonts(size
, normal_face
, fixed_face
);
138 m_Cells
->Layout(m_Width
);
139 // else: SetHtmlText() not yet called, no need for relayout
142 int wxHtmlDCRenderer::Render(int x
, int y
,
143 wxArrayInt
& known_pagebreaks
,
144 int from
, int dont_render
, int to
)
146 wxCHECK_MSG( m_Cells
, 0, "SetHtmlText() must be called before Render()" );
147 wxCHECK_MSG( m_DC
, 0, "SetDC() must be called before Render()" );
151 pbreak
= (int)(from
+ m_Height
);
152 while (m_Cells
->AdjustPagebreak(&pbreak
, known_pagebreaks
)) {}
153 hght
= pbreak
- from
;
159 wxHtmlRenderingInfo rinfo
;
160 wxDefaultHtmlRenderingStyle rstyle
;
161 rinfo
.SetStyle(&rstyle
);
162 m_DC
->SetBrush(*wxWHITE_BRUSH
);
163 m_DC
->SetClippingRegion(x
, y
, m_Width
, hght
);
168 m_DC
->DestroyClippingRegion();
171 if (pbreak
< m_Cells
->GetHeight()) return pbreak
;
172 else return GetTotalHeight();
175 int wxHtmlDCRenderer::GetTotalWidth() const
177 return m_Cells
? m_Cells
->GetWidth() : 0;
180 int wxHtmlDCRenderer::GetTotalHeight() const
182 return m_Cells
? m_Cells
->GetHeight() : 0;
186 //--------------------------------------------------------------------------------
188 //--------------------------------------------------------------------------------
191 wxList
wxHtmlPrintout::m_Filters
;
193 wxHtmlPrintout::wxHtmlPrintout(const wxString
& title
) : wxPrintout(title
)
195 m_Renderer
= new wxHtmlDCRenderer
;
196 m_RendererHdr
= new wxHtmlDCRenderer
;
197 m_NumPages
= wxHTML_PRINT_MAX_PAGES
;
198 m_Document
= m_BasePath
= wxEmptyString
; m_BasePathIsDir
= true;
199 m_Headers
[0] = m_Headers
[1] = wxEmptyString
;
200 m_Footers
[0] = m_Footers
[1] = wxEmptyString
;
201 m_HeaderHeight
= m_FooterHeight
= 0;
202 SetMargins(); // to default values
203 SetStandardFonts(DEFAULT_PRINT_FONT_SIZE
);
208 wxHtmlPrintout::~wxHtmlPrintout()
211 delete m_RendererHdr
;
214 void wxHtmlPrintout::CleanUpStatics()
216 WX_CLEAR_LIST(wxList
, m_Filters
);
220 void wxHtmlPrintout::AddFilter(wxHtmlFilter
*filter
)
222 m_Filters
.Append(filter
);
226 wxHtmlPrintout::CheckFit(const wxSize
& pageArea
, const wxSize
& docArea
) const
228 if ( docArea
.x
> pageArea
.x
)
236 _("The document \"%s\" doesn't fit on the page "
237 "horizontally and will be truncated if printed.\n"
239 "Would you like to proceed with printing it nevertheless?"),
243 wxOK
| wxCANCEL
| wxCANCEL_DEFAULT
| wxICON_QUESTION
245 dlg
.SetExtendedMessage
247 _("If possible, try changing the layout parameters to "
248 "make the printout more narrow.")
250 dlg
.SetOKLabel(wxID_PRINT
);
252 if ( dlg
.ShowModal() == wxID_CANCEL
)
259 void wxHtmlPrintout::OnPreparePrinting()
261 int pageWidth
, pageHeight
, mm_w
, mm_h
, dc_w
, dc_h
;
262 float ppmm_h
, ppmm_v
;
264 GetPageSizePixels(&pageWidth
, &pageHeight
);
265 GetPageSizeMM(&mm_w
, &mm_h
);
266 ppmm_h
= (float)pageWidth
/ mm_w
;
267 ppmm_v
= (float)pageHeight
/ mm_h
;
269 int ppiPrinterX
, ppiPrinterY
;
270 GetPPIPrinter(&ppiPrinterX
, &ppiPrinterY
);
271 wxUnusedVar(ppiPrinterX
);
272 int ppiScreenX
, ppiScreenY
;
273 GetPPIScreen(&ppiScreenX
, &ppiScreenY
);
274 wxUnusedVar(ppiScreenX
);
276 GetDC()->GetSize(&dc_w
, &dc_h
);
278 GetDC()->SetUserScale((double)dc_w
/ (double)pageWidth
,
279 (double)dc_h
/ (double)pageHeight
);
281 /* prepare headers/footers renderer: */
283 m_RendererHdr
->SetDC(GetDC(),
284 (double)ppiPrinterY
/ TYPICAL_SCREEN_DPI
,
285 (double)ppiPrinterY
/ (double)ppiScreenY
);
286 m_RendererHdr
->SetSize((int) (ppmm_h
* (mm_w
- m_MarginLeft
- m_MarginRight
)),
287 (int) (ppmm_v
* (mm_h
- m_MarginTop
- m_MarginBottom
)));
288 if (m_Headers
[0] != wxEmptyString
)
290 m_RendererHdr
->SetHtmlText(TranslateHeader(m_Headers
[0], 1));
291 m_HeaderHeight
= m_RendererHdr
->GetTotalHeight();
293 else if (m_Headers
[1] != wxEmptyString
)
295 m_RendererHdr
->SetHtmlText(TranslateHeader(m_Headers
[1], 1));
296 m_HeaderHeight
= m_RendererHdr
->GetTotalHeight();
298 if (m_Footers
[0] != wxEmptyString
)
300 m_RendererHdr
->SetHtmlText(TranslateHeader(m_Footers
[0], 1));
301 m_FooterHeight
= m_RendererHdr
->GetTotalHeight();
303 else if (m_Footers
[1] != wxEmptyString
)
305 m_RendererHdr
->SetHtmlText(TranslateHeader(m_Footers
[1], 1));
306 m_FooterHeight
= m_RendererHdr
->GetTotalHeight();
309 /* prepare main renderer: */
310 m_Renderer
->SetDC(GetDC(),
311 (double)ppiPrinterY
/ TYPICAL_SCREEN_DPI
,
312 (double)ppiPrinterY
/ (double)ppiScreenY
);
314 const int printAreaW
= int(ppmm_h
* (mm_w
- m_MarginLeft
- m_MarginRight
));
315 int printAreaH
= int(ppmm_v
* (mm_h
- m_MarginTop
- m_MarginBottom
));
316 if ( m_HeaderHeight
)
317 printAreaH
-= int(m_HeaderHeight
+ m_MarginSpace
* ppmm_v
);
318 if ( m_FooterHeight
)
319 printAreaH
-= int(m_FooterHeight
+ m_MarginSpace
* ppmm_v
);
321 m_Renderer
->SetSize(printAreaW
, printAreaH
);
322 m_Renderer
->SetHtmlText(m_Document
, m_BasePath
, m_BasePathIsDir
);
324 if ( CheckFit(wxSize(printAreaW
, printAreaH
),
325 wxSize(m_Renderer
->GetTotalWidth(),
326 m_Renderer
->GetTotalHeight())) )
328 // do paginate the document
331 //else: if we don't call CountPages() m_PageBreaks remains empty and our
332 // GetPageInfo() will return 0 as max page and so nothing will be
336 bool wxHtmlPrintout::OnBeginDocument(int startPage
, int endPage
)
338 if (!wxPrintout::OnBeginDocument(startPage
, endPage
)) return false;
344 bool wxHtmlPrintout::OnPrintPage(int page
)
347 if (dc
&& dc
->IsOk())
350 RenderPage(dc
, page
);
357 void wxHtmlPrintout::GetPageInfo(int *minPage
, int *maxPage
, int *selPageFrom
, int *selPageTo
)
360 if ( m_NumPages
>= (signed)m_PageBreaks
.GetCount()-1)
361 *maxPage
= m_NumPages
;
363 *maxPage
= (signed)m_PageBreaks
.GetCount()-1;
365 *selPageTo
= (signed)m_PageBreaks
.GetCount()-1;
370 bool wxHtmlPrintout::HasPage(int pageNum
)
372 return pageNum
> 0 && (unsigned)pageNum
< m_PageBreaks
.GetCount();
377 void wxHtmlPrintout::SetHtmlText(const wxString
& html
, const wxString
&basepath
, bool isdir
)
380 m_BasePath
= basepath
;
381 m_BasePathIsDir
= isdir
;
384 void wxHtmlPrintout::SetHtmlFile(const wxString
& htmlfile
)
389 if (wxFileExists(htmlfile
))
390 ff
= fs
.OpenFile(wxFileSystem::FileNameToURL(htmlfile
));
392 ff
= fs
.OpenFile(htmlfile
);
396 wxLogError(htmlfile
+ _(": file does not exist!"));
401 wxHtmlFilterHTML defaultFilter
;
404 wxList::compatibility_iterator node
= m_Filters
.GetFirst();
407 wxHtmlFilter
*h
= (wxHtmlFilter
*) node
->GetData();
410 doc
= h
->ReadFile(*ff
);
414 node
= node
->GetNext();
418 doc
= defaultFilter
.ReadFile(*ff
);
420 SetHtmlText(doc
, htmlfile
, false);
426 void wxHtmlPrintout::SetHeader(const wxString
& header
, int pg
)
428 if (pg
== wxPAGE_ALL
|| pg
== wxPAGE_EVEN
)
429 m_Headers
[0] = header
;
430 if (pg
== wxPAGE_ALL
|| pg
== wxPAGE_ODD
)
431 m_Headers
[1] = header
;
436 void wxHtmlPrintout::SetFooter(const wxString
& footer
, int pg
)
438 if (pg
== wxPAGE_ALL
|| pg
== wxPAGE_EVEN
)
439 m_Footers
[0] = footer
;
440 if (pg
== wxPAGE_ALL
|| pg
== wxPAGE_ODD
)
441 m_Footers
[1] = footer
;
446 void wxHtmlPrintout::CountPages()
449 int pageWidth
, pageHeight
, mm_w
, mm_h
;
450 float ppmm_h
, ppmm_v
;
452 GetPageSizePixels(&pageWidth
, &pageHeight
);
453 GetPageSizeMM(&mm_w
, &mm_h
);
454 ppmm_h
= (float)pageWidth
/ mm_w
;
455 ppmm_v
= (float)pageHeight
/ mm_h
;
459 // m_PageBreaks[0] = 0;
461 m_PageBreaks
.Clear();
462 m_PageBreaks
.Add( 0);
465 pos
= m_Renderer
->Render((int)( ppmm_h
* m_MarginLeft
),
466 (int) (ppmm_v
* (m_MarginTop
+ (m_HeaderHeight
== 0 ? 0 : m_MarginSpace
)) + m_HeaderHeight
),
469 m_PageBreaks
.Add( pos
);
470 if( m_PageBreaks
.GetCount() > wxHTML_PRINT_MAX_PAGES
)
472 wxMessageBox( _("HTML pagination algorithm generated more than the allowed maximum number of pages and it can't continue any longer!"),
473 _("Warning"), wxCANCEL
| wxICON_ERROR
);
476 } while (pos
< m_Renderer
->GetTotalHeight());
481 void wxHtmlPrintout::RenderPage(wxDC
*dc
, int page
)
485 int pageWidth
, pageHeight
, mm_w
, mm_h
, dc_w
, dc_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
;
492 dc
->GetSize(&dc_w
, &dc_h
);
494 int ppiPrinterX
, ppiPrinterY
;
495 GetPPIPrinter(&ppiPrinterX
, &ppiPrinterY
);
496 wxUnusedVar(ppiPrinterX
);
497 int ppiScreenX
, ppiScreenY
;
498 GetPPIScreen(&ppiScreenX
, &ppiScreenY
);
499 wxUnusedVar(ppiScreenX
);
501 dc
->SetUserScale((double)dc_w
/ (double)pageWidth
,
502 (double)dc_h
/ (double)pageHeight
);
504 m_Renderer
->SetDC(dc
,
505 (double)ppiPrinterY
/ TYPICAL_SCREEN_DPI
,
506 (double)ppiPrinterY
/ (double)ppiScreenY
);
508 dc
->SetBackgroundMode(wxBRUSHSTYLE_TRANSPARENT
);
510 m_Renderer
->Render((int) (ppmm_h
* m_MarginLeft
),
511 (int) (ppmm_v
* (m_MarginTop
+ (m_HeaderHeight
== 0 ? 0 : m_MarginSpace
)) + m_HeaderHeight
), m_PageBreaks
,
512 m_PageBreaks
[page
-1], false, m_PageBreaks
[page
]-m_PageBreaks
[page
-1]);
515 m_RendererHdr
->SetDC(dc
,
516 (double)ppiPrinterY
/ TYPICAL_SCREEN_DPI
,
517 (double)ppiPrinterY
/ (double)ppiScreenY
);
518 if (m_Headers
[page
% 2] != wxEmptyString
)
520 m_RendererHdr
->SetHtmlText(TranslateHeader(m_Headers
[page
% 2], page
));
521 m_RendererHdr
->Render((int) (ppmm_h
* m_MarginLeft
), (int) (ppmm_v
* m_MarginTop
), m_PageBreaks
);
523 if (m_Footers
[page
% 2] != wxEmptyString
)
525 m_RendererHdr
->SetHtmlText(TranslateHeader(m_Footers
[page
% 2], page
));
526 m_RendererHdr
->Render((int) (ppmm_h
* m_MarginLeft
), (int) (pageHeight
- ppmm_v
* m_MarginBottom
- m_FooterHeight
), m_PageBreaks
);
532 wxString
wxHtmlPrintout::TranslateHeader(const wxString
& instr
, int page
)
537 num
.Printf(wxT("%i"), page
);
538 r
.Replace(wxT("@PAGENUM@"), num
);
540 num
.Printf(wxT("%lu"), (unsigned long)(m_PageBreaks
.GetCount() - 1));
541 r
.Replace(wxT("@PAGESCNT@"), num
);
543 const wxDateTime now
= wxDateTime::Now();
544 r
.Replace(wxT("@DATE@"), now
.FormatDate());
545 r
.Replace(wxT("@TIME@"), now
.FormatTime());
547 r
.Replace(wxT("@TITLE@"), GetTitle());
554 void wxHtmlPrintout::SetMargins(float top
, float bottom
, float left
, float right
, float spaces
)
557 m_MarginBottom
= bottom
;
559 m_MarginRight
= right
;
560 m_MarginSpace
= spaces
;
566 void wxHtmlPrintout::SetFonts(const wxString
& normal_face
, const wxString
& fixed_face
,
569 m_Renderer
->SetFonts(normal_face
, fixed_face
, sizes
);
570 m_RendererHdr
->SetFonts(normal_face
, fixed_face
, sizes
);
573 void wxHtmlPrintout::SetStandardFonts(int size
,
574 const wxString
& normal_face
,
575 const wxString
& fixed_face
)
577 m_Renderer
->SetStandardFonts(size
, normal_face
, fixed_face
);
578 m_RendererHdr
->SetStandardFonts(size
, normal_face
, fixed_face
);
583 //----------------------------------------------------------------------------
584 // wxHtmlEasyPrinting
585 //----------------------------------------------------------------------------
588 wxHtmlEasyPrinting::wxHtmlEasyPrinting(const wxString
& name
, wxWindow
*parentWindow
)
590 m_ParentWindow
= parentWindow
;
593 m_PageSetupData
= new wxPageSetupDialogData
;
594 m_Headers
[0] = m_Headers
[1] = m_Footers
[0] = m_Footers
[1] = wxEmptyString
;
596 m_PageSetupData
->EnableMargins(true);
597 m_PageSetupData
->SetMarginTopLeft(wxPoint(25, 25));
598 m_PageSetupData
->SetMarginBottomRight(wxPoint(25, 25));
600 SetStandardFonts(DEFAULT_PRINT_FONT_SIZE
);
605 wxHtmlEasyPrinting::~wxHtmlEasyPrinting()
608 delete m_PageSetupData
;
612 wxPrintData
*wxHtmlEasyPrinting::GetPrintData()
614 if (m_PrintData
== NULL
)
615 m_PrintData
= new wxPrintData();
620 bool wxHtmlEasyPrinting::PreviewFile(const wxString
&htmlfile
)
622 wxHtmlPrintout
*p1
= CreatePrintout();
623 p1
->SetHtmlFile(htmlfile
);
624 wxHtmlPrintout
*p2
= CreatePrintout();
625 p2
->SetHtmlFile(htmlfile
);
626 return DoPreview(p1
, p2
);
631 bool wxHtmlEasyPrinting::PreviewText(const wxString
&htmltext
, const wxString
&basepath
)
633 wxHtmlPrintout
*p1
= CreatePrintout();
634 p1
->SetHtmlText(htmltext
, basepath
, true);
635 wxHtmlPrintout
*p2
= CreatePrintout();
636 p2
->SetHtmlText(htmltext
, basepath
, true);
637 return DoPreview(p1
, p2
);
642 bool wxHtmlEasyPrinting::PrintFile(const wxString
&htmlfile
)
644 wxHtmlPrintout
*p
= CreatePrintout();
645 p
->SetHtmlFile(htmlfile
);
646 bool ret
= DoPrint(p
);
653 bool wxHtmlEasyPrinting::PrintText(const wxString
&htmltext
, const wxString
&basepath
)
655 wxHtmlPrintout
*p
= CreatePrintout();
656 p
->SetHtmlText(htmltext
, basepath
, true);
657 bool ret
= DoPrint(p
);
664 bool wxHtmlEasyPrinting::DoPreview(wxHtmlPrintout
*printout1
, wxHtmlPrintout
*printout2
)
666 // Pass two printout objects: for preview, and possible printing.
667 wxPrintDialogData
printDialogData(*GetPrintData());
668 wxPrintPreview
*preview
= new wxPrintPreview(printout1
, printout2
, &printDialogData
);
675 wxPreviewFrame
*frame
= new wxPreviewFrame(preview
, m_ParentWindow
,
676 m_Name
+ _(" Preview"),
677 wxPoint(100, 100), wxSize(650, 500));
678 frame
->Centre(wxBOTH
);
686 bool wxHtmlEasyPrinting::DoPrint(wxHtmlPrintout
*printout
)
688 wxPrintDialogData
printDialogData(*GetPrintData());
689 wxPrinter
printer(&printDialogData
);
691 if (!printer
.Print(m_ParentWindow
, printout
, true))
696 (*GetPrintData()) = printer
.GetPrintDialogData().GetPrintData();
703 void wxHtmlEasyPrinting::PageSetup()
705 if (!GetPrintData()->Ok())
707 wxLogError(_("There was a problem during page setup: you may need to set a default printer."));
711 m_PageSetupData
->SetPrintData(*GetPrintData());
712 wxPageSetupDialog
pageSetupDialog(m_ParentWindow
, m_PageSetupData
);
714 if (pageSetupDialog
.ShowModal() == wxID_OK
)
716 (*GetPrintData()) = pageSetupDialog
.GetPageSetupData().GetPrintData();
717 (*m_PageSetupData
) = pageSetupDialog
.GetPageSetupData();
723 void wxHtmlEasyPrinting::SetHeader(const wxString
& header
, int pg
)
725 if (pg
== wxPAGE_ALL
|| pg
== wxPAGE_EVEN
)
726 m_Headers
[0] = header
;
727 if (pg
== wxPAGE_ALL
|| pg
== wxPAGE_ODD
)
728 m_Headers
[1] = header
;
733 void wxHtmlEasyPrinting::SetFooter(const wxString
& footer
, int pg
)
735 if (pg
== wxPAGE_ALL
|| pg
== wxPAGE_EVEN
)
736 m_Footers
[0] = footer
;
737 if (pg
== wxPAGE_ALL
|| pg
== wxPAGE_ODD
)
738 m_Footers
[1] = footer
;
742 void wxHtmlEasyPrinting::SetFonts(const wxString
& normal_face
, const wxString
& fixed_face
,
745 m_fontMode
= FontMode_Explicit
;
746 m_FontFaceNormal
= normal_face
;
747 m_FontFaceFixed
= fixed_face
;
751 m_FontsSizes
= m_FontsSizesArr
;
752 for (int i
= 0; i
< 7; i
++) m_FontsSizes
[i
] = sizes
[i
];
758 void wxHtmlEasyPrinting::SetStandardFonts(int size
,
759 const wxString
& normal_face
,
760 const wxString
& fixed_face
)
762 m_fontMode
= FontMode_Standard
;
763 m_FontFaceNormal
= normal_face
;
764 m_FontFaceFixed
= fixed_face
;
765 m_FontsSizesArr
[0] = size
;
769 wxHtmlPrintout
*wxHtmlEasyPrinting::CreatePrintout()
771 wxHtmlPrintout
*p
= new wxHtmlPrintout(m_Name
);
773 if (m_fontMode
== FontMode_Explicit
)
775 p
->SetFonts(m_FontFaceNormal
, m_FontFaceFixed
, m_FontsSizes
);
777 else // FontMode_Standard
779 p
->SetStandardFonts(m_FontsSizesArr
[0],
780 m_FontFaceNormal
, m_FontFaceFixed
);
783 p
->SetHeader(m_Headers
[0], wxPAGE_EVEN
);
784 p
->SetHeader(m_Headers
[1], wxPAGE_ODD
);
785 p
->SetFooter(m_Footers
[0], wxPAGE_EVEN
);
786 p
->SetFooter(m_Footers
[1], wxPAGE_ODD
);
788 p
->SetMargins(m_PageSetupData
->GetMarginTopLeft().y
,
789 m_PageSetupData
->GetMarginBottomRight().y
,
790 m_PageSetupData
->GetMarginTopLeft().x
,
791 m_PageSetupData
->GetMarginBottomRight().x
);
796 // A module to allow initialization/cleanup
797 // without calling these functions from app.cpp or from
798 // the user's application.
800 class wxHtmlPrintingModule
: public wxModule
802 DECLARE_DYNAMIC_CLASS(wxHtmlPrintingModule
)
804 wxHtmlPrintingModule() : wxModule() {}
805 bool OnInit() { return true; }
806 void OnExit() { wxHtmlPrintout::CleanUpStatics(); }
809 IMPLEMENT_DYNAMIC_CLASS(wxHtmlPrintingModule
, wxModule
)
812 // This hack forces the linker to always link in m_* files
813 // (wxHTML doesn't work without handlers from these files)
814 #include "wx/html/forcelnk.h"
815 FORCE_WXHTML_MODULES()
817 #endif // wxUSE_HTML & wxUSE_PRINTING_ARCHITECTURE