]> git.saurik.com Git - wxWidgets.git/blame - interface/wx/font.h
Fix typo in wxStandardPathsBase::ResourceCat description and document it.
[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$
526954c5 6// Licence: wxWindows licence
23324ae1
FM
7/////////////////////////////////////////////////////////////////////////////
8
0b70c946
FM
9
10/**
6aea1e4a
FM
11 Standard font families: these are used mainly during wxFont creation to specify
12 the generic properties of the font without hardcoding in the sources a specific
13 face name.
14
15 wxFontFamily thus allows to group the font face names of fonts with similar
16 properties. Most wxWidgets ports use lists of fonts for each font family
17 inspired by the data taken from http://www.codestyle.org/css/font-family.
0b70c946
FM
18*/
19enum wxFontFamily
20{
21 wxFONTFAMILY_DEFAULT = wxDEFAULT, //!< Chooses a default font.
f76c0758 22
0b70c946
FM
23 wxFONTFAMILY_DECORATIVE = wxDECORATIVE, //!< A decorative font.
24 wxFONTFAMILY_ROMAN = wxROMAN, //!< A formal, serif font.
25 wxFONTFAMILY_SCRIPT = wxSCRIPT, //!< A handwriting font.
26 wxFONTFAMILY_SWISS = wxSWISS, //!< A sans-serif font.
f76c0758 27
6aea1e4a
FM
28 /// A fixed pitch font. Note that wxFont currently does not make distinctions
29 /// between @c wxFONTFAMILY_MODERN and @c wxFONTFAMILY_TELETYPE.
30 wxFONTFAMILY_MODERN = wxMODERN,
f76c0758 31
6aea1e4a 32 /// A teletype (i.e. monospaced) font.
f76c0758
VZ
33 /// Monospace fonts have a fixed width like typewriters and often have strong angular
34 /// or block serifs. Monospace font faces are often used code samples and have a simple,
6aea1e4a
FM
35 /// functional font style.
36 /// See also wxFont::IsFixedWidth() for an easy way to test for monospace property.
37 wxFONTFAMILY_TELETYPE = wxTELETYPE,
f76c0758 38
6aea1e4a
FM
39 /// Returned by wxFont::GetFamily() when the face name of the font cannot
40 /// be classified into one of the previous wxFontFamily values.
41 wxFONTFAMILY_UNKNOWN = wxFONTFAMILY_MAX,
42
43 wxFONTFAMILY_MAX
0b70c946
FM
44};
45
46/**
47 Font styles.
48*/
49enum wxFontStyle
50{
071de7a0 51 /// The font is drawn without slant.
0b70c946 52 wxFONTSTYLE_NORMAL = wxNORMAL,
071de7a0
FM
53
54 /// The font is slanted in an italic style.
0b70c946 55 wxFONTSTYLE_ITALIC = wxITALIC,
f76c0758
VZ
56
57 /// The font is slanted, but in a roman style.
071de7a0 58 /// Note that under wxMSW this style is the same as @c wxFONTSTYLE_ITALIC.
0b70c946 59 wxFONTSTYLE_SLANT = wxSLANT,
071de7a0 60
0b70c946
FM
61 wxFONTSTYLE_MAX
62};
63
64/**
65 Font weights.
66*/
67enum wxFontWeight
68{
69 wxFONTWEIGHT_NORMAL = wxNORMAL, //!< Normal font.
70 wxFONTWEIGHT_LIGHT = wxLIGHT, //!< Light font.
71 wxFONTWEIGHT_BOLD = wxBOLD, //!< Bold font.
72 wxFONTWEIGHT_MAX
73};
74
75/**
76 The font flag bits for the new font ctor accepting one combined flags word.
77*/
78enum wxFontFlag
79{
80 /// no special flags: font with default weight/slant/anti-aliasing
81 wxFONTFLAG_DEFAULT = 0,
82
83 /// slant flags (default: no slant)
84 wxFONTFLAG_ITALIC = 1 << 0,
85 wxFONTFLAG_SLANT = 1 << 1,
86
87 /// weight flags (default: medium)
88 wxFONTFLAG_LIGHT = 1 << 2,
89 wxFONTFLAG_BOLD = 1 << 3,
90
91 /// anti-aliasing flag: force on or off (default: the current system default)
92 wxFONTFLAG_ANTIALIASED = 1 << 4,
93 wxFONTFLAG_NOT_ANTIALIASED = 1 << 5,
94
95 /// underlined/strikethrough flags (default: no lines)
96 wxFONTFLAG_UNDERLINED = 1 << 6,
97 wxFONTFLAG_STRIKETHROUGH = 1 << 7,
98
99 /// the mask of all currently used flags
100 wxFONTFLAG_MASK = wxFONTFLAG_ITALIC |
101 wxFONTFLAG_SLANT |
102 wxFONTFLAG_LIGHT |
103 wxFONTFLAG_BOLD |
104 wxFONTFLAG_ANTIALIASED |
105 wxFONTFLAG_NOT_ANTIALIASED |
106 wxFONTFLAG_UNDERLINED |
107 wxFONTFLAG_STRIKETHROUGH
108};
109
110
111
112/**
113 Font encodings.
f76c0758 114
7ce58684 115 See wxFont::SetEncoding().
0b70c946
FM
116*/
117enum wxFontEncoding
118{
119 /// Default system encoding.
120 wxFONTENCODING_SYSTEM = -1, // system default
121
122 /// Default application encoding.
123 wxFONTENCODING_DEFAULT, // current default encoding
124
125 // ISO8859 standard defines a number of single-byte charsets
9a6fda22
FM
126 wxFONTENCODING_ISO8859_1, //!< West European (Latin1)
127 wxFONTENCODING_ISO8859_2, //!< Central and East European (Latin2)
128 wxFONTENCODING_ISO8859_3, //!< Esperanto (Latin3)
129 wxFONTENCODING_ISO8859_4, //!< Baltic (old) (Latin4)
130 wxFONTENCODING_ISO8859_5, //!< Cyrillic
131 wxFONTENCODING_ISO8859_6, //!< Arabic
132 wxFONTENCODING_ISO8859_7, //!< Greek
133 wxFONTENCODING_ISO8859_8, //!< Hebrew
134 wxFONTENCODING_ISO8859_9, //!< Turkish (Latin5)
135 wxFONTENCODING_ISO8859_10, //!< Variation of Latin4 (Latin6)
136 wxFONTENCODING_ISO8859_11, //!< Thai
137 wxFONTENCODING_ISO8859_12, //!< doesn't exist currently, but put it
138 //!< here anyhow to make all ISO8859
139 //!< consecutive numbers
140 wxFONTENCODING_ISO8859_13, //!< Baltic (Latin7)
141 wxFONTENCODING_ISO8859_14, //!< Latin8
142 wxFONTENCODING_ISO8859_15, //!< Latin9 (a.k.a. Latin0, includes euro)
0b70c946
FM
143 wxFONTENCODING_ISO8859_MAX,
144
145 // Cyrillic charset soup (see http://czyborra.com/charsets/cyrillic.html)
9a6fda22
FM
146 wxFONTENCODING_KOI8, //!< KOI8 Russian
147 wxFONTENCODING_KOI8_U, //!< KOI8 Ukrainian
148 wxFONTENCODING_ALTERNATIVE, //!< same as MS-DOS CP866
149 wxFONTENCODING_BULGARIAN, //!< used under Linux in Bulgaria
0b70c946
FM
150
151 // what would we do without Microsoft? They have their own encodings
152 // for DOS
9a6fda22
FM
153 wxFONTENCODING_CP437, //!< original MS-DOS codepage
154 wxFONTENCODING_CP850, //!< CP437 merged with Latin1
155 wxFONTENCODING_CP852, //!< CP437 merged with Latin2
156 wxFONTENCODING_CP855, //!< another cyrillic encoding
157 wxFONTENCODING_CP866, //!< and another one
0b70c946 158 // and for Windows
9a6fda22
FM
159 wxFONTENCODING_CP874, //!< WinThai
160 wxFONTENCODING_CP932, //!< Japanese (shift-JIS)
161 wxFONTENCODING_CP936, //!< Chinese simplified (GB)
162 wxFONTENCODING_CP949, //!< Korean (Hangul charset)
163 wxFONTENCODING_CP950, //!< Chinese (traditional - Big5)
164 wxFONTENCODING_CP1250, //!< WinLatin2
165 wxFONTENCODING_CP1251, //!< WinCyrillic
166 wxFONTENCODING_CP1252, //!< WinLatin1
167 wxFONTENCODING_CP1253, //!< WinGreek (8859-7)
168 wxFONTENCODING_CP1254, //!< WinTurkish
169 wxFONTENCODING_CP1255, //!< WinHebrew
170 wxFONTENCODING_CP1256, //!< WinArabic
171 wxFONTENCODING_CP1257, //!< WinBaltic (same as Latin 7)
0b70c946
FM
172 wxFONTENCODING_CP12_MAX,
173
9a6fda22
FM
174 wxFONTENCODING_UTF7, //!< UTF-7 Unicode encoding
175 wxFONTENCODING_UTF8, //!< UTF-8 Unicode encoding
176 wxFONTENCODING_EUC_JP, //!< Extended Unix Codepage for Japanese
177 wxFONTENCODING_UTF16BE, //!< UTF-16 Big Endian Unicode encoding
178 wxFONTENCODING_UTF16LE, //!< UTF-16 Little Endian Unicode encoding
179 wxFONTENCODING_UTF32BE, //!< UTF-32 Big Endian Unicode encoding
0b70c946
FM
180 wxFONTENCODING_UTF32LE, // UTF-32 Little Endian Unicode encoding
181
9a6fda22 182 wxFONTENCODING_MACROMAN, //!< the standard mac encodings
0b70c946
FM
183 wxFONTENCODING_MACJAPANESE,
184 wxFONTENCODING_MACCHINESETRAD,
185 wxFONTENCODING_MACKOREAN,
186 wxFONTENCODING_MACARABIC,
187 wxFONTENCODING_MACHEBREW,
188 wxFONTENCODING_MACGREEK,
189 wxFONTENCODING_MACCYRILLIC,
190 wxFONTENCODING_MACDEVANAGARI,
191 wxFONTENCODING_MACGURMUKHI,
192 wxFONTENCODING_MACGUJARATI,
193 wxFONTENCODING_MACORIYA,
194 wxFONTENCODING_MACBENGALI,
195 wxFONTENCODING_MACTAMIL,
196 wxFONTENCODING_MACTELUGU,
197 wxFONTENCODING_MACKANNADA,
198 wxFONTENCODING_MACMALAJALAM,
199 wxFONTENCODING_MACSINHALESE,
200 wxFONTENCODING_MACBURMESE,
201 wxFONTENCODING_MACKHMER,
202 wxFONTENCODING_MACTHAI,
203 wxFONTENCODING_MACLAOTIAN,
204 wxFONTENCODING_MACGEORGIAN,
205 wxFONTENCODING_MACARMENIAN,
206 wxFONTENCODING_MACCHINESESIMP,
207 wxFONTENCODING_MACTIBETAN,
208 wxFONTENCODING_MACMONGOLIAN,
209 wxFONTENCODING_MACETHIOPIC,
210 wxFONTENCODING_MACCENTRALEUR,
211 wxFONTENCODING_MACVIATNAMESE,
212 wxFONTENCODING_MACARABICEXT,
213 wxFONTENCODING_MACSYMBOL,
214 wxFONTENCODING_MACDINGBATS,
215 wxFONTENCODING_MACTURKISH,
216 wxFONTENCODING_MACCROATIAN,
217 wxFONTENCODING_MACICELANDIC,
218 wxFONTENCODING_MACROMANIAN,
219 wxFONTENCODING_MACCELTIC,
220 wxFONTENCODING_MACGAELIC,
221 wxFONTENCODING_MACKEYBOARD,
222
223 // more CJK encodings (for historical reasons some are already declared
224 // above)
9a6fda22 225 wxFONTENCODING_ISO2022_JP, //!< ISO-2022-JP JIS encoding
0b70c946 226
9a6fda22 227 wxFONTENCODING_MAX, //!< highest enumerated encoding value
0b70c946
FM
228
229 wxFONTENCODING_MACMIN = wxFONTENCODING_MACROMAN ,
230 wxFONTENCODING_MACMAX = wxFONTENCODING_MACKEYBOARD ,
231
232 // aliases for endian-dependent UTF encodings
9a6fda22
FM
233 wxFONTENCODING_UTF16, //!< native UTF-16
234 wxFONTENCODING_UTF32, //!< native UTF-32
235
236 /// Alias for the native Unicode encoding on this platform
237 /// (this is used by wxEncodingConverter and wxUTFFile only for now)
238 wxFONTENCODING_UNICODE,
0b70c946 239
9a6fda22
FM
240 wxFONTENCODING_GB2312 = wxFONTENCODING_CP936, //!< Simplified Chinese
241 wxFONTENCODING_BIG5 = wxFONTENCODING_CP950, //!< Traditional Chinese
3d4e20dd
VZ
242 wxFONTENCODING_SHIFT_JIS = wxFONTENCODING_CP932, //!< Shift JIS
243 wxFONTENCODING_EUC_KR = wxFONTENCODING_CP949 //!< Korean
0b70c946
FM
244};
245
246
247
23324ae1
FM
248/**
249 @class wxFont
7c913512 250
0b70c946
FM
251 A font is an object which determines the appearance of text.
252 Fonts are used for drawing text to a device context, and setting the appearance
253 of a window's text.
7c913512 254
0b70c946 255 This class uses @ref overview_refcount "reference counting and copy-on-write"
23324ae1
FM
256 internally so that assignments between two instances of this class are very
257 cheap. You can therefore use actual objects instead of pointers without
258 efficiency problems. If an instance of this class is changed it will create
259 its own data internally so that other instances, which previously shared the
260 data using the reference counting, are not affected.
7c913512 261
23324ae1 262 You can retrieve the current system font settings with wxSystemSettings.
7c913512 263
23324ae1
FM
264 @library{wxcore}
265 @category{gdi}
7c913512 266
23324ae1 267 @stdobjects
65874118 268 ::wxNullFont, ::wxNORMAL_FONT, ::wxSMALL_FONT, ::wxITALIC_FONT, ::wxSWISS_FONT
7c913512 269
0b70c946
FM
270 @see @ref overview_font, wxDC::SetFont, wxDC::DrawText,
271 wxDC::GetTextExtent, wxFontDialog, wxSystemSettings
23324ae1
FM
272*/
273class wxFont : public wxGDIObject
274{
275public:
45a591fa 276 /**
0b70c946 277 Default ctor.
45a591fa
VZ
278 */
279 wxFont();
280
281 /**
0b70c946 282 Copy constructor, uses @ref overview_refcount "reference counting".
45a591fa
VZ
283 */
284 wxFont(const wxFont& font);
285
23324ae1
FM
286 /**
287 Creates a font object with the specified attributes.
3c4f71cc 288
7c913512 289 @param pointSize
b5791cc7 290 Size in points. See SetPointSize() for more info.
45a591fa 291 @param family
6aea1e4a
FM
292 The font family: a generic portable way of referring to fonts without specifying a
293 facename. This parameter must be one of the ::wxFontFamily enumeration values.
294 If the @a faceName argument is provided, then it overrides the font family.
45a591fa 295 @param style
b5791cc7 296 One of @c wxFONTSTYLE_NORMAL, @c wxFONTSTYLE_SLANT and @c wxFONTSTYLE_ITALIC.
45a591fa 297 @param weight
f76c0758 298 Font weight, sometimes also referred to as font boldness.
b5791cc7 299 One of the ::wxFontWeight enumeration values.
45a591fa 300 @param underline
0b70c946
FM
301 The value can be @true or @false.
302 At present this has an effect on Windows and Motif 2.x only.
45a591fa 303 @param faceName
6aea1e4a
FM
304 An optional string specifying the face name to be used.
305 If it is an empty string, a default face name will be chosen based on the family.
45a591fa 306 @param encoding
0b70c946
FM
307 An encoding which may be one of the enumeration values of ::wxFontEncoding.
308 Briefly these can be summed up as:
309 <TABLE>
b5791cc7
FM
310 <TR><TD>@c wxFONTENCODING_SYSTEM</TD><TD>Default system encoding.</TD></TR>
311 <TR><TD>@c wxFONTENCODING_DEFAULT</TD><TD>
8f1337ed 312 Default application encoding: this is the encoding set by calls to
f76c0758
VZ
313 SetDefaultEncoding() and which may be set to, say, KOI8 to create all
314 fonts by default with KOI8 encoding. Initially, the default application
8f1337ed 315 encoding is the same as default system encoding.</TD></TR>
b5791cc7
FM
316 <TR><TD>@c wxFONTENCODING_ISO8859_1...15</TD><TD>ISO8859 encodings.</TD></TR>
317 <TR><TD>@c wxFONTENCODING_KOI8</TD><TD>The standard Russian encoding for Internet.</TD></TR>
318 <TR><TD>@c wxFONTENCODING_CP1250...1252</TD><TD>Windows encodings similar to ISO8859 (but not identical).</TD></TR>
0b70c946 319 </TABLE>
45a591fa 320 If the specified encoding isn't available, no font is created
8f1337ed 321 (see also @ref overview_fontencoding).
45a591fa
VZ
322
323 @remarks If the desired font does not exist, the closest match will be
0b70c946 324 chosen. Under Windows, only scalable TrueType fonts are used.
45a591fa 325 */
882678eb 326 wxFont(int pointSize, wxFontFamily family, wxFontStyle style,
45a591fa 327 wxFontWeight weight,
11e3af6e 328 bool underline = false,
e9c3992c 329 const wxString& faceName = wxEmptyString,
45a591fa 330 wxFontEncoding encoding = wxFONTENCODING_DEFAULT);
0b70c946 331
45a591fa
VZ
332 /**
333 Creates a font object with the specified attributes.
334
7c913512 335 @param pixelSize
b5791cc7 336 Size in pixels. See SetPixelSize() for more info.
7c913512 337 @param family
6aea1e4a
FM
338 The font family: a generic portable way of referring to fonts without specifying a
339 facename. This parameter must be one of the ::wxFontFamily enumeration values.
340 If the @a faceName argument is provided, then it overrides the font family.
4cc4bfaf 341 @param style
b5791cc7 342 One of @c wxFONTSTYLE_NORMAL, @c wxFONTSTYLE_SLANT and @c wxFONTSTYLE_ITALIC.
7c913512 343 @param weight
0b70c946
FM
344 Font weight, sometimes also referred to as font boldness.
345 One of the ::wxFontWeight enumeration values.
4cc4bfaf 346 @param underline
0b70c946
FM
347 The value can be @true or @false.
348 At present this has an effect on Windows and Motif 2.x only.
4cc4bfaf 349 @param faceName
6aea1e4a
FM
350 An optional string specifying the face name to be used.
351 If it is an empty string, a default face name will be chosen based on the family.
7c913512 352 @param encoding
0b70c946
FM
353 An encoding which may be one of the enumeration values of ::wxFontEncoding.
354 Briefly these can be summed up as:
355 <TABLE>
b5791cc7
FM
356 <TR><TD>@c wxFONTENCODING_SYSTEM</TD><TD>Default system encoding.</TD></TR>
357 <TR><TD>@c wxFONTENCODING_DEFAULT</TD><TD>
8f1337ed 358 Default application encoding: this is the encoding set by calls to
f76c0758
VZ
359 SetDefaultEncoding() and which may be set to, say, KOI8 to create all
360 fonts by default with KOI8 encoding. Initially, the default application
8f1337ed 361 encoding is the same as default system encoding.</TD></TR>
b5791cc7
FM
362 <TR><TD>@c wxFONTENCODING_ISO8859_1...15</TD><TD>ISO8859 encodings.</TD></TR>
363 <TR><TD>@c wxFONTENCODING_KOI8</TD><TD>The standard Russian encoding for Internet.</TD></TR>
364 <TR><TD>@c wxFONTENCODING_CP1250...1252</TD><TD>Windows encodings similar to ISO8859 (but not identical).</TD></TR>
0b70c946 365 </TABLE>
4cc4bfaf 366 If the specified encoding isn't available, no font is created
8f1337ed 367 (see also @ref overview_fontencoding).
3c4f71cc 368
23324ae1 369 @remarks If the desired font does not exist, the closest match will be
0b70c946 370 chosen. Under Windows, only scalable TrueType fonts are used.
23324ae1 371 */
7c913512 372 wxFont(const wxSize& pixelSize, wxFontFamily family,
882678eb 373 wxFontStyle style, wxFontWeight weight,
11e3af6e 374 bool underline = false,
e9c3992c 375 const wxString& faceName = wxEmptyString,
7c913512 376 wxFontEncoding encoding = wxFONTENCODING_DEFAULT);
23324ae1 377
20cc4e19
VZ
378 /**
379 Constructor from font description string.
380
6aea1e4a
FM
381 This constructor uses SetNativeFontInfo() to initialize the font.
382 If @a fontdesc is invalid the font remains uninitialized, i.e. its IsOk() method
20cc4e19
VZ
383 will return @false.
384 */
385 wxFont(const wxString& fontdesc);
386
23324ae1
FM
387 /**
388 Destructor.
0b70c946 389
674d80a7 390 See @ref overview_refcount_destruct "reference-counted object destruction"
0b70c946 391 for more info.
3c4f71cc 392
23324ae1 393 @remarks Although all remaining fonts are deleted when the application
4cc4bfaf
FM
394 exits, the application should try to clean up all fonts
395 itself. This is because wxWidgets cannot know if a
396 pointer to the font object is stored in an application
397 data structure, and there is a risk of double deletion.
23324ae1 398 */
adaaa686 399 virtual ~wxFont();
23324ae1 400
f76c0758 401
23324ae1 402 /**
060c4f90 403 @name Getters
23324ae1 404 */
060c4f90 405 //@{
f76c0758 406
7ce58684
FM
407 /**
408 Returns the encoding of this font.
f76c0758 409
7ce58684 410 Note that under wxGTK the returned value is always @c wxFONTENCODING_UTF8.
f76c0758 411
7ce58684
FM
412 @see SetEncoding()
413 */
414 virtual wxFontEncoding GetEncoding() const;
f76c0758 415
23324ae1 416 /**
6aea1e4a
FM
417 Returns the face name associated with the font, or the empty string if
418 there is no face information.
3c4f71cc 419
4cc4bfaf 420 @see SetFaceName()
23324ae1 421 */
adaaa686 422 virtual wxString GetFaceName() const;
23324ae1
FM
423
424 /**
6aea1e4a
FM
425 Gets the font family.
426 As described in ::wxFontFamily docs the returned value acts as a rough,
427 basic classification of the main font properties (look, spacing).
f76c0758 428
6aea1e4a
FM
429 If the current font face name is not recognized by wxFont or by the
430 underlying system, @c wxFONTFAMILY_UNKNOWN is returned.
f76c0758 431
f7008bad 432 Note that currently this function is rather unreliable (@c wxFONTFAMILY_UNKNOWN
f76c0758 433 is returned in too many cases) and not particularly useful.
060c4f90 434 Font families mostly make sense only for font creation; see SetFamily().
3c4f71cc 435
4cc4bfaf 436 @see SetFamily()
23324ae1 437 */
26818748 438 virtual wxFontFamily GetFamily() const;
23324ae1
FM
439
440 /**
441 Returns the platform-dependent string completely describing this font.
64932e41
VZ
442
443 Returned string is always non-empty unless the font is invalid (in
444 which case an assert is triggered).
0b70c946 445
23324ae1 446 Note that the returned string is not meant to be shown or edited by the user: a
0b70c946 447 typical use of this function is for serializing in string-form a wxFont object.
3c4f71cc 448
a912ea26 449 @see SetNativeFontInfo(), GetNativeFontInfoUserDesc()
23324ae1 450 */
328f5751 451 wxString GetNativeFontInfoDesc() const;
23324ae1
FM
452
453 /**
0b70c946 454 Returns a user-friendly string for this font object.
64932e41
VZ
455
456 Returned string is always non-empty unless the font is invalid (in
457 which case an assert is triggered).
f76c0758 458
a912ea26
FM
459 The string does not encode all wxFont infos under all platforms;
460 e.g. under wxMSW the font family is not present in the returned string.
0b70c946 461
23324ae1
FM
462 Some examples of the formats of returned strings (which are platform-dependent)
463 are in SetNativeFontInfoUserDesc().
3c4f71cc 464
a912ea26 465 @see SetNativeFontInfoUserDesc(), GetNativeFontInfoDesc()
23324ae1 466 */
adaaa686 467 wxString GetNativeFontInfoUserDesc() const;
23324ae1
FM
468
469 /**
470 Gets the point size.
3c4f71cc 471
4cc4bfaf 472 @see SetPointSize()
23324ae1 473 */
adaaa686 474 virtual int GetPointSize() const;
23324ae1
FM
475
476 /**
b5791cc7 477 Gets the pixel size.
f76c0758 478
b5791cc7
FM
479 Note that under wxMSW if you passed to SetPixelSize() (or to the ctor)
480 a wxSize object with a null width value, you'll get a null width in
481 the returned object.
482
483 @see SetPixelSize()
484 */
485 virtual wxSize GetPixelSize() const;
f76c0758 486
b5791cc7
FM
487 /**
488 Gets the font style. See ::wxFontStyle for a list of valid styles.
3c4f71cc 489
4cc4bfaf 490 @see SetStyle()
23324ae1 491 */
26818748 492 virtual wxFontStyle GetStyle() const;
23324ae1
FM
493
494 /**
495 Returns @true if the font is underlined, @false otherwise.
3c4f71cc 496
4cc4bfaf 497 @see SetUnderlined()
23324ae1 498 */
adaaa686 499 virtual bool GetUnderlined() const;
23324ae1
FM
500
501 /**
b5791cc7 502 Gets the font weight. See ::wxFontWeight for a list of valid weight identifiers.
3c4f71cc 503
4cc4bfaf 504 @see SetWeight()
23324ae1 505 */
26818748 506 virtual wxFontWeight GetWeight() const;
23324ae1
FM
507
508 /**
509 Returns @true if the font is a fixed width (or monospaced) font,
510 @false if it is a proportional one or font is invalid.
f76c0758 511
6aea1e4a
FM
512 Note that this function under some platforms is different than just testing
513 for the font family being equal to @c wxFONTFAMILY_TELETYPE because native
514 platform-specific functions are used for the check (resulting in a more
515 accurate return value).
23324ae1 516 */
adaaa686 517 virtual bool IsFixedWidth() const;
23324ae1
FM
518
519 /**
520 Returns @true if this object is a valid font, @false otherwise.
521 */
0004982c 522 virtual bool IsOk() const;
f76c0758
VZ
523
524 //@}
525
526
527 /**
528 @name Similar fonts creation
529
6e7d2550
VZ
530 The functions in this section either modify the font in place or create
531 a new font similar to the given one but with its weight, style or size
532 changed.
f76c0758
VZ
533 */
534 //@{
535
536 /**
efb09182 537 Returns a bold version of this font.
6e7d2550
VZ
538
539 @see MakeBold()
540
541 @since 2.9.1
f76c0758 542 */
6e7d2550 543 wxFont Bold() const;
f76c0758
VZ
544
545 /**
efb09182 546 Returns an italic version of this font.
6e7d2550
VZ
547
548 @see MakeItalic()
549
550 @since 2.9.1
f76c0758 551 */
6e7d2550 552 wxFont Italic() const;
f76c0758
VZ
553
554 /**
efb09182 555 Returns a larger version of this font.
f76c0758 556
efb09182
VZ
557 The font size is multiplied by @c 1.2, the factor of @c 1.2 being
558 inspired by the W3C CSS specification.
f76c0758 559
efb09182 560 @see MakeLarger(), Smaller(), Scaled()
6e7d2550
VZ
561
562 @since 2.9.1
563 */
564 wxFont Larger() const;
565
efb09182
VZ
566 /**
567 Returns a smaller version of this font.
568
569 The font size is divided by @c 1.2, the factor of @c 1.2 being
570 inspired by the W3C CSS specification.
571
572 @see MakeSmaller(), Larger(), Scaled()
573
574 @since 2.9.1
575 */
576 wxFont Smaller() const;
577
6e7d2550
VZ
578 /**
579 Changes this font to be bold.
580
581 @see Bold()
582
583 @since 2.9.1
584 */
585 wxFont& MakeBold();
586
587 /**
588 Changes this font to be italic.
589
590 @see Italic()
591
592 @since 2.9.1
f76c0758 593 */
6e7d2550
VZ
594 wxFont& MakeItalic();
595
596 /**
597 Changes this font to be larger.
598
efb09182
VZ
599 The font size is multiplied by @c 1.2, the factor of @c 1.2 being
600 inspired by the W3C CSS specification.
6e7d2550
VZ
601
602 @see Larger(), MakeSmaller(), Scale()
603
604 @since 2.9.1
605 */
606 wxFont& MakeLarger();
f76c0758
VZ
607
608 /**
efb09182 609 Changes this font to be smaller.
f76c0758 610
efb09182
VZ
611 The font size is divided by @c 1.2, the factor of @c 1.2 being
612 inspired by the W3C CSS specification.
f76c0758 613
efb09182 614 @see Smaller(), MakeLarger(), Scale()
6e7d2550
VZ
615
616 @since 2.9.1
f76c0758 617 */
6e7d2550
VZ
618 wxFont& MakeSmaller();
619
620 /**
621 Changes the size of this font.
622
623 The font size is multiplied by the given factor (which may be less than
624 1 to create a smaller version of the font).
625
626 @see Scaled(), MakeLarger(), MakeSmaller()
627
628 @since 2.9.1
629 */
630 wxFont& Scale(float x);
f76c0758
VZ
631
632 /**
efb09182 633 Returns a scaled version of this font.
f76c0758
VZ
634
635 The font size is multiplied by the given factor (which may be less than
636 1 to create a smaller version of the font).
6e7d2550
VZ
637
638 @see Scale(), Larger(), Smaller()
639
640 @since 2.9.1
641 */
642 wxFont Scaled(float x) const;
643
23324ae1 644 //@}
f76c0758 645
23324ae1 646 /**
060c4f90 647 @name Setters
f76c0758 648
060c4f90
FM
649 These functions internally recreate the native font object with the new
650 specified property.
23324ae1 651 */
060c4f90
FM
652 //@{
653
7ce58684
FM
654 /**
655 Sets the encoding for this font.
f76c0758 656
7ce58684
FM
657 Note that under wxGTK this function has no effect (because the underlying
658 Pango library always uses @c wxFONTENCODING_UTF8).
f76c0758 659
7ce58684
FM
660 @see GetEncoding()
661 */
662 virtual void SetEncoding(wxFontEncoding encoding);
23324ae1
FM
663
664 /**
665 Sets the facename for the font.
3c4f71cc 666
7c913512 667 @param faceName
4cc4bfaf 668 A valid facename, which should be on the end-user's system.
3c4f71cc 669
23324ae1 670 @remarks To avoid portability problems, don't rely on a specific face,
f7008bad
FM
671 but specify the font family instead (see ::wxFontFamily and SetFamily()).
672
673 @return @true if the given face name exists; if the face name doesn't exist
f76c0758 674 in the user's system then the font is invalidated (so that IsOk() will
f7008bad 675 return @false) and @false is returned.
3c4f71cc 676
4cc4bfaf 677 @see GetFaceName(), SetFamily()
23324ae1 678 */
adaaa686 679 virtual bool SetFaceName(const wxString& faceName);
23324ae1
FM
680
681 /**
682 Sets the font family.
f76c0758 683
060c4f90
FM
684 As described in ::wxFontFamily docs the given @a family value acts as a rough,
685 basic indication of the main font properties (look, spacing).
686
687 Note that changing the font family results in changing the font face name.
3c4f71cc 688
7c913512 689 @param family
0b70c946 690 One of the ::wxFontFamily values.
3c4f71cc 691
4cc4bfaf 692 @see GetFamily(), SetFaceName()
23324ae1 693 */
a44f3b5a 694 virtual void SetFamily(wxFontFamily family);
23324ae1
FM
695
696 /**
0b70c946
FM
697 Creates the font corresponding to the given native font description string
698 which must have been previously returned by GetNativeFontInfoDesc().
699
700 If the string is invalid, font is unchanged.
701 This function is typically used for de-serializing a wxFont object
702 previously saved in a string-form.
703
704 @return @true if the creation was successful.
3c4f71cc 705
4cc4bfaf 706 @see SetNativeFontInfoUserDesc()
23324ae1
FM
707 */
708 bool SetNativeFontInfo(const wxString& info);
709
710 /**
711 Creates the font corresponding to the given native font description string and
0b70c946 712 returns @true if the creation was successful.
3c4f71cc 713
0b70c946
FM
714 Unlike SetNativeFontInfo(), this function accepts strings which are user-friendly.
715 Examples of accepted string formats are:
3c4f71cc 716
0b70c946
FM
717 @beginTable
718 @hdr3col{platform, generic syntax, example}
b5791cc7
FM
719 @row3col{wxGTK2, <tt>[FACE-NAME] [bold] [oblique|italic] [POINTSIZE]</tt>, Monospace bold 10}
720 @row3col{wxMSW, <tt>[light|bold] [italic] [FACE-NAME] [POINTSIZE] [ENCODING]</tt>, Tahoma 10 WINDOWS-1252}
0b70c946 721 @endTable
3c4f71cc 722
0b70c946 723 @todo add an example for wxMac
3c4f71cc 724
23324ae1 725 For more detailed information about the allowed syntaxes you can look at the
0b70c946
FM
726 documentation of the native API used for font-rendering
727 (e.g. @c pango_font_description_from_string on GTK).
f76c0758 728
a912ea26
FM
729 Note that unlike SetNativeFontInfo(), this function doesn't always restore all
730 attributes of the wxFont object under all platforms; e.g. on wxMSW the font family
731 is not restored (because GetNativeFontInfoUserDesc doesn't return it on wxMSW).
732 If you want to serialize/deserialize a font in string form, you should use
733 GetNativeFontInfoDesc() and SetNativeFontInfo() instead.
3c4f71cc 734
4cc4bfaf 735 @see SetNativeFontInfo()
23324ae1
FM
736 */
737 bool SetNativeFontInfoUserDesc(const wxString& info);
738
739 /**
740 Sets the point size.
f76c0758
VZ
741
742 The <em>point size</em> is defined as 1/72 of the anglo-Saxon inch
743 (25.4 mm): it is approximately 0.0139 inch or 352.8 um.
3c4f71cc 744
7c913512 745 @param pointSize
4cc4bfaf 746 Size in points.
3c4f71cc 747
4cc4bfaf 748 @see GetPointSize()
23324ae1 749 */
adaaa686 750 virtual void SetPointSize(int pointSize);
23324ae1 751
b5791cc7
FM
752 /**
753 Sets the pixel size.
f76c0758 754
b5791cc7
FM
755 The height parameter of @a pixelSize must be positive while the width
756 parameter may also be zero (to indicate that you're not interested in the
757 width of the characters: a suitable width will be chosen for best rendering).
f76c0758
VZ
758
759 This feature (specifying the font pixel size) is directly supported only
760 under wxMSW and wxGTK currently; under other platforms a font with the
b5791cc7
FM
761 closest size to the given one is found using binary search (this maybe slower).
762
763 @see GetPixelSize()
764 */
765 virtual void SetPixelSize(const wxSize& pixelSize);
f76c0758 766
23324ae1
FM
767 /**
768 Sets the font style.
3c4f71cc 769
7c913512 770 @param style
0b70c946 771 One of the ::wxFontStyle enumeration values.
3c4f71cc 772
4cc4bfaf 773 @see GetStyle()
23324ae1 774 */
a44f3b5a 775 virtual void SetStyle(wxFontStyle style);
23324ae1
FM
776
777 /**
778 Sets underlining.
3c4f71cc 779
45a591fa 780 @param underlined
4cc4bfaf 781 @true to underline, @false otherwise.
3c4f71cc 782
4cc4bfaf 783 @see GetUnderlined()
23324ae1 784 */
26818748 785 virtual void SetUnderlined(bool underlined);
23324ae1
FM
786
787 /**
788 Sets the font weight.
3c4f71cc 789
7c913512 790 @param weight
0b70c946 791 One of the ::wxFontWeight values.
3c4f71cc 792
4cc4bfaf 793 @see GetWeight()
23324ae1 794 */
a44f3b5a 795 virtual void SetWeight(wxFontWeight weight);
f76c0758 796
060c4f90
FM
797 //@}
798
23324ae1
FM
799
800 /**
801 Inequality operator.
0b70c946 802
674d80a7 803 See @ref overview_refcount_equality "reference-counted object comparison" for
23324ae1
FM
804 more info.
805 */
fadc2df6 806 bool operator!=(const wxFont& font) const;
23324ae1 807
23324ae1
FM
808 /**
809 Equality operator.
0b70c946 810
674d80a7 811 See @ref overview_refcount_equality "reference-counted object comparison" for
23324ae1
FM
812 more info.
813 */
fadc2df6 814 bool operator==(const wxFont& font) const;
0b70c946
FM
815
816 /**
817 Assignment operator, using @ref overview_refcount "reference counting".
818 */
819 wxFont& operator =(const wxFont& font);
f76c0758
VZ
820
821
060c4f90
FM
822 // statics
823
824 /**
825 Returns the current application's default encoding.
826
827 @see @ref overview_fontencoding, SetDefaultEncoding()
828 */
829 static wxFontEncoding GetDefaultEncoding();
830
831 /**
832 Sets the default font encoding.
833
834 @see @ref overview_fontencoding, GetDefaultEncoding()
835 */
836 static void SetDefaultEncoding(wxFontEncoding encoding);
f76c0758 837
060c4f90
FM
838 //@{
839 /**
840 This function takes the same parameters as the relative
841 @ref wxFont::wxFont "wxFont constructor" and returns a new font
842 object allocated on the heap.
843 */
844 static wxFont* New(int pointSize, wxFontFamily family, wxFontStyle style,
845 wxFontWeight weight,
846 bool underline = false,
847 const wxString& faceName = wxEmptyString,
848 wxFontEncoding encoding = wxFONTENCODING_DEFAULT);
849 static wxFont* New(int pointSize, wxFontFamily family,
850 int flags = wxFONTFLAG_DEFAULT,
851 const wxString& faceName = wxEmptyString,
852 wxFontEncoding encoding = wxFONTENCODING_DEFAULT);
853 static wxFont* New(const wxSize& pixelSize,
854 wxFontFamily family,
855 wxFontStyle style,
856 wxFontWeight weight,
857 bool underline = false,
858 const wxString& faceName = wxEmptyString,
859 wxFontEncoding encoding = wxFONTENCODING_DEFAULT);
860 static wxFont* New(const wxSize& pixelSize,
861 wxFontFamily family,
862 int flags = wxFONTFLAG_DEFAULT,
863 const wxString& faceName = wxEmptyString,
864 wxFontEncoding encoding = wxFONTENCODING_DEFAULT);
865 //@}
23324ae1 866};
e54c96f1
FM
867
868
869/**
65874118 870 An empty wxFont.
e54c96f1 871*/
7fa7088e 872wxFont wxNullFont;
e54c96f1
FM
873
874/**
0b70c946 875 Equivalent to wxSystemSettings::GetFont(wxSYS_DEFAULT_GUI_FONT).
f76c0758 876
b5791cc7 877 @see wxSystemSettings
e54c96f1 878*/
7fa7088e 879wxFont wxNORMAL_FONT;
e54c96f1
FM
880
881/**
b5791cc7 882 A font using the @c wxFONTFAMILY_SWISS family and 2 points smaller than
0b70c946 883 ::wxNORMAL_FONT.
e54c96f1 884*/
7fa7088e 885wxFont wxSMALL_FONT;
e54c96f1
FM
886
887/**
b5791cc7 888 A font using the @c wxFONTFAMILY_ROMAN family and @c wxFONTSTYLE_ITALIC style and
0b70c946 889 of the same size of ::wxNORMAL_FONT.
e54c96f1 890*/
7fa7088e 891wxFont wxITALIC_FONT;
e54c96f1
FM
892
893/**
0b70c946 894 A font identic to ::wxNORMAL_FONT except for the family used which is
b5791cc7 895 @c wxFONTFAMILY_SWISS.
e54c96f1 896*/
7fa7088e
BP
897wxFont wxSWISS_FONT;
898
899
65874118
FM
900/**
901 @class wxFontList
65874118 902
0b70c946
FM
903 A font list is a list containing all fonts which have been created.
904 There is only one instance of this class: ::wxTheFontList.
905
906 Use this object to search for a previously created font of the desired type
907 and create it if not already found.
908
65874118
FM
909 In some windowing systems, the font may be a scarce resource, so it is best to
910 reuse old resources if possible. When an application finishes, all fonts will
0b70c946 911 be deleted and their resources freed, eliminating the possibility of 'memory
65874118
FM
912 leaks'.
913
914 @library{wxcore}
915 @category{gdi}
916
917 @see wxFont
918*/
919class wxFontList : public wxList
920{
921public:
922 /**
923 Constructor. The application should not construct its own font list:
0b70c946 924 use the object pointer ::wxTheFontList.
65874118
FM
925 */
926 wxFontList();
927
928 /**
929 Finds a font of the given specification, or creates one and adds it to the
0b70c946 930 list. See the @ref wxFont "wxFont constructor" for details of the arguments.
65874118 931 */
a44f3b5a
FM
932 wxFont* FindOrCreateFont(int point_size, wxFontFamily family, wxFontStyle style,
933 wxFontWeight weight, bool underline = false,
934 const wxString& facename = wxEmptyString,
65874118
FM
935 wxFontEncoding encoding = wxFONTENCODING_DEFAULT);
936};
937
938
0b70c946
FM
939/**
940 The global wxFontList instance.
941*/
942wxFontList* wxTheFontList;
943
7fa7088e
BP
944
945// ============================================================================
946// Global functions/macros
947// ============================================================================
948
b21126db 949/** @addtogroup group_funcmacro_misc */
7fa7088e 950//@{
e54c96f1
FM
951
952/**
7fa7088e
BP
953 Converts string to a wxFont best represented by the given string. Returns
954 @true on success.
955
956 @see wxToString(const wxFont&)
957
958 @header{wx/font.h}
e54c96f1 959*/
7fa7088e 960bool wxFromString(const wxString& string, wxFont* font);
e54c96f1
FM
961
962/**
7fa7088e
BP
963 Converts the given wxFont into a string.
964
965 @see wxFromString(const wxString&, wxFont*)
966
967 @header{wx/font.h}
e54c96f1 968*/
7fa7088e 969wxString wxToString(const wxFont& font);
e54c96f1 970
7fa7088e 971//@}
e54c96f1 972