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