]>
Commit | Line | Data |
---|---|---|
23324ae1 FM |
1 | ///////////////////////////////////////////////////////////////////////////// |
2 | // Name: html/htmprint.h | |
e54c96f1 | 3 | // Purpose: interface of wxHtmlDCRenderer |
23324ae1 FM |
4 | // Author: wxWidgets team |
5 | // RCS-ID: $Id$ | |
526954c5 | 6 | // Licence: wxWindows licence |
23324ae1 FM |
7 | ///////////////////////////////////////////////////////////////////////////// |
8 | ||
9 | /** | |
10 | @class wxHtmlDCRenderer | |
7c913512 | 11 | |
5bddd46d FM |
12 | This class can render HTML document into a specified area of a DC. |
13 | You can use it in your own printing code, although use of wxHtmlEasyPrinting | |
23324ae1 | 14 | or wxHtmlPrintout is strongly recommended. |
7c913512 | 15 | |
23324ae1 | 16 | @library{wxhtml} |
5bddd46d | 17 | @category{html} |
23324ae1 FM |
18 | */ |
19 | class wxHtmlDCRenderer : public wxObject | |
20 | { | |
21 | public: | |
22 | /** | |
23 | Constructor. | |
24 | */ | |
25 | wxHtmlDCRenderer(); | |
26 | ||
27 | /** | |
4209475c VZ |
28 | Returns the width of the HTML text in pixels. |
29 | ||
30 | This can be compared with the width parameter of SetSize() to check if | |
31 | the document being printed fits into the page boundary. | |
32 | ||
33 | @see GetTotalHeight() | |
34 | ||
35 | @since 2.9.0 | |
36 | */ | |
37 | int GetTotalWidth() const; | |
38 | ||
39 | /** | |
40 | Returns the height of the HTML text in pixels. | |
41 | ||
42 | This is important if area height (see wxHtmlDCRenderer::SetSize) is | |
43 | smaller that total height and thus the page cannot fit into it. In that | |
44 | case you're supposed to call Render() as long as its return value is | |
45 | smaller than GetTotalHeight()'s. | |
46 | ||
47 | @see GetTotalWidth() | |
23324ae1 | 48 | */ |
4209475c | 49 | int GetTotalHeight() const; |
23324ae1 FM |
50 | |
51 | /** | |
52 | Renders HTML text to the DC. | |
5bddd46d | 53 | |
7c913512 | 54 | @param x,y |
f21dd16b FM |
55 | position of upper-left corner of printing rectangle (see SetSize()). |
56 | @param known_pagebreaks | |
57 | @todo docme | |
7c913512 | 58 | @param from |
f21dd16b | 59 | y-coordinate of the very first visible cell. |
7c913512 | 60 | @param dont_render |
4cc4bfaf | 61 | if @true then this method only returns y coordinate of the next page |
f21dd16b FM |
62 | and does not output anything. |
63 | @param to | |
64 | y-coordinate of the last visible cell. | |
5bddd46d FM |
65 | |
66 | Returned value is y coordinate of first cell than didn't fit onto page. | |
131fc120 VS |
67 | Use this value as from in next call to Render() in order to print |
68 | multipages document. | |
5bddd46d | 69 | |
131fc120 VS |
70 | @note |
71 | The following three methods @b must always be called before any call to | |
72 | Render(), in this order: | |
5bddd46d FM |
73 | - SetDC() |
74 | - SetSize() | |
75 | - SetHtmlText() | |
131fc120 VS |
76 | |
77 | @note Render() changes the DC's user scale and does NOT restore it. | |
23324ae1 | 78 | */ |
5267aefd | 79 | int Render(int x, int y, wxArrayInt& known_pagebreaks, int from = 0, |
a44f3b5a | 80 | int dont_render = false, int to = INT_MAX); |
23324ae1 FM |
81 | |
82 | /** | |
83 | Assign DC instance to the renderer. | |
5bddd46d | 84 | |
4cc4bfaf | 85 | @a pixel_scale can be used when rendering to high-resolution DCs (e.g. printer) |
23324ae1 | 86 | to adjust size of pixel metrics. |
5bddd46d FM |
87 | (Many dimensions in HTML are given in pixels -- e.g. image sizes. 300x300 |
88 | image would be only one inch wide on typical printer. With pixel_scale = 3.0 | |
89 | it would be 3 inches.) | |
23324ae1 | 90 | */ |
4cc4bfaf | 91 | void SetDC(wxDC* dc, double pixel_scale = 1.0); |
23324ae1 FM |
92 | |
93 | /** | |
e37870dd VZ |
94 | This function sets font sizes and faces. |
95 | ||
96 | @param normal_face | |
97 | This is face name for normal (i.e. non-fixed) font. | |
98 | It can be either empty string (then the default face is chosen) or | |
99 | platform-specific face name. Examples are "helvetica" under Unix or | |
100 | "Times New Roman" under Windows. | |
101 | @param fixed_face | |
102 | The same thing for fixed face ( \<TT\>..\</TT\> ) | |
103 | @param sizes | |
104 | This is an array of 7 items of int type. | |
105 | The values represent size of font with HTML size from -2 to +4 | |
106 | ( \<FONT SIZE=-2\> to \<FONT SIZE=+4\> ). | |
107 | Default sizes are used if sizes is @NULL. | |
108 | ||
109 | Default font sizes are defined by constants wxHTML_FONT_SIZE_1, | |
110 | wxHTML_FONT_SIZE_2, ..., wxHTML_FONT_SIZE_7. | |
111 | Note that they differ among platforms. Default face names are empty strings. | |
5bddd46d FM |
112 | |
113 | @see SetSize() | |
23324ae1 | 114 | */ |
5267aefd FM |
115 | void SetFonts(const wxString& normal_face, const wxString& fixed_face, |
116 | const int* sizes = NULL); | |
23324ae1 | 117 | |
e37870dd VZ |
118 | /** |
119 | Sets font sizes to be relative to the given size or the system | |
120 | default size; use either specified or default font | |
121 | ||
122 | @param size | |
123 | Point size of the default HTML text | |
124 | @param normal_face | |
125 | This is face name for normal (i.e. non-fixed) font. It can be | |
126 | either empty string (then the default face is chosen) or | |
127 | platform-specific face name. Examples are "helvetica" under | |
128 | Unix or "Times New Roman" under Windows. | |
129 | @param fixed_face | |
130 | The same thing for fixed face ( \<TT\>..\</TT\> ) | |
131 | ||
132 | @see SetSize() | |
133 | */ | |
134 | void SetStandardFonts(int size = -1, | |
135 | const wxString& normal_face = wxEmptyString, | |
136 | const wxString& fixed_face = wxEmptyString); | |
137 | ||
23324ae1 | 138 | /** |
5bddd46d FM |
139 | Assign text to the renderer. Render() then draws the text onto DC. |
140 | ||
7c913512 | 141 | @param html |
4cc4bfaf | 142 | HTML text. This is not a filename. |
7c913512 | 143 | @param basepath |
5bddd46d FM |
144 | base directory (html string would be stored there if it was in file). |
145 | It is used to determine path for loading images, for example. | |
7c913512 | 146 | @param isdir |
4cc4bfaf | 147 | @false if basepath is filename, @true if it is directory name |
5bddd46d | 148 | (see wxFileSystem for detailed explanation). |
23324ae1 FM |
149 | */ |
150 | void SetHtmlText(const wxString& html, | |
151 | const wxString& basepath = wxEmptyString, | |
4cc4bfaf | 152 | bool isdir = true); |
23324ae1 FM |
153 | |
154 | /** | |
155 | Set size of output rectangle, in pixels. Note that you @b can't change | |
e37870dd | 156 | width of the rectangle between calls to Render() ! |
23324ae1 FM |
157 | (You can freely change height.) |
158 | */ | |
159 | void SetSize(int width, int height); | |
160 | }; | |
161 | ||
162 | ||
e54c96f1 | 163 | |
23324ae1 FM |
164 | /** |
165 | @class wxHtmlEasyPrinting | |
7c913512 | 166 | |
5bddd46d FM |
167 | This class provides very simple interface to printing architecture. |
168 | It allows you to print HTML documents using only a few commands. | |
169 | ||
170 | @note | |
171 | Do not create this class on the stack only. You should create an instance | |
172 | on app startup and use this instance for all printing operations. | |
173 | The reason is that this class stores various settings in it. | |
7c913512 | 174 | |
23324ae1 | 175 | @library{wxhtml} |
5bddd46d | 176 | @category{html,printing} |
23324ae1 FM |
177 | */ |
178 | class wxHtmlEasyPrinting : public wxObject | |
179 | { | |
180 | public: | |
181 | /** | |
182 | Constructor. | |
5bddd46d | 183 | |
7c913512 | 184 | @param name |
4cc4bfaf | 185 | Name of the printing object. Used by preview frames and setup dialogs. |
7c913512 | 186 | @param parentWindow |
4cc4bfaf | 187 | pointer to the window that will own the preview frame and setup dialogs. |
5bddd46d | 188 | May be @NULL. |
23324ae1 FM |
189 | */ |
190 | wxHtmlEasyPrinting(const wxString& name = "Printing", | |
4cc4bfaf | 191 | wxWindow* parentWindow = NULL); |
23324ae1 | 192 | |
0678e935 BP |
193 | /** |
194 | Returns the current name being used for preview frames and setup | |
195 | dialogs. | |
196 | ||
197 | @since 2.8.11 / 2.9.1 | |
198 | */ | |
199 | const wxString& GetName() const; | |
200 | ||
23324ae1 | 201 | /** |
5bddd46d FM |
202 | Returns a pointer to wxPageSetupDialogData instance used by this class. |
203 | You can set its parameters (via SetXXXX methods). | |
23324ae1 FM |
204 | */ |
205 | wxPageSetupDialogData* GetPageSetupData(); | |
206 | ||
207 | /** | |
208 | Gets the parent window for dialogs. | |
209 | */ | |
328f5751 | 210 | wxWindow* GetParentWindow() const; |
23324ae1 FM |
211 | |
212 | /** | |
5bddd46d FM |
213 | Returns pointer to wxPrintData instance used by this class. |
214 | You can set its parameters (via SetXXXX methods). | |
23324ae1 FM |
215 | */ |
216 | wxPrintData* GetPrintData(); | |
217 | ||
218 | /** | |
219 | Display page setup dialog and allows the user to modify settings. | |
220 | */ | |
221 | void PageSetup(); | |
222 | ||
223 | /** | |
7c913512 | 224 | Preview HTML file. |
5bddd46d FM |
225 | |
226 | Returns @false in case of error -- call wxPrinter::GetLastError to get detailed | |
23324ae1 FM |
227 | information about the kind of the error. |
228 | */ | |
229 | bool PreviewFile(const wxString& htmlfile); | |
230 | ||
231 | /** | |
7c913512 | 232 | Preview HTML text (not file!). |
5bddd46d FM |
233 | |
234 | Returns @false in case of error -- call wxPrinter::GetLastError to get detailed | |
23324ae1 | 235 | information about the kind of the error. |
5bddd46d | 236 | |
7c913512 | 237 | @param htmltext |
4cc4bfaf | 238 | HTML text. |
7c913512 | 239 | @param basepath |
5bddd46d FM |
240 | base directory (html string would be stored there if it was in file). |
241 | It is used to determine path for loading images, for example. | |
23324ae1 FM |
242 | */ |
243 | bool PreviewText(const wxString& htmltext, | |
244 | const wxString& basepath = wxEmptyString); | |
245 | ||
246 | /** | |
247 | Print HTML file. | |
5bddd46d FM |
248 | |
249 | Returns @false in case of error -- call wxPrinter::GetLastError to get detailed | |
23324ae1 FM |
250 | information about the kind of the error. |
251 | */ | |
252 | bool PrintFile(const wxString& htmlfile); | |
253 | ||
254 | /** | |
7c913512 | 255 | Print HTML text (not file!). |
5bddd46d FM |
256 | |
257 | Returns @false in case of error -- call wxPrinter::GetLastError to get detailed | |
23324ae1 | 258 | information about the kind of the error. |
5bddd46d | 259 | |
7c913512 | 260 | @param htmltext |
4cc4bfaf | 261 | HTML text. |
7c913512 | 262 | @param basepath |
5bddd46d FM |
263 | base directory (html string would be stored there if it was in file). |
264 | It is used to determine path for loading images, for example. | |
23324ae1 FM |
265 | */ |
266 | bool PrintText(const wxString& htmltext, | |
267 | const wxString& basepath = wxEmptyString); | |
268 | ||
269 | /** | |
e37870dd | 270 | Sets fonts. See wxHtmlDCRenderer::SetFonts for detailed description. |
23324ae1 | 271 | */ |
5267aefd FM |
272 | void SetFonts(const wxString& normal_face, const wxString& fixed_face, |
273 | const int* sizes = NULL); | |
e37870dd | 274 | |
0678e935 BP |
275 | /** |
276 | Sets the name used for preview frames and setup dialogs. | |
277 | ||
278 | @since 2.8.11 / 2.9.1 | |
279 | */ | |
280 | void SetName(const wxString& name); | |
281 | ||
e37870dd VZ |
282 | /** |
283 | Sets default font sizes and/or default font size. | |
284 | See wxHtmlDCRenderer::SetStandardFonts for detailed description. | |
285 | @see SetFonts() | |
286 | */ | |
287 | void SetStandardFonts(int size = -1, | |
288 | const wxString& normal_face = wxEmptyString, | |
289 | const wxString& fixed_face = wxEmptyString); | |
23324ae1 FM |
290 | |
291 | /** | |
292 | Set page footer. The following macros can be used inside it: | |
2f663107 VZ |
293 | @@DATE@ is replaced by the current date in default format |
294 | @@PAGENUM@ is replaced by page number | |
295 | @@PAGESCNT@ is replaced by total number of pages | |
296 | @@TIME@ is replaced by the current time in default format | |
297 | @@TITLE@ is replaced with the title of the document | |
5bddd46d | 298 | |
7c913512 | 299 | @param footer |
4cc4bfaf | 300 | HTML text to be used as footer. |
7c913512 | 301 | @param pg |
4cc4bfaf | 302 | one of wxPAGE_ODD, wxPAGE_EVEN and wxPAGE_ALL constants. |
23324ae1 FM |
303 | */ |
304 | void SetFooter(const wxString& footer, int pg = wxPAGE_ALL); | |
305 | ||
306 | /** | |
307 | Set page header. The following macros can be used inside it: | |
5bddd46d FM |
308 | - @@DATE@ is replaced by the current date in default format |
309 | - @@PAGENUM@ is replaced by page number | |
310 | - @@PAGESCNT@ is replaced by total number of pages | |
311 | - @@TIME@ is replaced by the current time in default format | |
312 | - @@TITLE@ is replaced with the title of the document | |
313 | ||
7c913512 | 314 | @param header |
4cc4bfaf | 315 | HTML text to be used as header. |
7c913512 | 316 | @param pg |
4cc4bfaf | 317 | one of wxPAGE_ODD, wxPAGE_EVEN and wxPAGE_ALL constants. |
23324ae1 FM |
318 | */ |
319 | void SetHeader(const wxString& header, int pg = wxPAGE_ALL); | |
320 | ||
321 | /** | |
322 | Sets the parent window for dialogs. | |
323 | */ | |
324 | void SetParentWindow(wxWindow* window); | |
4209475c VZ |
325 | |
326 | private: | |
327 | /** | |
328 | Check whether the document fits into the page area. | |
329 | ||
330 | This function is called by the base class OnPreparePrinting() | |
331 | implementation and by default checks whether the document fits into | |
332 | @a pageArea horizontally and warns the user if it does not, giving him | |
333 | the possibility to cancel printing in this case (presumably in order to | |
334 | change some layout options and retry it again). | |
335 | ||
336 | You may override it to either suppress this check if truncation of the | |
337 | HTML being printed is acceptable or, on the contrary, add more checks to | |
338 | it, e.g. for the fit in the vertical direction if the document should | |
339 | always appear on a single page. | |
340 | ||
341 | @return | |
342 | @true if wxHtmlPrintout should continue or @false to cancel | |
343 | printing. | |
344 | ||
345 | @since 2.9.0 | |
346 | */ | |
347 | virtual bool CheckFit(const wxSize& pageArea, const wxSize& docArea) const; | |
23324ae1 FM |
348 | }; |
349 | ||
350 | ||
e54c96f1 | 351 | |
23324ae1 FM |
352 | /** |
353 | @class wxHtmlPrintout | |
7c913512 | 354 | |
23324ae1 | 355 | This class serves as printout class for HTML documents. |
7c913512 | 356 | |
23324ae1 | 357 | @library{wxhtml} |
5bddd46d | 358 | @category{html,printing} |
23324ae1 FM |
359 | */ |
360 | class wxHtmlPrintout : public wxPrintout | |
361 | { | |
362 | public: | |
363 | /** | |
364 | Constructor. | |
365 | */ | |
366 | wxHtmlPrintout(const wxString& title = "Printout"); | |
367 | ||
368 | /** | |
5bddd46d FM |
369 | Adds a filter to the static list of filters for wxHtmlPrintout. |
370 | See wxHtmlFilter for further information. | |
23324ae1 FM |
371 | */ |
372 | static void AddFilter(wxHtmlFilter* filter); | |
373 | ||
374 | /** | |
e37870dd VZ |
375 | This function sets font sizes and faces. See wxHtmlWindow::SetFonts |
376 | for detailed description. | |
23324ae1 | 377 | */ |
5267aefd FM |
378 | void SetFonts(const wxString& normal_face, const wxString& fixed_face, |
379 | const int* sizes = NULL); | |
23324ae1 FM |
380 | |
381 | /** | |
382 | Set page footer. The following macros can be used inside it: | |
5bddd46d FM |
383 | - @@DATE@ is replaced by the current date in default format |
384 | - @@PAGENUM@ is replaced by page number | |
385 | - @@PAGESCNT@ is replaced by total number of pages | |
386 | - @@TIME@ is replaced by the current time in default format | |
387 | - @@TITLE@ is replaced with the title of the document | |
388 | ||
7c913512 | 389 | @param footer |
4cc4bfaf | 390 | HTML text to be used as footer. |
7c913512 | 391 | @param pg |
4cc4bfaf | 392 | one of wxPAGE_ODD, wxPAGE_EVEN and wxPAGE_ALL constants. |
23324ae1 FM |
393 | */ |
394 | void SetFooter(const wxString& footer, int pg = wxPAGE_ALL); | |
395 | ||
396 | /** | |
397 | Set page header. The following macros can be used inside it: | |
5bddd46d FM |
398 | - @@DATE@ is replaced by the current date in default format |
399 | - @@PAGENUM@ is replaced by page number | |
400 | - @@PAGESCNT@ is replaced by total number of pages | |
401 | - @@TIME@ is replaced by the current time in default format | |
402 | - @@TITLE@ is replaced with the title of the document | |
403 | ||
7c913512 | 404 | @param header |
4cc4bfaf | 405 | HTML text to be used as header. |
7c913512 | 406 | @param pg |
4cc4bfaf | 407 | one of wxPAGE_ODD, wxPAGE_EVEN and wxPAGE_ALL constants. |
23324ae1 FM |
408 | */ |
409 | void SetHeader(const wxString& header, int pg = wxPAGE_ALL); | |
410 | ||
411 | /** | |
5bddd46d FM |
412 | Prepare the class for printing this HTML @b file. |
413 | The file may be located on any virtual file system or it may be normal file. | |
23324ae1 FM |
414 | */ |
415 | void SetHtmlFile(const wxString& htmlfile); | |
416 | ||
417 | /** | |
418 | Prepare the class for printing this HTML text. | |
5bddd46d | 419 | |
7c913512 | 420 | @param html |
4cc4bfaf | 421 | HTML text. (NOT file!) |
7c913512 | 422 | @param basepath |
5bddd46d FM |
423 | base directory (html string would be stored there if it was in file). |
424 | It is used to determine path for loading images, for example. | |
7c913512 | 425 | @param isdir |
4cc4bfaf | 426 | @false if basepath is filename, @true if it is directory name |
5bddd46d | 427 | (see wxFileSystem for detailed explanation). |
23324ae1 FM |
428 | */ |
429 | void SetHtmlText(const wxString& html, | |
430 | const wxString& basepath = wxEmptyString, | |
4cc4bfaf | 431 | bool isdir = true); |
23324ae1 FM |
432 | |
433 | /** | |
5bddd46d FM |
434 | Sets margins in millimeters. |
435 | Defaults to 1 inch for margins and 0.5cm for space between text and header | |
436 | and/or footer. | |
23324ae1 FM |
437 | */ |
438 | void SetMargins(float top = 25.2, float bottom = 25.2, | |
439 | float left = 25.2, | |
440 | float right = 25.2, | |
441 | float spaces = 5); | |
442 | }; | |
e54c96f1 | 443 |