1 /////////////////////////////////////////////////////////////////////////////
3 // Purpose: html printing classes
4 // Author: Vaclav Slavik
8 // Licence: wxWindows licence
9 /////////////////////////////////////////////////////////////////////////////
11 #ifndef _WX_HTMPRINT_H_
12 #define _WX_HTMPRINT_H_
14 #if defined(__GNUG__) && !defined(__APPLE__)
15 #pragma interface "htmprint.h"
20 #if wxUSE_HTML & wxUSE_PRINTING_ARCHITECTURE
22 #include "wx/html/htmlcell.h"
23 #include "wx/html/winpars.h"
26 #include "wx/printdlg.h"
28 //--------------------------------------------------------------------------------
30 // This class is capable of rendering HTML into specified
32 //--------------------------------------------------------------------------------
34 class WXDLLEXPORT wxHtmlDCRenderer
: public wxObject
40 // Following 3 methods *must* be called before any call to Render:
42 // Asign DC to this render
43 void SetDC(wxDC
*dc
, double pixel_scale
= 1.0);
45 // Sets size of output rectangle, in pixels. Note that you *can't* change
46 // width of the rectangle between calls to Render! (You can freely change height.)
47 void SetSize(int width
, int height
);
49 // Sets the text to be displayed.
50 // Basepath is base directory (html string would be stored there if it was in
51 // file). It is used to determine path for loading images, for example.
52 // isdir is FALSE if basepath is filename, TRUE if it is directory name
53 // (see wxFileSystem for detailed explanation)
54 void SetHtmlText(const wxString
& html
, const wxString
& basepath
= wxEmptyString
, bool isdir
= TRUE
);
56 // Sets fonts to be used when displaying HTML page. (if size null then default sizes used).
57 void SetFonts(wxString normal_face
, wxString fixed_face
, const int *sizes
= NULL
);
59 // [x,y] is position of upper-left corner of printing rectangle (see SetSize)
60 // from is y-coordinate of the very first visible cell
61 // Returned value is y coordinate of first cell than didn't fit onto page.
62 // Use this value as 'from' in next call to Render in order to print multiple pages
64 // If dont_render is TRUE then nothing is rendered into DC and it only counts
65 // pixels and return y coord of the next page
67 // CAUTION! Render() changes DC's user scale and does NOT restore it!
68 int Render(int x
, int y
, int from
= 0, int dont_render
= FALSE
);
70 // returns total height of the html document
71 // (compare Render's return value with this)
76 wxHtmlWinParser
*m_Parser
;
78 wxHtmlContainerCell
*m_Cells
;
79 int m_MaxWidth
, m_Width
, m_Height
;
81 DECLARE_NO_COPY_CLASS(wxHtmlDCRenderer
)
96 //--------------------------------------------------------------------------------
98 // This class is derived from standard wxWindows printout class
99 // and is used to print HTML documents.
100 //--------------------------------------------------------------------------------
103 class WXDLLEXPORT wxHtmlPrintout
: public wxPrintout
106 wxHtmlPrintout(const wxString
& title
= wxT("Printout"));
109 void SetHtmlText(const wxString
& html
, const wxString
&basepath
= wxEmptyString
, bool isdir
= TRUE
);
110 // prepares the class for printing this html document.
111 // Must be called before using the class, in fact just after constructor
113 // basepath is base directory (html string would be stored there if it was in
114 // file). It is used to determine path for loading images, for example.
115 // isdir is FALSE if basepath is filename, TRUE if it is directory name
116 // (see wxFileSystem for detailed explanation)
118 void SetHtmlFile(const wxString
&htmlfile
);
119 // same as SetHtmlText except that it takes regular file as the parameter
121 void SetHeader(const wxString
& header
, int pg
= wxPAGE_ALL
);
122 void SetFooter(const wxString
& footer
, int pg
= wxPAGE_ALL
);
123 // sets header/footer for the document. The argument is interpreted as HTML document.
124 // You can use macros in it:
125 // @PAGENUM@ is replaced by page number
126 // @PAGESCNT@ is replaced by total number of pages
128 // pg is one of wxPAGE_ODD, wxPAGE_EVEN and wx_PAGE_ALL constants.
129 // You can set different header/footer for odd and even pages
131 // Sets fonts to be used when displaying HTML page. (if size null then default sizes used).
132 void SetFonts(wxString normal_face
, wxString fixed_face
, const int *sizes
= NULL
);
134 void SetMargins(float top
= 25.2, float bottom
= 25.2, float left
= 25.2, float right
= 25.2,
136 // sets margins in milimeters. Defaults to 1 inch for margins and 0.5cm for space
137 // between text and header and/or footer
140 bool OnPrintPage(int page
);
141 bool HasPage(int page
);
142 void GetPageInfo(int *minPage
, int *maxPage
, int *selPageFrom
, int *selPageTo
);
143 bool OnBeginDocument(int startPage
, int endPage
);
147 void RenderPage(wxDC
*dc
, int page
);
148 // renders one page into dc
149 wxString
TranslateHeader(const wxString
& instr
, int page
);
150 // substitute @PAGENUM@ and @PAGESCNT@ by real values
152 // counts pages and fills m_NumPages and m_PageBreaks
157 int m_PageBreaks
[wxHTML_PRINT_MAX_PAGES
];
159 wxString m_Document
, m_BasePath
;
160 bool m_BasePathIsDir
;
161 wxString m_Headers
[2], m_Footers
[2];
163 int m_HeaderHeight
, m_FooterHeight
;
164 wxHtmlDCRenderer
*m_Renderer
, *m_RendererHdr
;
165 float m_MarginTop
, m_MarginBottom
, m_MarginLeft
, m_MarginRight
, m_MarginSpace
;
167 DECLARE_NO_COPY_CLASS(wxHtmlPrintout
)
174 //--------------------------------------------------------------------------------
175 // wxHtmlEasyPrinting
176 // This class provides very simple interface to printing
177 // architecture. It allows you to print HTML documents only
178 // with very few commands.
180 // Note : do not create this class on stack only.
181 // You should create an instance on app startup and
182 // use this instance for all printing. Why? The class
183 // stores page&printer settings in it.
184 //--------------------------------------------------------------------------------
186 class WXDLLEXPORT wxHtmlEasyPrinting
: public wxObject
189 wxHtmlEasyPrinting(const wxString
& name
= wxT("Printing"), wxFrame
*parent_frame
= NULL
);
190 ~wxHtmlEasyPrinting();
192 bool PreviewFile(const wxString
&htmlfile
);
193 bool PreviewText(const wxString
&htmltext
, const wxString
& basepath
= wxEmptyString
);
194 // Preview file / html-text for printing
195 // (and offers printing)
196 // basepath is base directory for opening subsequent files (e.g. from <img> tag)
198 bool PrintFile(const wxString
&htmlfile
);
199 bool PrintText(const wxString
&htmltext
, const wxString
& basepath
= wxEmptyString
);
200 // Print file / html-text w/o preview
204 // pop up printer or page setup dialog
206 void SetHeader(const wxString
& header
, int pg
= wxPAGE_ALL
);
207 void SetFooter(const wxString
& footer
, int pg
= wxPAGE_ALL
);
208 // sets header/footer for the document. The argument is interpreted as HTML document.
209 // You can use macros in it:
210 // @PAGENUM@ is replaced by page number
211 // @PAGESCNT@ is replaced by total number of pages
213 // pg is one of wxPAGE_ODD, wxPAGE_EVEN and wx_PAGE_ALL constants.
214 // You can set different header/footer for odd and even pages
216 void SetFonts(wxString normal_face
, wxString fixed_face
, const int *sizes
= 0);
217 // Sets fonts to be used when displaying HTML page. (if size null then default sizes used)
219 wxPrintData
*GetPrintData() {return m_PrintData
;}
220 wxPageSetupDialogData
*GetPageSetupData() {return m_PageSetupData
;}
221 // return page setting data objects.
222 // (You can set their parameters.)
225 virtual wxHtmlPrintout
*CreatePrintout();
226 virtual bool DoPreview(wxHtmlPrintout
*printout1
, wxHtmlPrintout
*printout2
);
227 virtual bool DoPrint(wxHtmlPrintout
*printout
);
230 wxPrintData
*m_PrintData
;
231 wxPageSetupDialogData
*m_PageSetupData
;
233 int m_FontsSizesArr
[7];
235 wxString m_FontFaceFixed
, m_FontFaceNormal
;
236 wxString m_Headers
[2], m_Footers
[2];
239 DECLARE_NO_COPY_CLASS(wxHtmlEasyPrinting
)
245 #endif // wxUSE_HTML & wxUSE_PRINTING_ARCHITECTURE
247 #endif // _WX_HTMPRINT_H_