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