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