]>
git.saurik.com Git - wxWidgets.git/blob - interface/wx/font.h
1 /////////////////////////////////////////////////////////////////////////////
3 // Purpose: interface of wxFont
4 // Author: wxWidgets team
6 // Licence: wxWindows license
7 /////////////////////////////////////////////////////////////////////////////
12 A font is an object which determines the appearance of text. Fonts are
13 used for drawing text to a device context, and setting the appearance of
16 This class uses @ref overview_trefcount "reference counting and copy-on-write"
17 internally so that assignments between two instances of this class are very
18 cheap. You can therefore use actual objects instead of pointers without
19 efficiency problems. If an instance of this class is changed it will create
20 its own data internally so that other instances, which previously shared the
21 data using the reference counting, are not affected.
23 You can retrieve the current system font settings with wxSystemSettings.
31 ::wxNullFont, ::wxNORMAL_FONT, ::wxSMALL_FONT, ::wxITALIC_FONT, ::wxSWISS_FONT
33 @see @ref overview_wxfontoverview, wxDC::SetFont, wxDC::DrawText,
34 wxDC::GetTextExtent, wxFontDialog, wxSystemSettings
36 class wxFont
: public wxGDIObject
41 Creates a font object.
46 Creates a font object with the specified font.
51 wxFont(const wxFont
& font
);
54 Creates a font object with the specified attributes.
59 Font family, a generic way of referring to fonts without specifying actual
62 <TR><TD>wxFONTFAMILY_DEFAULT</TD><TD>Chooses a default font.</TD></TR>
63 <TR><TD>wxFONTFAMILY_DECORATIVE</TD><TD>A decorative font.</TD></TR>
64 <TR><TD>wxFONTFAMILY_ROMAN</TD><TD>A formal, serif font.</TD></TR>
65 <TR><TD>wxFONTFAMILY_SCRIPT</TD><TD>A handwriting font.</TD></TR>
66 <TR><TD>wxFONTFAMILY_SWISS</TD><TD>A sans-serif font.</TD></TR>
67 <TR><TD>wxFONTFAMILY_MODERN</TD><TD>A fixed pitch font.</TD></TR>
68 <TR><TD>wxFONTFAMILY_TELETYPE</TD><TD>A teletype font.</TD></TR>
71 One of wxFONTSTYLE_NORMAL, wxFONTSTYLE_SLANT and wxFONTSTYLE_ITALIC.
73 Font weight, sometimes also referred to as font boldness. One of:
75 <TR><TD>wxFONTWEIGHT_NORMAL</TD><TD>Normal font.</TD></TR>
76 <TR><TD>wxFONTWEIGHT_LIGHT</TD><TD>Light font.</TD></TR>
77 <TR><TD>wxFONTWEIGHT_BOLD</TD><TD>Bold font.</TD></TR>
80 The value can be @true or @false. At present this has an effect on Windows
83 An optional string specifying the actual typeface to be used. If it is an
85 a default typeface will be chosen based on the family.
87 An encoding which may be one of
89 <TR><TD>wxFONTENCODING_SYSTEM</TD><TD>Default system encoding.</TD></TR>
90 <TR><TD>wxFONTENCODING_DEFAULT</TD><TD>
91 Default application encoding: this
92 is the encoding set by calls to
93 SetDefaultEncoding and which may be set to,
94 say, KOI8 to create all fonts by default with KOI8 encoding. Initially, the
95 default application encoding is the same as default system encoding.</TD></TR>
96 <TR><TD>wxFONTENCODING_ISO8859_1...15</TD><TD>ISO8859 encodings.</TD></TR>
97 <TR><TD>wxFONTENCODING_KOI8</TD><TD>The standard Russian encoding for Internet.</TD></TR>
98 <TR><TD>wxFONTENCODING_CP1250...1252</TD><TD>Windows encodings similar to ISO8859 (but not identical).</TD></TR>
101 If the specified encoding isn't available, no font is created
102 (see also font encoding overview).
104 @remarks If the desired font does not exist, the closest match will be
105 chosen. Under Windows, only scalable TrueType fonts are
108 wxFont(int pointSize
, wxFontFamily family
, int style
,
110 const bool underline
= false,
111 const wxString
& faceName
= "",
112 wxFontEncoding encoding
= wxFONTENCODING_DEFAULT
);
114 Creates a font object with the specified attributes.
117 Size in pixels: this is directly supported only under MSW
118 currently where this constructor can be used directly, under other
120 font with the closest size to the given one is found using binary search and
121 the static New method must be used.
123 Font family, a generic way of referring to fonts without specifying actual
126 <TR><TD>wxFONTFAMILY_DEFAULT</TD><TD>Chooses a default font.</TD></TR>
127 <TR><TD>wxFONTFAMILY_DECORATIVE</TD><TD>A decorative font.</TD></TR>
128 <TR><TD>wxFONTFAMILY_ROMAN</TD><TD>A formal, serif font.</TD></TR>
129 <TR><TD>wxFONTFAMILY_SCRIPT</TD><TD>A handwriting font.</TD></TR>
130 <TR><TD>wxFONTFAMILY_SWISS</TD><TD>A sans-serif font.</TD></TR>
131 <TR><TD>wxFONTFAMILY_MODERN</TD><TD>A fixed pitch font.</TD></TR>
132 <TR><TD>wxFONTFAMILY_TELETYPE</TD><TD>A teletype font.</TD></TR>
135 One of wxFONTSTYLE_NORMAL, wxFONTSTYLE_SLANT and wxFONTSTYLE_ITALIC.
137 Font weight, sometimes also referred to as font boldness. One of:
139 <TR><TD>wxFONTWEIGHT_NORMAL</TD><TD>Normal font.</TD></TR>
140 <TR><TD>wxFONTWEIGHT_LIGHT</TD><TD>Light font.</TD></TR>
141 <TR><TD>wxFONTWEIGHT_BOLD</TD><TD>Bold font.</TD></TR>
144 The value can be @true or @false. At present this has an effect on Windows
147 An optional string specifying the actual typeface to be used. If it is an
149 a default typeface will be chosen based on the family.
151 An encoding which may be one of
153 <TR><TD>wxFONTENCODING_SYSTEM</TD><TD>Default system encoding.</TD></TR>
154 <TR><TD>wxFONTENCODING_DEFAULT</TD><TD>
155 Default application encoding: this
156 is the encoding set by calls to
157 SetDefaultEncoding and which may be set to,
158 say, KOI8 to create all fonts by default with KOI8 encoding. Initially, the
159 default application encoding is the same as default system encoding.</TD></TR>
160 <TR><TD>wxFONTENCODING_ISO8859_1...15</TD><TD>ISO8859 encodings.</TD></TR>
161 <TR><TD>wxFONTENCODING_KOI8</TD><TD>The standard Russian encoding for Internet.</TD></TR>
162 <TR><TD>wxFONTENCODING_CP1250...1252</TD><TD>Windows encodings similar to ISO8859 (but not identical).</TD></TR>
165 If the specified encoding isn't available, no font is created
166 (see also font encoding overview).
168 @remarks If the desired font does not exist, the closest match will be
169 chosen. Under Windows, only scalable TrueType fonts are
172 wxFont(const wxSize
& pixelSize
, wxFontFamily family
,
173 int style
, wxFontWeight weight
,
174 const bool underline
= false,
175 const wxString
& faceName
= "",
176 wxFontEncoding encoding
= wxFONTENCODING_DEFAULT
);
181 See @ref overview_refcountdestruct "reference-counted object destruction" for
184 @remarks Although all remaining fonts are deleted when the application
185 exits, the application should try to clean up all fonts
186 itself. This is because wxWidgets cannot know if a
187 pointer to the font object is stored in an application
188 data structure, and there is a risk of double deletion.
193 Returns the current application's default encoding.
195 @see @ref overview_wxfontencodingoverview, SetDefaultEncoding()
197 static wxFontEncoding
GetDefaultEncoding();
200 Returns the typeface name associated with the font, or the empty string if
202 typeface information.
206 wxString
GetFaceName() const;
209 Gets the font family. See SetFamily() for a list of valid
214 wxFontFamily
GetFamily() const;
217 Returns the platform-dependent string completely describing this font.
218 Returned string is always non-empty.
219 Note that the returned string is not meant to be shown or edited by the user: a
221 use of this function is for serializing in string-form a wxFont object.
223 @see SetNativeFontInfo(),GetNativeFontInfoUserDesc()
225 wxString
GetNativeFontInfoDesc() const;
228 Returns a user-friendly string for this font object. Returned string is always
230 Some examples of the formats of returned strings (which are platform-dependent)
231 are in SetNativeFontInfoUserDesc().
233 @see GetNativeFontInfoDesc()
235 wxString
GetNativeFontInfoUserDesc();
242 int GetPointSize() const;
245 Gets the font style. See wxFont() for a list of valid
250 int GetStyle() const;
253 Returns @true if the font is underlined, @false otherwise.
257 bool GetUnderlined() const;
260 Gets the font weight. See wxFont() for a list of valid
265 wxFontWeight
GetWeight() const;
268 Returns @true if the font is a fixed width (or monospaced) font,
269 @false if it is a proportional one or font is invalid.
271 bool IsFixedWidth() const;
274 Returns @true if this object is a valid font, @false otherwise.
280 These functions take the same parameters as @ref ctor() wxFont
281 constructor and return a new font object allocated on the heap.
282 Using @c New() is currently the only way to directly create a font with
283 the given size in pixels on platforms other than wxMSW.
285 static wxFont
* New(int pointSize
, wxFontFamily family
, int style
,
287 const bool underline
= false,
288 const wxString
& faceName
= "",
289 wxFontEncoding encoding
= wxFONTENCODING_DEFAULT
);
290 static wxFont
* New(int pointSize
, wxFontFamily family
,
291 int flags
= wxFONTFLAG_DEFAULT
,
292 const wxString
& faceName
= "",
293 wxFontEncoding encoding
= wxFONTENCODING_DEFAULT
);
294 static wxFont
* New(const wxSize
& pixelSize
,
298 const bool underline
= false,
299 const wxString
& faceName
= "",
300 wxFontEncoding encoding
= wxFONTENCODING_DEFAULT
);
301 static wxFont
* New(const wxSize
& pixelSize
,
303 int flags
= wxFONTFLAG_DEFAULT
,
304 const wxString
& faceName
= "",
305 wxFontEncoding encoding
= wxFONTENCODING_DEFAULT
);
309 Sets the default font encoding.
311 @see @ref overview_wxfontencodingoverview, GetDefaultEncoding()
313 static void SetDefaultEncoding(wxFontEncoding encoding
);
316 Sets the facename for the font.
317 Returns @true if the given face name exists; @false otherwise.
320 A valid facename, which should be on the end-user's system.
322 @remarks To avoid portability problems, don't rely on a specific face,
323 but specify the font family instead or as well. A
324 suitable font will be found on the end-user's system.
325 If both the family and the facename are specified,
326 wxWidgets will first search for the specific face, and
327 then for a font belonging to the same family.
329 @see GetFaceName(), SetFamily()
331 bool SetFaceName(const wxString
& faceName
);
334 Sets the font family.
339 <TR><TD>wxFONTFAMILY_DEFAULT</TD><TD>Chooses a default font.</TD></TR>
340 <TR><TD>wxFONTFAMILY_DECORATIVE</TD><TD>A decorative font.</TD></TR>
341 <TR><TD>wxFONTFAMILY_ROMAN</TD><TD>A formal, serif font.</TD></TR>
342 <TR><TD>wxFONTFAMILY_SCRIPT</TD><TD>A handwriting font.</TD></TR>
343 <TR><TD>wxFONTFAMILY_SWISS</TD><TD>A sans-serif font.</TD></TR>
344 <TR><TD>wxFONTFAMILY_MODERN</TD><TD>A fixed pitch font.</TD></TR>
345 <TR><TD>wxFONTFAMILY_TELETYPE</TD><TD>A teletype font.</TD></TR>
347 @see GetFamily(), SetFaceName()
349 void SetFamily(wxFontFamily family
);
352 Creates the font corresponding to the given native font description string and
354 the creation was successful.
355 which must have been previously returned by
356 GetNativeFontInfoDesc(). If the string is
357 invalid, font is unchanged. This function is typically used for de-serializing
359 object previously saved in a string-form.
361 @see SetNativeFontInfoUserDesc()
363 bool SetNativeFontInfo(const wxString
& info
);
366 Creates the font corresponding to the given native font description string and
368 the creation was successful.
369 Unlike SetNativeFontInfo(), this function accepts
370 strings which are user-friendly.
371 Examples of accepted string formats are:
377 on @b wxGTK2: @c [FACE-NAME] [bold] [oblique|italic] [POINTSIZE]
381 on @b wxMSW: @c [light|bold] [italic] [FACE-NAME] [POINTSIZE] [ENCODING]
383 Tahoma 10 WINDOWS-1252
389 For more detailed information about the allowed syntaxes you can look at the
390 documentation of the native API used for font-rendering (e.g. pango_font_description_from_string).
392 @see SetNativeFontInfo()
394 bool SetNativeFontInfoUserDesc(const wxString
& info
);
404 void SetPointSize(int pointSize
);
410 One of wxFONTSTYLE_NORMAL, wxFONTSTYLE_SLANT and wxFONTSTYLE_ITALIC.
414 void SetStyle(int style
);
420 @true to underline, @false otherwise.
424 void SetUnderlined(const bool underlined
);
427 Sets the font weight.
432 <TR><TD>wxFONTWEIGHT_NORMAL</TD><TD>Normal font.</TD></TR>
433 <TR><TD>wxFONTWEIGHT_LIGHT</TD><TD>Light font.</TD></TR>
434 <TR><TD>wxFONTWEIGHT_BOLD</TD><TD>Bold font.</TD></TR>
439 void SetWeight(wxFontWeight weight
);
443 See @ref overview_refcountequality "reference-counted object comparison" for
446 bool operator !=(const wxFont
& font
);
449 Assignment operator, using @ref overview_trefcount "reference counting".
451 wxFont
operator =(const wxFont
& font
);
455 See @ref overview_refcountequality "reference-counted object comparison" for
458 bool operator ==(const wxFont
& font
);
470 wxFont wxNORMAL_FONT
;
480 wxFont wxITALIC_FONT
;
491 A font list is a list containing all fonts which have been created. There
492 is only one instance of this class: @b wxTheFontList. Use this object to search
493 for a previously created font of the desired type and create it if not already
495 In some windowing systems, the font may be a scarce resource, so it is best to
496 reuse old resources if possible. When an application finishes, all fonts will
498 deleted and their resources freed, eliminating the possibility of 'memory
506 class wxFontList
: public wxList
510 Constructor. The application should not construct its own font list:
511 use the object pointer @b wxTheFontList.
516 Finds a font of the given specification, or creates one and adds it to the
517 list. See the @ref wxFont::ctor "wxFont constructor" for
518 details of the arguments.
520 wxFont
* FindOrCreateFont(int point_size
, int family
, int style
,
522 bool underline
= false,
523 const wxString
& facename
= NULL
,
524 wxFontEncoding encoding
= wxFONTENCODING_DEFAULT
);
529 // ============================================================================
530 // Global functions/macros
531 // ============================================================================
533 /** @ingroup group_funcmacro_misc */
537 Converts string to a wxFont best represented by the given string. Returns
540 @see wxToString(const wxFont&)
544 bool wxFromString(const wxString
& string
, wxFont
* font
);
547 Converts the given wxFont into a string.
549 @see wxFromString(const wxString&, wxFont*)
553 wxString
wxToString(const wxFont
& font
);