]>
git.saurik.com Git - wxWidgets.git/blob - interface/font.h
1 /////////////////////////////////////////////////////////////////////////////
3 // Purpose: documentation for wxFont class
4 // Author: wxWidgets team
6 // Licence: wxWindows license
7 /////////////////////////////////////////////////////////////////////////////
13 A font is an object which determines the appearance of text. Fonts are
14 used for drawing text to a device context, and setting the appearance of
17 This class uses @ref overview_trefcount "reference counting and copy-on-write"
18 internally so that assignments between two instances of this class are very
19 cheap. You can therefore use actual objects instead of pointers without
20 efficiency problems. If an instance of this class is changed it will create
21 its own data internally so that other instances, which previously shared the
22 data using the reference counting, are not affected.
24 You can retrieve the current system font settings with wxSystemSettings.
44 @ref overview_wxfontoverview "wxFont overview", wxDC::SetFont, wxDC::DrawText,
45 wxDC::GetTextExtent, wxFontDialog, wxSystemSettings
47 class wxFont
: public wxGDIObject
52 Creates a font object with the specified attributes.
58 Size in pixels: this is directly supported only under MSW
59 currently where this constructor can be used directly, under other platforms a
60 font with the closest size to the given one is found using binary search and
61 the static New method must be used.
64 Font family, a generic way of referring to fonts without specifying actual
71 Chooses a default font.
73 wxFONTFAMILY_DECORATIVE
104 One of wxFONTSTYLE_NORMAL, wxFONTSTYLE_SLANT and wxFONTSTYLE_ITALIC.
107 Font weight, sometimes also referred to as font boldness. One of:
126 The value can be @true or @false. At present this has an effect on Windows and
130 An optional string specifying the actual typeface to be used. If it is an empty
132 a default typeface will be chosen based on the family.
135 An encoding which may be one of
137 wxFONTENCODING_SYSTEM
140 Default system encoding.
142 wxFONTENCODING_DEFAULT
145 Default application encoding: this
146 is the encoding set by calls to
147 SetDefaultEncoding and which may be set to,
148 say, KOI8 to create all fonts by default with KOI8 encoding. Initially, the
149 default application encoding is the same as default system encoding.
151 wxFONTENCODING_ISO8859_1...15
159 The standard Russian encoding for Internet.
161 wxFONTENCODING_CP1250...1252
164 Windows encodings similar to ISO8859 (but not identical).
166 If the specified encoding isn't available, no font is created
167 (see also font encoding overview).
169 @remarks If the desired font does not exist, the closest match will be
170 chosen. Under Windows, only scalable TrueType fonts
174 wxFont(const wxFont
& font
);
175 wxFont(int pointSize
, wxFontFamily family
, int style
,
177 const bool underline
= @
false,
178 const wxString
& faceName
= "",
179 wxFontEncoding encoding
= wxFONTENCODING_DEFAULT
);
180 wxFont(const wxSize
& pixelSize
, wxFontFamily family
,
181 int style
, wxFontWeight weight
,
182 const bool underline
= @
false,
183 const wxString
& faceName
= "",
184 wxFontEncoding encoding
= wxFONTENCODING_DEFAULT
);
189 See @ref overview_refcountdestruct "reference-counted object destruction" for
192 @remarks Although all remaining fonts are deleted when the application
193 exits, the application should try to clean up all
194 fonts itself. This is because wxWidgets cannot know
195 if a pointer to the font object is stored in an
196 application data structure, and there is a risk of
202 Returns the current application's default encoding.
204 @sa @ref overview_wxfontencodingoverview "Font encoding overview",
207 static wxFontEncoding
GetDefaultEncoding();
210 Returns the typeface name associated with the font, or the empty string if
212 typeface information.
216 wxString
GetFaceName();
219 Gets the font family. See SetFamily() for a list of valid
224 wxFontFamily
GetFamily();
227 Returns the platform-dependent string completely describing this font.
228 Returned string is always non-empty.
229 Note that the returned string is not meant to be shown or edited by the user: a
231 use of this function is for serializing in string-form a wxFont object.
233 @sa SetNativeFontInfo(),GetNativeFontInfoUserDesc()
235 wxString
GetNativeFontInfoDesc();
238 Returns a user-friendly string for this font object. Returned string is always
240 Some examples of the formats of returned strings (which are platform-dependent)
241 are in SetNativeFontInfoUserDesc().
243 @sa GetNativeFontInfoDesc()
245 wxString
GetNativeFontInfoUserDesc();
255 Gets the font style. See wxFont() for a list of valid
263 Returns @true if the font is underlined, @false otherwise.
267 bool GetUnderlined();
270 Gets the font weight. See wxFont() for a list of valid
275 wxFontWeight
GetWeight();
278 Returns @true if the font is a fixed width (or monospaced) font,
279 @false if it is a proportional one or font is invalid.
284 Returns @true if this object is a valid font, @false otherwise.
286 #define bool IsOk() /* implementation is private */
290 These functions take the same parameters as @ref ctor() wxFont
291 constructor and return a new font object allocated on the heap.
293 Using @c New() is currently the only way to directly create a font with
294 the given size in pixels on platforms other than wxMSW.
296 static wxFont
* New(int pointSize
, wxFontFamily family
,
299 const bool underline
= @
false,
300 const wxString
& faceName
= "",
301 wxFontEncoding encoding
= wxFONTENCODING_DEFAULT
);
302 static wxFont
* New(int pointSize
, wxFontFamily family
,
303 int flags
= wxFONTFLAG_DEFAULT
,
304 const wxString
& faceName
= "",
305 wxFontEncoding encoding
= wxFONTENCODING_DEFAULT
);
306 static wxFont
* New(const wxSize
& pixelSize
,
310 const bool underline
= @
false,
311 const wxString
& faceName
= "",
312 wxFontEncoding encoding
= wxFONTENCODING_DEFAULT
);
313 static wxFont
* New(const wxSize
& pixelSize
,
315 int flags
= wxFONTFLAG_DEFAULT
,
316 const wxString
& faceName
= "",
317 wxFontEncoding encoding
= wxFONTENCODING_DEFAULT
);
321 Sets the default font encoding.
323 @sa @ref overview_wxfontencodingoverview "Font encoding overview",
326 static void SetDefaultEncoding(wxFontEncoding encoding
);
329 Sets the facename for the font.
330 Returns @true if the given face name exists; @false otherwise.
333 A valid facename, which should be on the end-user's system.
335 @remarks To avoid portability problems, don't rely on a specific face,
336 but specify the font family instead or as well. A
337 suitable font will be found on the end-user's system.
338 If both the family and the facename are specified,
339 wxWidgets will first search for the specific face,
340 and then for a font belonging to the same family.
342 @sa GetFaceName(), SetFamily()
344 bool SetFaceName(const wxString
& faceName
);
347 Sets the font family.
356 Chooses a default font.
358 wxFONTFAMILY_DECORATIVE
366 A formal, serif font.
383 wxFONTFAMILY_TELETYPE
388 @sa GetFamily(), SetFaceName()
390 void SetFamily(wxFontFamily family
);
393 Creates the font corresponding to the given native font description string and
395 the creation was successful.
396 which must have been previously returned by
397 GetNativeFontInfoDesc(). If the string is
398 invalid, font is unchanged. This function is typically used for de-serializing
400 object previously saved in a string-form.
402 @sa SetNativeFontInfoUserDesc()
404 bool SetNativeFontInfo(const wxString
& info
);
407 Creates the font corresponding to the given native font description string and
409 the creation was successful.
410 Unlike SetNativeFontInfo(), this function accepts
411 strings which are user-friendly.
412 Examples of accepted string formats are:
420 on @b wxGTK2: @c [FACE-NAME] [bold] [oblique|italic] [POINTSIZE]
425 on @b wxMSW: @c [light|bold] [italic] [FACE-NAME] [POINTSIZE] [ENCODING]
428 Tahoma 10 WINDOWS-1252
435 For more detailed information about the allowed syntaxes you can look at the
436 documentation of the native API used for font-rendering (e.g. pango_font_description_from_string).
438 @sa SetNativeFontInfo()
440 bool SetNativeFontInfoUserDesc(const wxString
& info
);
450 void SetPointSize(int pointSize
);
456 One of wxFONTSTYLE_NORMAL, wxFONTSTYLE_SLANT and wxFONTSTYLE_ITALIC.
460 void SetStyle(int style
);
466 @true to underline, @false otherwise.
470 void SetUnderlined(const bool underlined
);
473 Sets the font weight.
496 void SetWeight(wxFontWeight weight
);
500 See @ref overview_refcountequality "reference-counted object comparison" for
503 bool operator !=(const wxFont
& font
);
506 Assignment operator, using @ref overview_trefcount "reference counting".
508 wxFont
operator =(const wxFont
& font
);
512 See @ref overview_refcountequality "reference-counted object comparison" for
515 bool operator ==(const wxFont
& font
);