]> git.saurik.com Git - wxWidgets.git/blame - interface/font.h
pen.h depends from brush.h in compat mode
[wxWidgets.git] / interface / font.h
CommitLineData
23324ae1
FM
1/////////////////////////////////////////////////////////////////////////////
2// Name: font.h
e54c96f1 3// Purpose: interface of wxFont
23324ae1
FM
4// Author: wxWidgets team
5// RCS-ID: $Id$
6// Licence: wxWindows license
7/////////////////////////////////////////////////////////////////////////////
8
9/**
10 @class wxFont
11 @wxheader{font.h}
7c913512 12
23324ae1
FM
13 A font is an object which determines the appearance of text. Fonts are
14 used for drawing text to a device context, and setting the appearance of
15 a window's text.
7c913512 16
23324ae1
FM
17 This class uses @ref overview_trefcount "reference counting and copy-on-write"
18 internally so that assignments between two instances of this class are very
19 cheap. You can therefore use actual objects instead of pointers without
20 efficiency problems. If an instance of this class is changed it will create
21 its own data internally so that other instances, which previously shared the
22 data using the reference counting, are not affected.
7c913512 23
23324ae1 24 You can retrieve the current system font settings with wxSystemSettings.
7c913512 25
23324ae1 26 wxSystemSettings
7c913512 27
23324ae1
FM
28 @library{wxcore}
29 @category{gdi}
7c913512 30
23324ae1 31 @stdobjects
e54c96f1
FM
32 ::Objects:, ::wxNullFont, ::Pointers:, ::wxNORMAL_FONT, ::wxSMALL_FONT,
33 ::wxITALIC_FONT, ::wxSWISS_FONT,
7c913512 34
e54c96f1 35 @see @ref overview_wxfontoverview, wxDC::SetFont, wxDC::DrawText,
23324ae1
FM
36 wxDC::GetTextExtent, wxFontDialog, wxSystemSettings
37*/
38class wxFont : public wxGDIObject
39{
40public:
41 //@{
42 /**
43 Creates a font object with the specified attributes.
44
7c913512 45 @param pointSize
4cc4bfaf 46 Size in points.
7c913512 47 @param pixelSize
4cc4bfaf
FM
48 Size in pixels: this is directly supported only under MSW
49 currently where this constructor can be used directly, under other
50 platforms a
51 font with the closest size to the given one is found using binary search and
52 the static New method must be used.
7c913512 53 @param family
4cc4bfaf 54 Font family, a generic way of referring to fonts without specifying actual
23324ae1
FM
55 facename. One of:
56
57
23324ae1
FM
58
59
23324ae1 60
23324ae1
FM
61
62
4cc4bfaf 63 wxFONTFAMILY_DEFAULT
23324ae1 64
23324ae1
FM
65
66
23324ae1 67
4cc4bfaf 68 Chooses a default font.
23324ae1
FM
69
70
23324ae1 71
23324ae1
FM
72
73
4cc4bfaf 74 wxFONTFAMILY_DECORATIVE
23324ae1 75
23324ae1
FM
76
77
23324ae1 78
4cc4bfaf 79 A decorative font.
23324ae1
FM
80
81
23324ae1 82
23324ae1 83
4cc4bfaf
FM
84
85 wxFONTFAMILY_ROMAN
86
87
88
89
90 A formal, serif font.
91
92
93
94
95
96 wxFONTFAMILY_SCRIPT
97
98
99
100
101 A handwriting font.
102
103
104
105
106
107 wxFONTFAMILY_SWISS
108
109
110
111
112 A sans-serif font.
113
114
115
116
117
118 wxFONTFAMILY_MODERN
119
120
121
122
123 A fixed pitch font.
124
125
126
127
128
129 wxFONTFAMILY_TELETYPE
130
131
132
133
134 A teletype font.
135 @param style
136 One of wxFONTSTYLE_NORMAL, wxFONTSTYLE_SLANT and wxFONTSTYLE_ITALIC.
7c913512 137 @param weight
4cc4bfaf 138 Font weight, sometimes also referred to as font boldness. One of:
23324ae1
FM
139
140
23324ae1
FM
141
142
23324ae1 143
23324ae1
FM
144
145
4cc4bfaf 146 wxFONTWEIGHT_NORMAL
23324ae1 147
23324ae1
FM
148
149
23324ae1 150
4cc4bfaf
FM
151 Normal font.
152
153
154
155
156
157 wxFONTWEIGHT_LIGHT
158
159
23324ae1 160
23324ae1 161
4cc4bfaf
FM
162 Light font.
163
164
165
166
167
168 wxFONTWEIGHT_BOLD
169
170
171
172
173 Bold font.
174 @param underline
175 The value can be @true or @false. At present this has an effect on Windows
176 and Motif 2.x only.
177 @param faceName
178 An optional string specifying the actual typeface to be used. If it is an
179 empty string,
180 a default typeface will be chosen based on the family.
7c913512 181 @param encoding
4cc4bfaf
FM
182 An encoding which may be one of
183
184
185
186
187
188
189
190 wxFONTENCODING_SYSTEM
191
192
193
194
195 Default system encoding.
196
197
198
199
200
201 wxFONTENCODING_DEFAULT
202
203
204
205
206 Default application encoding: this
207 is the encoding set by calls to
208 SetDefaultEncoding and which may be set to,
209 say, KOI8 to create all fonts by default with KOI8 encoding. Initially, the
210 default application encoding is the same as default system encoding.
23324ae1 211
23324ae1
FM
212
213
23324ae1 214
23324ae1 215
4cc4bfaf 216 wxFONTENCODING_ISO8859_1...15
23324ae1 217
23324ae1 218
23324ae1
FM
219
220
4cc4bfaf 221 ISO8859 encodings.
23324ae1 222
23324ae1
FM
223
224
23324ae1 225
23324ae1 226
4cc4bfaf 227 wxFONTENCODING_KOI8
23324ae1 228
23324ae1 229
4cc4bfaf
FM
230
231
232 The standard Russian encoding for Internet.
233
234
235
236
237
238 wxFONTENCODING_CP1250...1252
239
240
241
242
243 Windows encodings similar to ISO8859 (but not identical).
244
245
246
247
248
249 If the specified encoding isn't available, no font is created
250 (see also font encoding overview).
23324ae1
FM
251
252 @remarks If the desired font does not exist, the closest match will be
4cc4bfaf
FM
253 chosen. Under Windows, only scalable TrueType fonts are
254 used.
23324ae1
FM
255 */
256 wxFont();
7c913512
FM
257 wxFont(const wxFont& font);
258 wxFont(int pointSize, wxFontFamily family, int style,
259 wxFontWeight weight,
4cc4bfaf 260 const bool underline = false,
7c913512
FM
261 const wxString& faceName = "",
262 wxFontEncoding encoding = wxFONTENCODING_DEFAULT);
263 wxFont(const wxSize& pixelSize, wxFontFamily family,
264 int style, wxFontWeight weight,
4cc4bfaf 265 const bool underline = false,
7c913512
FM
266 const wxString& faceName = "",
267 wxFontEncoding encoding = wxFONTENCODING_DEFAULT);
23324ae1
FM
268 //@}
269
270 /**
271 Destructor.
272 See @ref overview_refcountdestruct "reference-counted object destruction" for
273 more info.
274
275 @remarks Although all remaining fonts are deleted when the application
4cc4bfaf
FM
276 exits, the application should try to clean up all fonts
277 itself. This is because wxWidgets cannot know if a
278 pointer to the font object is stored in an application
279 data structure, and there is a risk of double deletion.
23324ae1
FM
280 */
281 ~wxFont();
282
283 /**
284 Returns the current application's default encoding.
285
4cc4bfaf 286 @see @ref overview_wxfontencodingoverview, SetDefaultEncoding()
23324ae1
FM
287 */
288 static wxFontEncoding GetDefaultEncoding();
289
290 /**
291 Returns the typeface name associated with the font, or the empty string if
292 there is no
293 typeface information.
294
4cc4bfaf 295 @see SetFaceName()
23324ae1 296 */
328f5751 297 wxString GetFaceName() const;
23324ae1
FM
298
299 /**
300 Gets the font family. See SetFamily() for a list of valid
301 family identifiers.
302
4cc4bfaf 303 @see SetFamily()
23324ae1 304 */
328f5751 305 wxFontFamily GetFamily() const;
23324ae1
FM
306
307 /**
308 Returns the platform-dependent string completely describing this font.
309 Returned string is always non-empty.
310 Note that the returned string is not meant to be shown or edited by the user: a
311 typical
312 use of this function is for serializing in string-form a wxFont object.
313
4cc4bfaf 314 @see SetNativeFontInfo(),GetNativeFontInfoUserDesc()
23324ae1 315 */
328f5751 316 wxString GetNativeFontInfoDesc() const;
23324ae1
FM
317
318 /**
319 Returns a user-friendly string for this font object. Returned string is always
320 non-empty.
321 Some examples of the formats of returned strings (which are platform-dependent)
322 are in SetNativeFontInfoUserDesc().
323
4cc4bfaf 324 @see GetNativeFontInfoDesc()
23324ae1
FM
325 */
326 wxString GetNativeFontInfoUserDesc();
327
328 /**
329 Gets the point size.
330
4cc4bfaf 331 @see SetPointSize()
23324ae1 332 */
328f5751 333 int GetPointSize() const;
23324ae1
FM
334
335 /**
336 Gets the font style. See wxFont() for a list of valid
337 styles.
338
4cc4bfaf 339 @see SetStyle()
23324ae1 340 */
328f5751 341 int GetStyle() const;
23324ae1
FM
342
343 /**
344 Returns @true if the font is underlined, @false otherwise.
345
4cc4bfaf 346 @see SetUnderlined()
23324ae1 347 */
328f5751 348 bool GetUnderlined() const;
23324ae1
FM
349
350 /**
351 Gets the font weight. See wxFont() for a list of valid
352 weight identifiers.
353
4cc4bfaf 354 @see SetWeight()
23324ae1 355 */
328f5751 356 wxFontWeight GetWeight() const;
23324ae1
FM
357
358 /**
359 Returns @true if the font is a fixed width (or monospaced) font,
360 @false if it is a proportional one or font is invalid.
361 */
328f5751 362 bool IsFixedWidth() const;
23324ae1
FM
363
364 /**
365 Returns @true if this object is a valid font, @false otherwise.
366 */
328f5751 367 bool IsOk() const;
23324ae1
FM
368
369 //@{
370 /**
371 These functions take the same parameters as @ref ctor() wxFont
372 constructor and return a new font object allocated on the heap.
23324ae1
FM
373 Using @c New() is currently the only way to directly create a font with
374 the given size in pixels on platforms other than wxMSW.
375 */
4cc4bfaf
FM
376 static wxFont* New(int pointSize, wxFontFamily family, int style,
377 wxFontWeight weight,
378 const bool underline = false,
379 const wxString& faceName = "",
380 wxFontEncoding encoding = wxFONTENCODING_DEFAULT);
381 static wxFont* New(int pointSize, wxFontFamily family,
382 int flags = wxFONTFLAG_DEFAULT,
383 const wxString& faceName = "",
384 wxFontEncoding encoding = wxFONTENCODING_DEFAULT);
385 static wxFont* New(const wxSize& pixelSize,
386 wxFontFamily family,
387 int style,
388 wxFontWeight weight,
389 const bool underline = false,
390 const wxString& faceName = "",
391 wxFontEncoding encoding = wxFONTENCODING_DEFAULT);
392 static wxFont* New(const wxSize& pixelSize,
393 wxFontFamily family,
394 int flags = wxFONTFLAG_DEFAULT,
395 const wxString& faceName = "",
396 wxFontEncoding encoding = wxFONTENCODING_DEFAULT);
23324ae1
FM
397 //@}
398
399 /**
400 Sets the default font encoding.
401
4cc4bfaf 402 @see @ref overview_wxfontencodingoverview, GetDefaultEncoding()
23324ae1
FM
403 */
404 static void SetDefaultEncoding(wxFontEncoding encoding);
405
406 /**
407 Sets the facename for the font.
408 Returns @true if the given face name exists; @false otherwise.
409
7c913512 410 @param faceName
4cc4bfaf 411 A valid facename, which should be on the end-user's system.
23324ae1
FM
412
413 @remarks To avoid portability problems, don't rely on a specific face,
4cc4bfaf
FM
414 but specify the font family instead or as well. A
415 suitable font will be found on the end-user's system.
416 If both the family and the facename are specified,
417 wxWidgets will first search for the specific face, and
418 then for a font belonging to the same family.
23324ae1 419
4cc4bfaf 420 @see GetFaceName(), SetFamily()
23324ae1
FM
421 */
422 bool SetFaceName(const wxString& faceName);
423
424 /**
425 Sets the font family.
426
7c913512 427 @param family
4cc4bfaf
FM
428 One of:
429
430
431
432
433
434
435
436 wxFONTFAMILY_DEFAULT
437
438
439
440
441 Chooses a default font.
442
443
444
445
446
447 wxFONTFAMILY_DECORATIVE
448
449
450
451
452 A decorative font.
453
454
455
456
457
458 wxFONTFAMILY_ROMAN
23324ae1
FM
459
460
23324ae1
FM
461
462
4cc4bfaf 463 A formal, serif font.
23324ae1 464
23324ae1
FM
465
466
23324ae1 467
23324ae1 468
4cc4bfaf 469 wxFONTFAMILY_SCRIPT
23324ae1 470
23324ae1 471
23324ae1
FM
472
473
4cc4bfaf 474 A handwriting font.
23324ae1 475
23324ae1
FM
476
477
23324ae1 478
23324ae1 479
4cc4bfaf 480 wxFONTFAMILY_SWISS
23324ae1 481
23324ae1 482
23324ae1
FM
483
484
4cc4bfaf 485 A sans-serif font.
23324ae1 486
4cc4bfaf
FM
487
488
489
490
491 wxFONTFAMILY_MODERN
492
493
494
495
496 A fixed pitch font.
497
498
499
500
501
502 wxFONTFAMILY_TELETYPE
503
504
505
506
507 A teletype font.
508
509 @see GetFamily(), SetFaceName()
23324ae1
FM
510 */
511 void SetFamily(wxFontFamily family);
512
513 /**
514 Creates the font corresponding to the given native font description string and
515 returns @true if
516 the creation was successful.
517 which must have been previously returned by
518 GetNativeFontInfoDesc(). If the string is
519 invalid, font is unchanged. This function is typically used for de-serializing
520 a wxFont
521 object previously saved in a string-form.
522
4cc4bfaf 523 @see SetNativeFontInfoUserDesc()
23324ae1
FM
524 */
525 bool SetNativeFontInfo(const wxString& info);
526
527 /**
528 Creates the font corresponding to the given native font description string and
529 returns @true if
530 the creation was successful.
531 Unlike SetNativeFontInfo(), this function accepts
532 strings which are user-friendly.
533 Examples of accepted string formats are:
534
23324ae1
FM
535 Generic syntax
536
23324ae1
FM
537 Example
538
539 on @b wxGTK2: @c [FACE-NAME] [bold] [oblique|italic] [POINTSIZE]
540
23324ae1
FM
541 Monospace bold 10
542
543 on @b wxMSW: @c [light|bold] [italic] [FACE-NAME] [POINTSIZE] [ENCODING]
544
23324ae1
FM
545 Tahoma 10 WINDOWS-1252
546
547 on @b wxMac: FIXME
548
23324ae1
FM
549 FIXME
550
551 For more detailed information about the allowed syntaxes you can look at the
552 documentation of the native API used for font-rendering (e.g. pango_font_description_from_string).
553
4cc4bfaf 554 @see SetNativeFontInfo()
23324ae1
FM
555 */
556 bool SetNativeFontInfoUserDesc(const wxString& info);
557
558 /**
559 Sets the point size.
560
7c913512 561 @param pointSize
4cc4bfaf 562 Size in points.
23324ae1 563
4cc4bfaf 564 @see GetPointSize()
23324ae1
FM
565 */
566 void SetPointSize(int pointSize);
567
568 /**
569 Sets the font style.
570
7c913512 571 @param style
4cc4bfaf 572 One of wxFONTSTYLE_NORMAL, wxFONTSTYLE_SLANT and wxFONTSTYLE_ITALIC.
23324ae1 573
4cc4bfaf 574 @see GetStyle()
23324ae1
FM
575 */
576 void SetStyle(int style);
577
578 /**
579 Sets underlining.
580
7c913512 581 @param underlining
4cc4bfaf 582 @true to underline, @false otherwise.
23324ae1 583
4cc4bfaf 584 @see GetUnderlined()
23324ae1
FM
585 */
586 void SetUnderlined(const bool underlined);
587
588 /**
589 Sets the font weight.
590
7c913512 591 @param weight
4cc4bfaf
FM
592 One of:
593
594
595
596
597
598
599
600 wxFONTWEIGHT_NORMAL
601
602
603
604
605 Normal font.
606
607
608
609
610
611 wxFONTWEIGHT_LIGHT
612
613
614
23324ae1 615
4cc4bfaf 616 Light font.
23324ae1 617
23324ae1
FM
618
619
23324ae1 620
23324ae1 621
4cc4bfaf 622 wxFONTWEIGHT_BOLD
23324ae1 623
23324ae1 624
23324ae1
FM
625
626
4cc4bfaf 627 Bold font.
23324ae1 628
4cc4bfaf 629 @see GetWeight()
23324ae1
FM
630 */
631 void SetWeight(wxFontWeight weight);
632
633 /**
634 Inequality operator.
635 See @ref overview_refcountequality "reference-counted object comparison" for
636 more info.
637 */
638 bool operator !=(const wxFont& font);
639
640 /**
641 Assignment operator, using @ref overview_trefcount "reference counting".
642 */
643 wxFont operator =(const wxFont& font);
644
645 /**
646 Equality operator.
647 See @ref overview_refcountequality "reference-counted object comparison" for
648 more info.
649 */
650 bool operator ==(const wxFont& font);
651};
e54c96f1
FM
652
653
654/**
655 FIXME
656*/
657wxFont Objects:
658;
659
660/**
661 FIXME
662*/
663wxFont wxNullFont;
664
665/**
666 FIXME
667*/
668wxFont Pointers:
669;
670
671/**
672 FIXME
673*/
674wxFont wxNORMAL_FONT;
675
676/**
677 FIXME
678*/
679wxFont wxSMALL_FONT;
680
681/**
682 FIXME
683*/
684wxFont wxITALIC_FONT;
685
686/**
687 FIXME
688*/
689wxFont wxSWISS_FONT;
690
691