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