1 /////////////////////////////////////////////////////////////////////////////
3 // Purpose: interface of wxFont
4 // Author: wxWidgets team
5 // Licence: wxWindows licence
6 /////////////////////////////////////////////////////////////////////////////
10 Standard font families: these are used mainly during wxFont creation to specify
11 the generic properties of the font without hardcoding in the sources a specific
14 wxFontFamily thus allows to group the font face names of fonts with similar
15 properties. Most wxWidgets ports use lists of fonts for each font family
16 inspired by the data taken from http://www.codestyle.org/css/font-family.
20 wxFONTFAMILY_DEFAULT
= wxDEFAULT
, //!< Chooses a default font.
22 wxFONTFAMILY_DECORATIVE
= wxDECORATIVE
, //!< A decorative font.
23 wxFONTFAMILY_ROMAN
= wxROMAN
, //!< A formal, serif font.
24 wxFONTFAMILY_SCRIPT
= wxSCRIPT
, //!< A handwriting font.
25 wxFONTFAMILY_SWISS
= wxSWISS
, //!< A sans-serif font.
27 /// A fixed pitch font. Note that wxFont currently does not make distinctions
28 /// between @c wxFONTFAMILY_MODERN and @c wxFONTFAMILY_TELETYPE.
29 wxFONTFAMILY_MODERN
= wxMODERN
,
31 /// A teletype (i.e. monospaced) font.
32 /// Monospace fonts have a fixed width like typewriters and often have strong angular
33 /// or block serifs. Monospace font faces are often used code samples and have a simple,
34 /// functional font style.
35 /// See also wxFont::IsFixedWidth() for an easy way to test for monospace property.
36 wxFONTFAMILY_TELETYPE
= wxTELETYPE
,
39 /// Invalid font family value, returned by wxFont::GetFamily() when the
40 /// font is invalid for example.
41 wxFONTFAMILY_UNKNOWN
= wxFONTFAMILY_MAX
49 /// The font is drawn without slant.
50 wxFONTSTYLE_NORMAL
= wxNORMAL
,
52 /// The font is slanted in an italic style.
53 wxFONTSTYLE_ITALIC
= wxITALIC
,
55 /// The font is slanted, but in a roman style.
56 /// Note that under wxMSW this style is the same as @c wxFONTSTYLE_ITALIC.
57 wxFONTSTYLE_SLANT
= wxSLANT
,
67 wxFONTWEIGHT_NORMAL
= wxNORMAL
, //!< Normal font.
68 wxFONTWEIGHT_LIGHT
= wxLIGHT
, //!< Light font.
69 wxFONTWEIGHT_BOLD
= wxBOLD
, //!< Bold font.
76 The elements of this enum correspond to CSS absolute size specifications,
77 see http://www.w3.org/TR/CSS21/fonts.html#font-size-props
79 @see wxFont::SetSymbolicSize()
83 enum wxFontSymbolicSize
85 wxFONTSIZE_XX_SMALL
= -3, //!< Extra small.
86 wxFONTSIZE_X_SMALL
, //!< Very small.
87 wxFONTSIZE_SMALL
, //!< Small.
88 wxFONTSIZE_MEDIUM
, //!< Normal.
89 wxFONTSIZE_LARGE
, //!< Large.
90 wxFONTSIZE_X_LARGE
, //!< Very large.
91 wxFONTSIZE_XX_LARGE
//!< Extra large.
95 The font flag bits for the new font ctor accepting one combined flags word.
99 /// no special flags: font with default weight/slant/anti-aliasing
100 wxFONTFLAG_DEFAULT
= 0,
102 /// slant flags (default: no slant)
103 wxFONTFLAG_ITALIC
= 1 << 0,
104 wxFONTFLAG_SLANT
= 1 << 1,
106 /// weight flags (default: medium)
107 wxFONTFLAG_LIGHT
= 1 << 2,
108 wxFONTFLAG_BOLD
= 1 << 3,
110 /// anti-aliasing flag: force on or off (default: the current system default)
111 wxFONTFLAG_ANTIALIASED
= 1 << 4,
112 wxFONTFLAG_NOT_ANTIALIASED
= 1 << 5,
114 /// Underlined style (not underlined by default).
115 wxFONTFLAG_UNDERLINED
= 1 << 6,
117 /// Strike-through style (only supported in wxMSW and wxGTK currently).
118 wxFONTFLAG_STRIKETHROUGH
= 1 << 7,
120 /// the mask of all currently used flags
121 wxFONTFLAG_MASK
= wxFONTFLAG_ITALIC
|
125 wxFONTFLAG_ANTIALIASED
|
126 wxFONTFLAG_NOT_ANTIALIASED
|
127 wxFONTFLAG_UNDERLINED
|
128 wxFONTFLAG_STRIKETHROUGH
136 See wxFont::SetEncoding().
140 /// Default system encoding.
141 wxFONTENCODING_SYSTEM
= -1, // system default
143 /// Default application encoding.
144 wxFONTENCODING_DEFAULT
, // current default encoding
146 // ISO8859 standard defines a number of single-byte charsets
147 wxFONTENCODING_ISO8859_1
, //!< West European (Latin1)
148 wxFONTENCODING_ISO8859_2
, //!< Central and East European (Latin2)
149 wxFONTENCODING_ISO8859_3
, //!< Esperanto (Latin3)
150 wxFONTENCODING_ISO8859_4
, //!< Baltic (old) (Latin4)
151 wxFONTENCODING_ISO8859_5
, //!< Cyrillic
152 wxFONTENCODING_ISO8859_6
, //!< Arabic
153 wxFONTENCODING_ISO8859_7
, //!< Greek
154 wxFONTENCODING_ISO8859_8
, //!< Hebrew
155 wxFONTENCODING_ISO8859_9
, //!< Turkish (Latin5)
156 wxFONTENCODING_ISO8859_10
, //!< Variation of Latin4 (Latin6)
157 wxFONTENCODING_ISO8859_11
, //!< Thai
158 wxFONTENCODING_ISO8859_12
, //!< doesn't exist currently, but put it
159 //!< here anyhow to make all ISO8859
160 //!< consecutive numbers
161 wxFONTENCODING_ISO8859_13
, //!< Baltic (Latin7)
162 wxFONTENCODING_ISO8859_14
, //!< Latin8
163 wxFONTENCODING_ISO8859_15
, //!< Latin9 (a.k.a. Latin0, includes euro)
164 wxFONTENCODING_ISO8859_MAX
,
166 // Cyrillic charset soup (see http://czyborra.com/charsets/cyrillic.html)
167 wxFONTENCODING_KOI8
, //!< KOI8 Russian
168 wxFONTENCODING_KOI8_U
, //!< KOI8 Ukrainian
169 wxFONTENCODING_ALTERNATIVE
, //!< same as MS-DOS CP866
170 wxFONTENCODING_BULGARIAN
, //!< used under Linux in Bulgaria
172 // what would we do without Microsoft? They have their own encodings
174 wxFONTENCODING_CP437
, //!< original MS-DOS codepage
175 wxFONTENCODING_CP850
, //!< CP437 merged with Latin1
176 wxFONTENCODING_CP852
, //!< CP437 merged with Latin2
177 wxFONTENCODING_CP855
, //!< another cyrillic encoding
178 wxFONTENCODING_CP866
, //!< and another one
180 wxFONTENCODING_CP874
, //!< WinThai
181 wxFONTENCODING_CP932
, //!< Japanese (shift-JIS)
182 wxFONTENCODING_CP936
, //!< Chinese simplified (GB)
183 wxFONTENCODING_CP949
, //!< Korean (Hangul charset)
184 wxFONTENCODING_CP950
, //!< Chinese (traditional - Big5)
185 wxFONTENCODING_CP1250
, //!< WinLatin2
186 wxFONTENCODING_CP1251
, //!< WinCyrillic
187 wxFONTENCODING_CP1252
, //!< WinLatin1
188 wxFONTENCODING_CP1253
, //!< WinGreek (8859-7)
189 wxFONTENCODING_CP1254
, //!< WinTurkish
190 wxFONTENCODING_CP1255
, //!< WinHebrew
191 wxFONTENCODING_CP1256
, //!< WinArabic
192 wxFONTENCODING_CP1257
, //!< WinBaltic (same as Latin 7)
193 wxFONTENCODING_CP1258
, //!< WinVietnamese (since 2.9.4)
194 wxFONTENCODING_CP1361
, //!< Johab Korean character set (since 2.9.4)
195 wxFONTENCODING_CP12_MAX
,
197 wxFONTENCODING_UTF7
, //!< UTF-7 Unicode encoding
198 wxFONTENCODING_UTF8
, //!< UTF-8 Unicode encoding
199 wxFONTENCODING_EUC_JP
, //!< Extended Unix Codepage for Japanese
200 wxFONTENCODING_UTF16BE
, //!< UTF-16 Big Endian Unicode encoding
201 wxFONTENCODING_UTF16LE
, //!< UTF-16 Little Endian Unicode encoding
202 wxFONTENCODING_UTF32BE
, //!< UTF-32 Big Endian Unicode encoding
203 wxFONTENCODING_UTF32LE
, // UTF-32 Little Endian Unicode encoding
205 wxFONTENCODING_MACROMAN
, //!< the standard mac encodings
206 wxFONTENCODING_MACJAPANESE
,
207 wxFONTENCODING_MACCHINESETRAD
,
208 wxFONTENCODING_MACKOREAN
,
209 wxFONTENCODING_MACARABIC
,
210 wxFONTENCODING_MACHEBREW
,
211 wxFONTENCODING_MACGREEK
,
212 wxFONTENCODING_MACCYRILLIC
,
213 wxFONTENCODING_MACDEVANAGARI
,
214 wxFONTENCODING_MACGURMUKHI
,
215 wxFONTENCODING_MACGUJARATI
,
216 wxFONTENCODING_MACORIYA
,
217 wxFONTENCODING_MACBENGALI
,
218 wxFONTENCODING_MACTAMIL
,
219 wxFONTENCODING_MACTELUGU
,
220 wxFONTENCODING_MACKANNADA
,
221 wxFONTENCODING_MACMALAJALAM
,
222 wxFONTENCODING_MACSINHALESE
,
223 wxFONTENCODING_MACBURMESE
,
224 wxFONTENCODING_MACKHMER
,
225 wxFONTENCODING_MACTHAI
,
226 wxFONTENCODING_MACLAOTIAN
,
227 wxFONTENCODING_MACGEORGIAN
,
228 wxFONTENCODING_MACARMENIAN
,
229 wxFONTENCODING_MACCHINESESIMP
,
230 wxFONTENCODING_MACTIBETAN
,
231 wxFONTENCODING_MACMONGOLIAN
,
232 wxFONTENCODING_MACETHIOPIC
,
233 wxFONTENCODING_MACCENTRALEUR
,
234 wxFONTENCODING_MACVIATNAMESE
,
235 wxFONTENCODING_MACARABICEXT
,
236 wxFONTENCODING_MACSYMBOL
,
237 wxFONTENCODING_MACDINGBATS
,
238 wxFONTENCODING_MACTURKISH
,
239 wxFONTENCODING_MACCROATIAN
,
240 wxFONTENCODING_MACICELANDIC
,
241 wxFONTENCODING_MACROMANIAN
,
242 wxFONTENCODING_MACCELTIC
,
243 wxFONTENCODING_MACGAELIC
,
244 wxFONTENCODING_MACKEYBOARD
,
246 // more CJK encodings (for historical reasons some are already declared
248 wxFONTENCODING_ISO2022_JP
, //!< ISO-2022-JP JIS encoding
250 wxFONTENCODING_MAX
, //!< highest enumerated encoding value
252 wxFONTENCODING_MACMIN
= wxFONTENCODING_MACROMAN
,
253 wxFONTENCODING_MACMAX
= wxFONTENCODING_MACKEYBOARD
,
255 // aliases for endian-dependent UTF encodings
256 wxFONTENCODING_UTF16
, //!< native UTF-16
257 wxFONTENCODING_UTF32
, //!< native UTF-32
259 /// Alias for the native Unicode encoding on this platform
260 /// (this is used by wxEncodingConverter and wxUTFFile only for now)
261 wxFONTENCODING_UNICODE
,
263 wxFONTENCODING_GB2312
= wxFONTENCODING_CP936
, //!< Simplified Chinese
264 wxFONTENCODING_BIG5
= wxFONTENCODING_CP950
, //!< Traditional Chinese
265 wxFONTENCODING_SHIFT_JIS
= wxFONTENCODING_CP932
, //!< Shift JIS
266 wxFONTENCODING_EUC_KR
= wxFONTENCODING_CP949
, //!< Korean
267 wxFONTENCODING_JOHAB
= wxFONTENCODING_CP1361
, //!< Korean Johab (since 2.9.4)
268 wxFONTENCODING_VIETNAMESE
= wxFONTENCODING_CP1258
//!< Vietnamese (since 2.9.4)
275 This class is a helper used for wxFont creation using named parameter
276 idiom: it allows to specify various wxFont attributes using the chained
277 calls to its clearly named methods instead of passing them in the fixed
278 order to wxFont constructors.
280 For example, to create an italic font with the given face name and size you
283 wxFont font(wxFontInfo(12).FaceName("Helvetica").Italic());
286 Notice that all of the methods of this object return a reference to the
287 object itself, allowing the calls to them to be chained as in the example
290 All methods taking boolean parameters can be used to turn the specified
291 font attribute on or off and turn it on by default.
299 Default constructor uses the default font size for the current
305 Constructor setting the font size in points to use.
307 @see wxFont::SetPointSize()
309 explicit wxFontInfo(int pointSize
);
312 Constructor setting the font size in pixels to use.
314 @see wxFont::SetPixelSize()
316 explicit wxFontInfo(const wxSize
& pixelSize
);
321 The family is a generic portable way of referring to fonts without
322 specifying a precise face name. This parameter must be one of the
323 ::wxFontFamily enumeration values.
325 If the FaceName() is used, then it overrides the font family.
327 @see wxFont::SetFamily()
329 wxFontInfo
& Family(wxFontFamily family
);
332 Set the font face name to use.
334 Face names are not portable, so prefer to use Family() in portable
337 @see wxFont::SetFaceName()
339 wxFontInfo
& FaceName(const wxString
& faceName
);
342 Use a bold version of the font.
344 @see ::wxFontWeight, wxFont::SetWeight()
346 wxFontInfo
& Bold(bool bold
= true);
349 Use a lighter version of the font.
351 @see ::wxFontWeight, wxFont::SetWeight()
353 wxFontInfo
& Light(bool light
= true);
356 Use an italic version of the font.
358 @see ::wxFontStyle, wxFont::SetStyle()
360 wxFontInfo
& Italic(bool italic
= true);
363 Use a slanted version of the font.
365 @see ::wxFontStyle, wxFont::SetStyle()
367 wxFontInfo
& Slant(bool slant
= true);
370 Set anti-aliasing flag.
372 Force the use of anti-aliasing on or off.
374 Currently this is not implemented, i.e. using this method doesn't do
377 wxFontInfo
& AntiAliased(bool antiAliased
= true);
380 Use an underlined version of the font.
382 wxFontInfo
& Underlined(bool underlined
= true);
385 Use a strike-through version of the font.
387 Currently this is only implemented in wxMSW and wxGTK.
389 wxFontInfo
& Strikethrough(bool strikethrough
= true);
392 Set the font encoding to use.
394 This is mostly unneeded in Unicode builds of wxWidgets.
396 @see ::wxFontEncoding, wxFont::SetEncoding()
398 wxFontInfo
& Encoding(wxFontEncoding encoding
);
401 Set all the font attributes at once.
403 See ::wxFontFlag for the various flags that can be used.
405 wxFontInfo
& AllFlags(int flags
);
411 A font is an object which determines the appearance of text.
413 Fonts are used for drawing text to a device context, and setting the appearance
414 of a window's text, see wxDC::SetFont() and wxWindow::SetFont().
416 The easiest way to create a custom font is to use wxFontInfo object to
417 specify the font attributes and then use wxFont::wxFont(const wxFontInfo&)
418 constructor. Alternatively, you could start with one of the pre-defined
419 fonts or use wxWindow::GetFont() and modify the font, e.g. by increasing
420 its size using MakeLarger() or changing its weight using MakeBold().
422 This class uses @ref overview_refcount "reference counting and copy-on-write"
423 internally so that assignments between two instances of this class are very
424 cheap. You can therefore use actual objects instead of pointers without
425 efficiency problems. If an instance of this class is changed it will create
426 its own data internally so that other instances, which previously shared the
427 data using the reference counting, are not affected.
429 You can retrieve the current system font settings with wxSystemSettings.
435 ::wxNullFont, ::wxNORMAL_FONT, ::wxSMALL_FONT, ::wxITALIC_FONT, ::wxSWISS_FONT
437 @see @ref overview_font, wxDC::SetFont, wxDC::DrawText,
438 wxDC::GetTextExtent, wxFontDialog, wxSystemSettings
440 class wxFont
: public wxGDIObject
449 Copy constructor, uses @ref overview_refcount "reference counting".
451 wxFont(const wxFont
& font
);
454 Creates a font object using the specified font description.
456 This is the preferred way to create font objects as using this ctor
457 results in more readable code and it is also extensible, e.g. it could
458 continue to be used if support for more font attributes is added in the
459 future. For example, this constructor provides the only way of creating
460 fonts with strike-through style.
462 Example of creating a font using this ctor:
464 wxFont font(wxFontInfo(10).Bold().Underlined());
469 wxFont(const wxFontInfo
& font
);
472 Creates a font object with the specified attributes and size in points.
474 Notice that the use of this constructor is often more verbose and less
475 readable than the use of constructor from wxFontInfo, e.g. the example
476 in that constructor documentation would need to be written as
478 wxFont font(10, wxFONTFAMILY_DEFAULT, wxFONTSTYLE_NORMAL,
479 wxFONTWEIGHT_BOLD, true);
481 which is longer and less clear.
484 Size in points. See SetPointSize() for more info.
486 The font family: a generic portable way of referring to fonts without specifying a
487 facename. This parameter must be one of the ::wxFontFamily enumeration values.
488 If the @a faceName argument is provided, then it overrides the font family.
490 One of @c wxFONTSTYLE_NORMAL, @c wxFONTSTYLE_SLANT and @c wxFONTSTYLE_ITALIC.
492 Font weight, sometimes also referred to as font boldness.
493 One of the ::wxFontWeight enumeration values.
495 The value can be @true or @false.
496 At present this has an effect on Windows and Motif 2.x only.
498 An optional string specifying the face name to be used.
499 If it is an empty string, a default face name will be chosen based on the family.
501 An encoding which may be one of the enumeration values of ::wxFontEncoding.
502 Briefly these can be summed up as:
504 <TR><TD>@c wxFONTENCODING_SYSTEM</TD><TD>Default system encoding.</TD></TR>
505 <TR><TD>@c wxFONTENCODING_DEFAULT</TD><TD>
506 Default application encoding: this is the encoding set by calls to
507 SetDefaultEncoding() and which may be set to, say, KOI8 to create all
508 fonts by default with KOI8 encoding. Initially, the default application
509 encoding is the same as default system encoding.</TD></TR>
510 <TR><TD>@c wxFONTENCODING_ISO8859_1...15</TD><TD>ISO8859 encodings.</TD></TR>
511 <TR><TD>@c wxFONTENCODING_KOI8</TD><TD>The standard Russian encoding for Internet.</TD></TR>
512 <TR><TD>@c wxFONTENCODING_CP1250...1252</TD><TD>Windows encodings similar to ISO8859 (but not identical).</TD></TR>
514 If the specified encoding isn't available, no font is created
515 (see also @ref overview_fontencoding).
517 @remarks If the desired font does not exist, the closest match will be
518 chosen. Under Windows, only scalable TrueType fonts are used.
520 wxFont(int pointSize
, wxFontFamily family
, wxFontStyle style
,
522 bool underline
= false,
523 const wxString
& faceName
= wxEmptyString
,
524 wxFontEncoding encoding
= wxFONTENCODING_DEFAULT
);
527 Creates a font object with the specified attributes and size in pixels.
529 Notice that the use of this constructor is often more verbose and less
530 readable than the use of constructor from wxFontInfo, consider using
531 that constructor instead.
534 Size in pixels. See SetPixelSize() for more info.
536 The font family: a generic portable way of referring to fonts without specifying a
537 facename. This parameter must be one of the ::wxFontFamily enumeration values.
538 If the @a faceName argument is provided, then it overrides the font family.
540 One of @c wxFONTSTYLE_NORMAL, @c wxFONTSTYLE_SLANT and @c wxFONTSTYLE_ITALIC.
542 Font weight, sometimes also referred to as font boldness.
543 One of the ::wxFontWeight enumeration values.
545 The value can be @true or @false.
546 At present this has an effect on Windows and Motif 2.x only.
548 An optional string specifying the face name to be used.
549 If it is an empty string, a default face name will be chosen based on the family.
551 An encoding which may be one of the enumeration values of ::wxFontEncoding.
552 Briefly these can be summed up as:
554 <TR><TD>@c wxFONTENCODING_SYSTEM</TD><TD>Default system encoding.</TD></TR>
555 <TR><TD>@c wxFONTENCODING_DEFAULT</TD><TD>
556 Default application encoding: this is the encoding set by calls to
557 SetDefaultEncoding() and which may be set to, say, KOI8 to create all
558 fonts by default with KOI8 encoding. Initially, the default application
559 encoding is the same as default system encoding.</TD></TR>
560 <TR><TD>@c wxFONTENCODING_ISO8859_1...15</TD><TD>ISO8859 encodings.</TD></TR>
561 <TR><TD>@c wxFONTENCODING_KOI8</TD><TD>The standard Russian encoding for Internet.</TD></TR>
562 <TR><TD>@c wxFONTENCODING_CP1250...1252</TD><TD>Windows encodings similar to ISO8859 (but not identical).</TD></TR>
564 If the specified encoding isn't available, no font is created
565 (see also @ref overview_fontencoding).
567 @remarks If the desired font does not exist, the closest match will be
568 chosen. Under Windows, only scalable TrueType fonts are used.
570 wxFont(const wxSize
& pixelSize
, wxFontFamily family
,
571 wxFontStyle style
, wxFontWeight weight
,
572 bool underline
= false,
573 const wxString
& faceName
= wxEmptyString
,
574 wxFontEncoding encoding
= wxFONTENCODING_DEFAULT
);
577 Constructor from font description string.
579 This constructor uses SetNativeFontInfo() to initialize the font.
580 If @a fontdesc is invalid the font remains uninitialized, i.e. its IsOk() method
583 wxFont(const wxString
& nativeInfoString
);
586 Construct font from a native font info structure.
588 wxFont(const wxNativeFontInfo
& nativeInfo
);
593 See @ref overview_refcount_destruct "reference-counted object destruction"
596 @remarks Although all remaining fonts are deleted when the application
597 exits, the application should try to clean up all fonts
598 itself. This is because wxWidgets cannot know if a
599 pointer to the font object is stored in an application
600 data structure, and there is a risk of double deletion.
611 Returns the encoding of this font.
613 Note that under wxGTK the returned value is always @c wxFONTENCODING_UTF8.
617 virtual wxFontEncoding
GetEncoding() const;
620 Returns the face name associated with the font, or the empty string if
621 there is no face information.
625 virtual wxString
GetFaceName() const;
628 Gets the font family if possible.
630 As described in ::wxFontFamily docs the returned value acts as a rough,
631 basic classification of the main font properties (look, spacing).
633 If the current font face name is not recognized by wxFont or by the
634 underlying system, @c wxFONTFAMILY_DEFAULT is returned.
636 Note that currently this function is not very precise and so not
637 particularly useful. Font families mostly make sense only for font
638 creation, see SetFamily().
642 virtual wxFontFamily
GetFamily() const;
645 Returns the platform-dependent string completely describing this font.
647 Returned string is always non-empty unless the font is invalid (in
648 which case an assert is triggered).
650 Note that the returned string is not meant to be shown or edited by the user: a
651 typical use of this function is for serializing in string-form a wxFont object.
653 @see SetNativeFontInfo(), GetNativeFontInfoUserDesc()
655 wxString
GetNativeFontInfoDesc() const;
658 Returns a user-friendly string for this font object.
660 Returned string is always non-empty unless the font is invalid (in
661 which case an assert is triggered).
663 The string does not encode all wxFont infos under all platforms;
664 e.g. under wxMSW the font family is not present in the returned string.
666 Some examples of the formats of returned strings (which are platform-dependent)
667 are in SetNativeFontInfoUserDesc().
669 @see SetNativeFontInfoUserDesc(), GetNativeFontInfoDesc()
671 wxString
GetNativeFontInfoUserDesc() const;
673 const wxNativeFontInfo
*GetNativeFontInfo() const;
680 virtual int GetPointSize() const;
685 Note that under wxMSW if you passed to SetPixelSize() (or to the ctor)
686 a wxSize object with a null width value, you'll get a null width in
691 virtual wxSize
GetPixelSize() const;
694 Gets the font style. See ::wxFontStyle for a list of valid styles.
698 virtual wxFontStyle
GetStyle() const;
701 Returns @true if the font is underlined, @false otherwise.
705 virtual bool GetUnderlined() const;
708 Returns @true if the font is stricken-through, @false otherwise.
710 @see SetStrikethrough()
714 virtual bool GetStrikethrough() const;
717 Gets the font weight. See ::wxFontWeight for a list of valid weight identifiers.
721 virtual wxFontWeight
GetWeight() const;
724 Returns @true if the font is a fixed width (or monospaced) font,
725 @false if it is a proportional one or font is invalid.
727 Note that this function under some platforms is different than just testing
728 for the font family being equal to @c wxFONTFAMILY_TELETYPE because native
729 platform-specific functions are used for the check (resulting in a more
730 accurate return value).
732 virtual bool IsFixedWidth() const;
735 Returns @true if this object is a valid font, @false otherwise.
737 virtual bool IsOk() const;
743 @name Similar fonts creation
745 The functions in this section either modify the font in place or create
746 a new font similar to the given one but with its weight, style or size
752 Returns a bold version of this font.
761 Returns an italic version of this font.
767 wxFont
Italic() const;
770 Returns a larger version of this font.
772 The font size is multiplied by @c 1.2, the factor of @c 1.2 being
773 inspired by the W3C CSS specification.
775 @see MakeLarger(), Smaller(), Scaled()
779 wxFont
Larger() const;
782 Returns a smaller version of this font.
784 The font size is divided by @c 1.2, the factor of @c 1.2 being
785 inspired by the W3C CSS specification.
787 @see MakeSmaller(), Larger(), Scaled()
791 wxFont
Smaller() const;
794 Returns underlined version of this font.
796 @see MakeUnderlined()
800 wxFont
Underlined() const;
803 Returns stricken-through version of this font.
805 Currently stricken-through fonts are only supported in wxMSW and wxGTK.
807 @see MakeStrikethrough()
811 wxFont
Strikethrough() const;
814 Changes this font to be bold.
823 Changes this font to be italic.
829 wxFont
& MakeItalic();
832 Changes this font to be larger.
834 The font size is multiplied by @c 1.2, the factor of @c 1.2 being
835 inspired by the W3C CSS specification.
837 @see Larger(), MakeSmaller(), Scale()
841 wxFont
& MakeLarger();
844 Changes this font to be smaller.
846 The font size is divided by @c 1.2, the factor of @c 1.2 being
847 inspired by the W3C CSS specification.
849 @see Smaller(), MakeLarger(), Scale()
853 wxFont
& MakeSmaller();
856 Changes this font to be underlined.
862 wxFont
& MakeUnderlined();
865 Changes this font to be stricken-through.
867 Currently stricken-through fonts are only supported in wxMSW and wxGTK.
873 wxFont
& MakeStrikethrough();
876 Changes the size of this font.
878 The font size is multiplied by the given factor (which may be less than
879 1 to create a smaller version of the font).
881 @see Scaled(), MakeLarger(), MakeSmaller()
885 wxFont
& Scale(float x
);
888 Returns a scaled version of this font.
890 The font size is multiplied by the given factor (which may be less than
891 1 to create a smaller version of the font).
893 @see Scale(), Larger(), Smaller()
897 wxFont
Scaled(float x
) const;
904 These functions internally recreate the native font object with the new
910 Sets the encoding for this font.
912 Note that under wxGTK this function has no effect (because the underlying
913 Pango library always uses @c wxFONTENCODING_UTF8).
917 virtual void SetEncoding(wxFontEncoding encoding
);
920 Sets the facename for the font.
923 A valid facename, which should be on the end-user's system.
925 @remarks To avoid portability problems, don't rely on a specific face,
926 but specify the font family instead (see ::wxFontFamily and SetFamily()).
928 @return @true if the given face name exists; if the face name doesn't exist
929 in the user's system then the font is invalidated (so that IsOk() will
930 return @false) and @false is returned.
932 @see GetFaceName(), SetFamily()
934 virtual bool SetFaceName(const wxString
& faceName
);
937 Sets the font family.
939 As described in ::wxFontFamily docs the given @a family value acts as a rough,
940 basic indication of the main font properties (look, spacing).
942 Note that changing the font family results in changing the font face name.
945 One of the ::wxFontFamily values.
947 @see GetFamily(), SetFaceName()
949 virtual void SetFamily(wxFontFamily family
);
952 Creates the font corresponding to the given native font description string
953 which must have been previously returned by GetNativeFontInfoDesc().
955 If the string is invalid, font is unchanged.
956 This function is typically used for de-serializing a wxFont object
957 previously saved in a string-form.
959 @return @true if the creation was successful.
961 @see SetNativeFontInfoUserDesc()
963 bool SetNativeFontInfo(const wxString
& info
);
966 Creates the font corresponding to the given native font description string and
967 returns @true if the creation was successful.
969 Unlike SetNativeFontInfo(), this function accepts strings which are user-friendly.
970 Examples of accepted string formats are:
973 @hdr3col{platform, generic syntax, example}
974 @row3col{wxGTK2, <tt>[underlined] [strikethrough] [FACE-NAME] [bold] [oblique|italic] [POINTSIZE]</tt>, Monospace bold 10}
975 @row3col{wxMSW, <tt>[light|bold] [italic] [FACE-NAME] [POINTSIZE] [ENCODING]</tt>, Tahoma 10 WINDOWS-1252}
978 @todo add an example for wxMac
980 For more detailed information about the allowed syntaxes you can look at the
981 documentation of the native API used for font-rendering
982 (e.g. @c pango_font_description_from_string under GTK, although notice
983 that it doesn't support the "underlined" and "strikethrough" attributes
984 and so those are handled by wxWidgets itself).
986 Note that unlike SetNativeFontInfo(), this function doesn't always restore all
987 attributes of the wxFont object under all platforms; e.g. on wxMSW the font family
988 is not restored (because GetNativeFontInfoUserDesc doesn't return it on wxMSW).
989 If you want to serialize/deserialize a font in string form, you should use
990 GetNativeFontInfoDesc() and SetNativeFontInfo() instead.
992 @see SetNativeFontInfo()
994 bool SetNativeFontInfoUserDesc(const wxString
& info
);
996 void SetNativeFontInfo(const wxNativeFontInfo
& info
);
1001 The <em>point size</em> is defined as 1/72 of the Anglo-Saxon inch
1002 (25.4 mm): it is approximately 0.0139 inch or 352.8 um.
1009 virtual void SetPointSize(int pointSize
);
1012 Sets the pixel size.
1014 The height parameter of @a pixelSize must be positive while the width
1015 parameter may also be zero (to indicate that you're not interested in the
1016 width of the characters: a suitable width will be chosen for best rendering).
1018 This feature (specifying the font pixel size) is directly supported only
1019 under wxMSW and wxGTK currently; under other platforms a font with the
1020 closest size to the given one is found using binary search (this maybe slower).
1024 virtual void SetPixelSize(const wxSize
& pixelSize
);
1027 Sets the font style.
1030 One of the ::wxFontStyle enumeration values.
1034 virtual void SetStyle(wxFontStyle style
);
1037 Sets the font size using a predefined symbolic size name.
1039 This function allows to change font size to be (very) large or small
1040 compared to the standard font size.
1042 @see SetSymbolicSizeRelativeTo().
1046 void SetSymbolicSize(wxFontSymbolicSize size
);
1049 Sets the font size compared to the base font size.
1051 This is the same as SetSymbolicSize() except that it uses the given
1052 font size as the normal font size instead of the standard font size.
1056 void SetSymbolicSizeRelativeTo(wxFontSymbolicSize size
, int base
);
1062 @true to underline, @false otherwise.
1064 @see GetUnderlined()
1066 virtual void SetUnderlined(bool underlined
);
1069 Sets strike-through attribute of the font.
1071 Currently stricken-through fonts are only supported in wxMSW and wxGTK.
1073 @param strikethrough
1074 @true to add strike-through style, @false to remove it.
1076 @see GetStrikethrough()
1080 virtual void SetStrikethrough(bool strikethrough
);
1083 Sets the font weight.
1086 One of the ::wxFontWeight values.
1090 virtual void SetWeight(wxFontWeight weight
);
1096 Inequality operator.
1098 See @ref overview_refcount_equality "reference-counted object comparison" for
1101 bool operator!=(const wxFont
& font
) const;
1106 See @ref overview_refcount_equality "reference-counted object comparison" for
1109 bool operator==(const wxFont
& font
) const;
1112 Assignment operator, using @ref overview_refcount "reference counting".
1114 wxFont
& operator =(const wxFont
& font
);
1120 Returns the current application's default encoding.
1122 @see @ref overview_fontencoding, SetDefaultEncoding()
1124 static wxFontEncoding
GetDefaultEncoding();
1127 Sets the default font encoding.
1129 @see @ref overview_fontencoding, GetDefaultEncoding()
1131 static void SetDefaultEncoding(wxFontEncoding encoding
);
1135 This function takes the same parameters as the relative
1136 @ref wxFont::wxFont "wxFont constructor" and returns a new font
1137 object allocated on the heap.
1139 Their use is discouraged, use wxFont constructor from wxFontInfo
1142 static wxFont
* New(int pointSize
, wxFontFamily family
, wxFontStyle style
,
1143 wxFontWeight weight
,
1144 bool underline
= false,
1145 const wxString
& faceName
= wxEmptyString
,
1146 wxFontEncoding encoding
= wxFONTENCODING_DEFAULT
);
1147 static wxFont
* New(int pointSize
, wxFontFamily family
,
1148 int flags
= wxFONTFLAG_DEFAULT
,
1149 const wxString
& faceName
= wxEmptyString
,
1150 wxFontEncoding encoding
= wxFONTENCODING_DEFAULT
);
1151 static wxFont
* New(const wxSize
& pixelSize
,
1152 wxFontFamily family
,
1154 wxFontWeight weight
,
1155 bool underline
= false,
1156 const wxString
& faceName
= wxEmptyString
,
1157 wxFontEncoding encoding
= wxFONTENCODING_DEFAULT
);
1158 static wxFont
* New(const wxSize
& pixelSize
,
1159 wxFontFamily family
,
1160 int flags
= wxFONTFLAG_DEFAULT
,
1161 const wxString
& faceName
= wxEmptyString
,
1162 wxFontEncoding encoding
= wxFONTENCODING_DEFAULT
);
1165 static wxFont
*New(const wxNativeFontInfo
& nativeInfo
);
1166 static wxFont
*New(const wxString
& nativeInfoString
);
1178 Equivalent to wxSystemSettings::GetFont(wxSYS_DEFAULT_GUI_FONT).
1180 @see wxSystemSettings
1182 wxFont
* wxNORMAL_FONT
;
1185 A font using the @c wxFONTFAMILY_SWISS family and 2 points smaller than
1188 wxFont
* wxSMALL_FONT
;
1191 A font using the @c wxFONTFAMILY_ROMAN family and @c wxFONTSTYLE_ITALIC style and
1192 of the same size of ::wxNORMAL_FONT.
1194 wxFont
* wxITALIC_FONT
;
1197 A font identic to ::wxNORMAL_FONT except for the family used which is
1198 @c wxFONTFAMILY_SWISS.
1200 wxFont
* wxSWISS_FONT
;
1206 A font list is a list containing all fonts which have been created.
1207 There is only one instance of this class: ::wxTheFontList.
1209 Use this object to search for a previously created font of the desired type
1210 and create it if not already found.
1212 In some windowing systems, the font may be a scarce resource, so it is best to
1213 reuse old resources if possible. When an application finishes, all fonts will
1214 be deleted and their resources freed, eliminating the possibility of 'memory
1226 Constructor. The application should not construct its own font list:
1227 use the object pointer ::wxTheFontList.
1232 Finds a font of the given specification, or creates one and adds it to the
1233 list. See the @ref wxFont "wxFont constructor" for details of the arguments.
1235 wxFont
* FindOrCreateFont(int point_size
, wxFontFamily family
, wxFontStyle style
,
1236 wxFontWeight weight
, bool underline
= false,
1237 const wxString
& facename
= wxEmptyString
,
1238 wxFontEncoding encoding
= wxFONTENCODING_DEFAULT
);
1243 The global wxFontList instance.
1245 wxFontList
* wxTheFontList
;
1248 // ============================================================================
1249 // Global functions/macros
1250 // ============================================================================
1252 /** @addtogroup group_funcmacro_misc */
1256 Converts string to a wxFont best represented by the given string. Returns
1259 @see wxToString(const wxFont&)
1263 bool wxFromString(const wxString
& string
, wxFont
* font
);
1266 Converts the given wxFont into a string.
1268 @see wxFromString(const wxString&, wxFont*)
1272 wxString
wxToString(const wxFont
& font
);