]> git.saurik.com Git - wxWidgets.git/blob - include/wx/html/htmprint.h
added wxImage::ConvertAlphaToMask
[wxWidgets.git] / include / wx / html / htmprint.h
1 /////////////////////////////////////////////////////////////////////////////
2 // Name: htmprint.h
3 // Purpose: html printing classes
4 // Author: Vaclav Slavik
5 // Created: 25/09/99
6 // RCS-ID: $Id$
7 // Copyright: (c)
8 // Licence: wxWindows licence
9 /////////////////////////////////////////////////////////////////////////////
10
11 #ifndef _WX_HTMPRINT_H_
12 #define _WX_HTMPRINT_H_
13
14 #if defined(__GNUG__) && !defined(NO_GCC_PRAGMA)
15 #pragma interface "htmprint.h"
16 #endif
17
18 #include "wx/defs.h"
19
20 #if wxUSE_HTML & wxUSE_PRINTING_ARCHITECTURE
21
22 #include "wx/html/htmlcell.h"
23 #include "wx/html/winpars.h"
24 #include "wx/html/htmlfilt.h"
25
26 #include "wx/print.h"
27 #include "wx/printdlg.h"
28
29 #include <limits.h> // INT_MAX
30
31 //--------------------------------------------------------------------------------
32 // wxHtmlDCRenderer
33 // This class is capable of rendering HTML into specified
34 // portion of DC
35 //--------------------------------------------------------------------------------
36
37 class WXDLLIMPEXP_HTML wxHtmlDCRenderer : public wxObject
38 {
39 public:
40 wxHtmlDCRenderer();
41 ~wxHtmlDCRenderer();
42
43 // Following 3 methods *must* be called before any call to Render:
44
45 // Assign DC to this render
46 void SetDC(wxDC *dc, double pixel_scale = 1.0);
47
48 // Sets size of output rectangle, in pixels. Note that you *can't* change
49 // width of the rectangle between calls to Render! (You can freely change height.)
50 void SetSize(int width, int height);
51
52 // Sets the text to be displayed.
53 // Basepath is base directory (html string would be stored there if it was in
54 // file). It is used to determine path for loading images, for example.
55 // isdir is FALSE if basepath is filename, TRUE if it is directory name
56 // (see wxFileSystem for detailed explanation)
57 void SetHtmlText(const wxString& html, const wxString& basepath = wxEmptyString, bool isdir = TRUE);
58
59 // Sets fonts to be used when displaying HTML page. (if size null then default sizes used).
60 void SetFonts(wxString normal_face, wxString fixed_face, const int *sizes = NULL);
61
62 // Sets font sizes to be relative to the given size or the system default size
63 void NormalizeFontSizes(int size=-1);
64
65 // [x,y] is position of upper-left corner of printing rectangle (see SetSize)
66 // from is y-coordinate of the very first visible cell
67 // to is y-coordinate of the next following page break, if any
68 // Returned value is y coordinate of first cell than didn't fit onto page.
69 // Use this value as 'from' in next call to Render in order to print multiple pages
70 // document
71 // If dont_render is TRUE then nothing is rendered into DC and it only counts
72 // pixels and return y coord of the next page
73 //
74 // known_pagebreaks and number_of_pages are used only when counting pages;
75 // otherwise, their default values should be used. Their purpose is to
76 // support pagebreaks using a subset of CSS2's <DIV>. The <DIV> handler
77 // needs to know what pagebreaks have already been set so that it doesn't
78 // set the same pagebreak twice.
79 //
80 // CAUTION! Render() changes DC's user scale and does NOT restore it!
81 int Render(int x, int y, int from = 0, int dont_render = FALSE, int to = INT_MAX,
82 int *known_pagebreaks = NULL, int number_of_pages = 0);
83
84 // returns total height of the html document
85 // (compare Render's return value with this)
86 int GetTotalHeight();
87
88 private:
89 wxDC *m_DC;
90 wxHtmlWinParser *m_Parser;
91 wxFileSystem *m_FS;
92 wxHtmlContainerCell *m_Cells;
93 int m_MaxWidth, m_Width, m_Height;
94
95 DECLARE_NO_COPY_CLASS(wxHtmlDCRenderer)
96 };
97
98
99
100
101
102 enum {
103 wxPAGE_ODD,
104 wxPAGE_EVEN,
105 wxPAGE_ALL
106 };
107
108
109
110 //--------------------------------------------------------------------------------
111 // wxHtmlPrintout
112 // This class is derived from standard wxWidgets printout class
113 // and is used to print HTML documents.
114 //--------------------------------------------------------------------------------
115
116
117 class WXDLLIMPEXP_HTML wxHtmlPrintout : public wxPrintout
118 {
119 public:
120 wxHtmlPrintout(const wxString& title = wxT("Printout"));
121 ~wxHtmlPrintout();
122
123 void SetHtmlText(const wxString& html, const wxString &basepath = wxEmptyString, bool isdir = TRUE);
124 // prepares the class for printing this html document.
125 // Must be called before using the class, in fact just after constructor
126 //
127 // basepath is base directory (html string would be stored there if it was in
128 // file). It is used to determine path for loading images, for example.
129 // isdir is FALSE if basepath is filename, TRUE if it is directory name
130 // (see wxFileSystem for detailed explanation)
131
132 void SetHtmlFile(const wxString &htmlfile);
133 // same as SetHtmlText except that it takes regular file as the parameter
134
135 void SetHeader(const wxString& header, int pg = wxPAGE_ALL);
136 void SetFooter(const wxString& footer, int pg = wxPAGE_ALL);
137 // sets header/footer for the document. The argument is interpreted as HTML document.
138 // You can use macros in it:
139 // @PAGENUM@ is replaced by page number
140 // @PAGESCNT@ is replaced by total number of pages
141 //
142 // pg is one of wxPAGE_ODD, wxPAGE_EVEN and wx_PAGE_ALL constants.
143 // You can set different header/footer for odd and even pages
144
145 // Sets fonts to be used when displaying HTML page. (if size null then default sizes used).
146 void SetFonts(wxString normal_face, wxString fixed_face, const int *sizes = NULL);
147
148 // Sets font sizes to be relative to the given size or the system default size
149 void NormalizeFontSizes(int size=-1);
150
151 void SetMargins(float top = 25.2, float bottom = 25.2, float left = 25.2, float right = 25.2,
152 float spaces = 5);
153 // sets margins in milimeters. Defaults to 1 inch for margins and 0.5cm for space
154 // between text and header and/or footer
155
156 // wxPrintout stuff:
157 bool OnPrintPage(int page);
158 bool HasPage(int page);
159 void GetPageInfo(int *minPage, int *maxPage, int *selPageFrom, int *selPageTo);
160 bool OnBeginDocument(int startPage, int endPage);
161 void OnPreparePrinting();
162
163 // Adds input filter
164 static void AddFilter(wxHtmlFilter *filter);
165
166 // Cleanup
167 static void CleanUpStatics();
168
169 private:
170
171 void RenderPage(wxDC *dc, int page);
172 // renders one page into dc
173 wxString TranslateHeader(const wxString& instr, int page);
174 // substitute @PAGENUM@ and @PAGESCNT@ by real values
175 void CountPages();
176 // counts pages and fills m_NumPages and m_PageBreaks
177
178
179 private:
180 int m_NumPages;
181 int m_PageBreaks[wxHTML_PRINT_MAX_PAGES];
182
183 wxString m_Document, m_BasePath;
184 bool m_BasePathIsDir;
185 wxString m_Headers[2], m_Footers[2];
186
187 int m_HeaderHeight, m_FooterHeight;
188 wxHtmlDCRenderer *m_Renderer, *m_RendererHdr;
189 float m_MarginTop, m_MarginBottom, m_MarginLeft, m_MarginRight, m_MarginSpace;
190
191 // list of HTML filters
192 static wxList m_Filters;
193
194 DECLARE_NO_COPY_CLASS(wxHtmlPrintout)
195 };
196
197
198
199
200
201 //--------------------------------------------------------------------------------
202 // wxHtmlEasyPrinting
203 // This class provides very simple interface to printing
204 // architecture. It allows you to print HTML documents only
205 // with very few commands.
206 //
207 // Note : do not create this class on stack only.
208 // You should create an instance on app startup and
209 // use this instance for all printing. Why? The class
210 // stores page&printer settings in it.
211 //--------------------------------------------------------------------------------
212
213 class WXDLLIMPEXP_HTML wxHtmlEasyPrinting : public wxObject
214 {
215 public:
216 wxHtmlEasyPrinting(const wxString& name = wxT("Printing"), wxWindow *parentWindow = NULL);
217 ~wxHtmlEasyPrinting();
218
219 bool PreviewFile(const wxString &htmlfile);
220 bool PreviewText(const wxString &htmltext, const wxString& basepath = wxEmptyString);
221 // Preview file / html-text for printing
222 // (and offers printing)
223 // basepath is base directory for opening subsequent files (e.g. from <img> tag)
224
225 bool PrintFile(const wxString &htmlfile);
226 bool PrintText(const wxString &htmltext, const wxString& basepath = wxEmptyString);
227 // Print file / html-text w/o preview
228
229 void PrinterSetup();
230 void PageSetup();
231 // pop up printer or page setup dialog
232
233 void SetHeader(const wxString& header, int pg = wxPAGE_ALL);
234 void SetFooter(const wxString& footer, int pg = wxPAGE_ALL);
235 // sets header/footer for the document. The argument is interpreted as HTML document.
236 // You can use macros in it:
237 // @PAGENUM@ is replaced by page number
238 // @PAGESCNT@ is replaced by total number of pages
239 //
240 // pg is one of wxPAGE_ODD, wxPAGE_EVEN and wx_PAGE_ALL constants.
241 // You can set different header/footer for odd and even pages
242
243 void SetFonts(wxString normal_face, wxString fixed_face, const int *sizes = 0);
244 // Sets fonts to be used when displaying HTML page. (if size null then default sizes used)
245
246 void NormalizeFontSizes(int size=-1);
247 // Sets font sizes to be relative to the given size or the system default size
248
249 wxPrintData *GetPrintData();
250 wxPageSetupDialogData *GetPageSetupData() {return m_PageSetupData;}
251 // return page setting data objects.
252 // (You can set their parameters.)
253
254 protected:
255 virtual wxHtmlPrintout *CreatePrintout();
256 virtual bool DoPreview(wxHtmlPrintout *printout1, wxHtmlPrintout *printout2);
257 virtual bool DoPrint(wxHtmlPrintout *printout);
258
259 private:
260 wxPrintData *m_PrintData;
261 wxPageSetupDialogData *m_PageSetupData;
262 wxString m_Name;
263 int m_FontsSizesArr[7];
264 int *m_FontsSizes;
265 wxString m_FontFaceFixed, m_FontFaceNormal;
266 wxString m_Headers[2], m_Footers[2];
267 wxWindow *m_ParentWindow;
268
269 DECLARE_NO_COPY_CLASS(wxHtmlEasyPrinting)
270 };
271
272
273
274
275 #endif // wxUSE_HTML & wxUSE_PRINTING_ARCHITECTURE
276
277 #endif // _WX_HTMPRINT_H_
278