]> git.saurik.com Git - wxWidgets.git/blame - interface/font.h
SF bug 1895101
[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.
3c4f71cc 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 55 facename. One of:
3c4f71cc
VS
56
57
58
59
60
61
62
4cc4bfaf 63 wxFONTFAMILY_DEFAULT
3c4f71cc
VS
64
65
66
67
4cc4bfaf 68 Chooses a default font.
3c4f71cc
VS
69
70
71
72
73
4cc4bfaf 74 wxFONTFAMILY_DECORATIVE
3c4f71cc
VS
75
76
77
78
4cc4bfaf 79 A decorative font.
3c4f71cc
VS
80
81
82
83
84
4cc4bfaf 85 wxFONTFAMILY_ROMAN
3c4f71cc
VS
86
87
88
89
4cc4bfaf 90 A formal, serif font.
3c4f71cc
VS
91
92
93
94
95
4cc4bfaf 96 wxFONTFAMILY_SCRIPT
3c4f71cc
VS
97
98
99
100
4cc4bfaf 101 A handwriting font.
3c4f71cc
VS
102
103
104
105
106
4cc4bfaf 107 wxFONTFAMILY_SWISS
3c4f71cc
VS
108
109
110
111
4cc4bfaf 112 A sans-serif font.
3c4f71cc
VS
113
114
115
116
117
4cc4bfaf 118 wxFONTFAMILY_MODERN
3c4f71cc
VS
119
120
121
122
4cc4bfaf 123 A fixed pitch font.
3c4f71cc
VS
124
125
126
127
128
4cc4bfaf 129 wxFONTFAMILY_TELETYPE
3c4f71cc
VS
130
131
132
133
4cc4bfaf
FM
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:
3c4f71cc
VS
139
140
141
142
143
144
145
4cc4bfaf 146 wxFONTWEIGHT_NORMAL
3c4f71cc
VS
147
148
149
150
4cc4bfaf 151 Normal font.
3c4f71cc
VS
152
153
154
155
156
4cc4bfaf 157 wxFONTWEIGHT_LIGHT
3c4f71cc
VS
158
159
160
161
4cc4bfaf 162 Light font.
3c4f71cc
VS
163
164
165
166
167
4cc4bfaf 168 wxFONTWEIGHT_BOLD
3c4f71cc
VS
169
170
171
172
4cc4bfaf
FM
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 182 An encoding which may be one of
3c4f71cc
VS
183
184
185
186
187
188
189
4cc4bfaf 190 wxFONTENCODING_SYSTEM
3c4f71cc
VS
191
192
193
194
4cc4bfaf 195 Default system encoding.
3c4f71cc
VS
196
197
198
199
200
4cc4bfaf 201 wxFONTENCODING_DEFAULT
3c4f71cc
VS
202
203
204
205
4cc4bfaf
FM
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.
3c4f71cc
VS
211
212
213
214
215
4cc4bfaf 216 wxFONTENCODING_ISO8859_1...15
3c4f71cc
VS
217
218
219
220
4cc4bfaf 221 ISO8859 encodings.
3c4f71cc
VS
222
223
224
225
226
4cc4bfaf 227 wxFONTENCODING_KOI8
3c4f71cc
VS
228
229
230
231
4cc4bfaf 232 The standard Russian encoding for Internet.
3c4f71cc
VS
233
234
235
236
237
4cc4bfaf 238 wxFONTENCODING_CP1250...1252
3c4f71cc
VS
239
240
241
242
4cc4bfaf 243 Windows encodings similar to ISO8859 (but not identical).
3c4f71cc
VS
244
245
246
247
248
4cc4bfaf
FM
249 If the specified encoding isn't available, no font is created
250 (see also font encoding overview).
3c4f71cc 251
23324ae1 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.
3c4f71cc 274
23324ae1 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.
3c4f71cc 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.
3c4f71cc 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.
3c4f71cc 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.
3c4f71cc 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().
3c4f71cc 323
4cc4bfaf 324 @see GetNativeFontInfoDesc()
23324ae1
FM
325 */
326 wxString GetNativeFontInfoUserDesc();
327
328 /**
329 Gets the point size.
3c4f71cc 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.
3c4f71cc 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.
3c4f71cc 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.
3c4f71cc 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.
3c4f71cc 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.
3c4f71cc 409
7c913512 410 @param faceName
4cc4bfaf 411 A valid facename, which should be on the end-user's system.
3c4f71cc 412
23324ae1 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.
3c4f71cc 419
4cc4bfaf 420 @see GetFaceName(), SetFamily()
23324ae1
FM
421 */
422 bool SetFaceName(const wxString& faceName);
423
424 /**
425 Sets the font family.
3c4f71cc 426
7c913512 427 @param family
4cc4bfaf 428 One of:
3c4f71cc
VS
429
430
431
432
433
434
435
4cc4bfaf 436 wxFONTFAMILY_DEFAULT
3c4f71cc
VS
437
438
439
440
4cc4bfaf 441 Chooses a default font.
3c4f71cc
VS
442
443
444
445
446
4cc4bfaf 447 wxFONTFAMILY_DECORATIVE
3c4f71cc
VS
448
449
450
451
4cc4bfaf 452 A decorative font.
3c4f71cc
VS
453
454
455
456
457
4cc4bfaf 458 wxFONTFAMILY_ROMAN
3c4f71cc
VS
459
460
461
462
4cc4bfaf 463 A formal, serif font.
3c4f71cc
VS
464
465
466
467
468
4cc4bfaf 469 wxFONTFAMILY_SCRIPT
3c4f71cc
VS
470
471
472
473
4cc4bfaf 474 A handwriting font.
3c4f71cc
VS
475
476
477
478
479
4cc4bfaf 480 wxFONTFAMILY_SWISS
3c4f71cc
VS
481
482
483
484
4cc4bfaf 485 A sans-serif font.
3c4f71cc
VS
486
487
488
489
490
4cc4bfaf 491 wxFONTFAMILY_MODERN
3c4f71cc
VS
492
493
494
495
4cc4bfaf 496 A fixed pitch font.
3c4f71cc
VS
497
498
499
500
501
4cc4bfaf 502 wxFONTFAMILY_TELETYPE
3c4f71cc
VS
503
504
505
506
4cc4bfaf 507 A teletype font.
3c4f71cc 508
4cc4bfaf 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.
3c4f71cc 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:
3c4f71cc 534
23324ae1 535 Generic syntax
3c4f71cc 536
23324ae1 537 Example
3c4f71cc 538
23324ae1 539 on @b wxGTK2: @c [FACE-NAME] [bold] [oblique|italic] [POINTSIZE]
3c4f71cc 540
23324ae1 541 Monospace bold 10
3c4f71cc 542
23324ae1 543 on @b wxMSW: @c [light|bold] [italic] [FACE-NAME] [POINTSIZE] [ENCODING]
3c4f71cc 544
23324ae1 545 Tahoma 10 WINDOWS-1252
3c4f71cc 546
23324ae1 547 on @b wxMac: FIXME
3c4f71cc 548
23324ae1 549 FIXME
3c4f71cc 550
23324ae1
FM
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).
3c4f71cc 553
4cc4bfaf 554 @see SetNativeFontInfo()
23324ae1
FM
555 */
556 bool SetNativeFontInfoUserDesc(const wxString& info);
557
558 /**
559 Sets the point size.
3c4f71cc 560
7c913512 561 @param pointSize
4cc4bfaf 562 Size in points.
3c4f71cc 563
4cc4bfaf 564 @see GetPointSize()
23324ae1
FM
565 */
566 void SetPointSize(int pointSize);
567
568 /**
569 Sets the font style.
3c4f71cc 570
7c913512 571 @param style
4cc4bfaf 572 One of wxFONTSTYLE_NORMAL, wxFONTSTYLE_SLANT and wxFONTSTYLE_ITALIC.
3c4f71cc 573
4cc4bfaf 574 @see GetStyle()
23324ae1
FM
575 */
576 void SetStyle(int style);
577
578 /**
579 Sets underlining.
3c4f71cc 580
7c913512 581 @param underlining
4cc4bfaf 582 @true to underline, @false otherwise.
3c4f71cc 583
4cc4bfaf 584 @see GetUnderlined()
23324ae1
FM
585 */
586 void SetUnderlined(const bool underlined);
587
588 /**
589 Sets the font weight.
3c4f71cc 590
7c913512 591 @param weight
4cc4bfaf 592 One of:
3c4f71cc
VS
593
594
595
596
597
598
599
4cc4bfaf 600 wxFONTWEIGHT_NORMAL
3c4f71cc
VS
601
602
603
604
4cc4bfaf 605 Normal font.
3c4f71cc
VS
606
607
608
609
610
4cc4bfaf 611 wxFONTWEIGHT_LIGHT
3c4f71cc
VS
612
613
614
615
4cc4bfaf 616 Light font.
3c4f71cc
VS
617
618
619
620
621
4cc4bfaf 622 wxFONTWEIGHT_BOLD
3c4f71cc
VS
623
624
625
626
4cc4bfaf 627 Bold font.
3c4f71cc 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*/
7fa7088e 657wxFont wxNullFont;
e54c96f1
FM
658
659/**
660 FIXME
661*/
7fa7088e 662wxFont wxNORMAL_FONT;
e54c96f1
FM
663
664/**
665 FIXME
666*/
7fa7088e 667wxFont wxSMALL_FONT;
e54c96f1
FM
668
669/**
670 FIXME
671*/
7fa7088e 672wxFont wxITALIC_FONT;
e54c96f1
FM
673
674/**
675 FIXME
676*/
7fa7088e
BP
677wxFont wxSWISS_FONT;
678
679
680
681// ============================================================================
682// Global functions/macros
683// ============================================================================
684
685/** @ingroup group_funcmacro_misc */
686//@{
e54c96f1
FM
687
688/**
7fa7088e
BP
689 Converts string to a wxFont best represented by the given string. Returns
690 @true on success.
691
692 @see wxToString(const wxFont&)
693
694 @header{wx/font.h}
e54c96f1 695*/
7fa7088e 696bool wxFromString(const wxString& string, wxFont* font);
e54c96f1
FM
697
698/**
7fa7088e
BP
699 Converts the given wxFont into a string.
700
701 @see wxFromString(const wxString&, wxFont*)
702
703 @header{wx/font.h}
e54c96f1 704*/
7fa7088e 705wxString wxToString(const wxFont& font);
e54c96f1 706
7fa7088e 707//@}
e54c96f1 708