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