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