]>
git.saurik.com Git - wxWidgets.git/blob - interface/font.h
b2dd00387ae13d539ed96068a03a66b34a66b2bc
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, wxDC::SetFont, wxDC::DrawText,
45 wxDC::GetTextExtent, wxFontDialog, wxSystemSettings
47 class wxFont
: public wxGDIObject
52 Creates a font object with the specified attributes.
57 Size in pixels: this is directly supported only under MSW
58 currently where this constructor can be used directly, under other
60 font with the closest size to the given one is found using binary search and
61 the static New method must be used.
63 Font family, a generic way of referring to fonts without specifying actual
77 Chooses a default font.
83 wxFONTFAMILY_DECORATIVE
138 wxFONTFAMILY_TELETYPE
145 One of wxFONTSTYLE_NORMAL, wxFONTSTYLE_SLANT and wxFONTSTYLE_ITALIC.
147 Font weight, sometimes also referred to as font boldness. One of:
184 The value can be @true or @false. At present this has an effect on Windows
187 An optional string specifying the actual typeface to be used. If it is an
189 a default typeface will be chosen based on the family.
191 An encoding which may be one of
199 wxFONTENCODING_SYSTEM
204 Default system encoding.
210 wxFONTENCODING_DEFAULT
215 Default application encoding: this
216 is the encoding set by calls to
217 SetDefaultEncoding and which may be set to,
218 say, KOI8 to create all fonts by default with KOI8 encoding. Initially, the
219 default application encoding is the same as default system encoding.
225 wxFONTENCODING_ISO8859_1...15
241 The standard Russian encoding for Internet.
247 wxFONTENCODING_CP1250...1252
252 Windows encodings similar to ISO8859 (but not identical).
258 If the specified encoding isn't available, no font is created
259 (see also font encoding overview).
261 @remarks If the desired font does not exist, the closest match will be
262 chosen. Under Windows, only scalable TrueType fonts are
266 wxFont(const wxFont
& font
);
267 wxFont(int pointSize
, wxFontFamily family
, int style
,
269 const bool underline
= false,
270 const wxString
& faceName
= "",
271 wxFontEncoding encoding
= wxFONTENCODING_DEFAULT
);
272 wxFont(const wxSize
& pixelSize
, wxFontFamily family
,
273 int style
, wxFontWeight weight
,
274 const bool underline
= false,
275 const wxString
& faceName
= "",
276 wxFontEncoding encoding
= wxFONTENCODING_DEFAULT
);
281 See @ref overview_refcountdestruct "reference-counted object destruction" for
284 @remarks Although all remaining fonts are deleted when the application
285 exits, the application should try to clean up all fonts
286 itself. This is because wxWidgets cannot know if a
287 pointer to the font object is stored in an application
288 data structure, and there is a risk of double deletion.
293 Returns the current application's default encoding.
295 @see @ref overview_wxfontencodingoverview, SetDefaultEncoding()
297 static wxFontEncoding
GetDefaultEncoding();
300 Returns the typeface name associated with the font, or the empty string if
302 typeface information.
306 wxString
GetFaceName();
309 Gets the font family. See SetFamily() for a list of valid
314 wxFontFamily
GetFamily();
317 Returns the platform-dependent string completely describing this font.
318 Returned string is always non-empty.
319 Note that the returned string is not meant to be shown or edited by the user: a
321 use of this function is for serializing in string-form a wxFont object.
323 @see SetNativeFontInfo(),GetNativeFontInfoUserDesc()
325 wxString
GetNativeFontInfoDesc();
328 Returns a user-friendly string for this font object. Returned string is always
330 Some examples of the formats of returned strings (which are platform-dependent)
331 are in SetNativeFontInfoUserDesc().
333 @see GetNativeFontInfoDesc()
335 wxString
GetNativeFontInfoUserDesc();
345 Gets the font style. See wxFont() for a list of valid
353 Returns @true if the font is underlined, @false otherwise.
357 bool GetUnderlined();
360 Gets the font weight. See wxFont() for a list of valid
365 wxFontWeight
GetWeight();
368 Returns @true if the font is a fixed width (or monospaced) font,
369 @false if it is a proportional one or font is invalid.
374 Returns @true if this object is a valid font, @false otherwise.
380 These functions take the same parameters as @ref ctor() wxFont
381 constructor and return a new font object allocated on the heap.
382 Using @c New() is currently the only way to directly create a font with
383 the given size in pixels on platforms other than wxMSW.
385 static wxFont
* New(int pointSize
, wxFontFamily family
, int style
,
387 const bool underline
= false,
388 const wxString
& faceName
= "",
389 wxFontEncoding encoding
= wxFONTENCODING_DEFAULT
);
390 static wxFont
* New(int pointSize
, wxFontFamily family
,
391 int flags
= wxFONTFLAG_DEFAULT
,
392 const wxString
& faceName
= "",
393 wxFontEncoding encoding
= wxFONTENCODING_DEFAULT
);
394 static wxFont
* New(const wxSize
& pixelSize
,
398 const bool underline
= false,
399 const wxString
& faceName
= "",
400 wxFontEncoding encoding
= wxFONTENCODING_DEFAULT
);
401 static wxFont
* New(const wxSize
& pixelSize
,
403 int flags
= wxFONTFLAG_DEFAULT
,
404 const wxString
& faceName
= "",
405 wxFontEncoding encoding
= wxFONTENCODING_DEFAULT
);
409 Sets the default font encoding.
411 @see @ref overview_wxfontencodingoverview, GetDefaultEncoding()
413 static void SetDefaultEncoding(wxFontEncoding encoding
);
416 Sets the facename for the font.
417 Returns @true if the given face name exists; @false otherwise.
420 A valid facename, which should be on the end-user's system.
422 @remarks To avoid portability problems, don't rely on a specific face,
423 but specify the font family instead or as well. A
424 suitable font will be found on the end-user's system.
425 If both the family and the facename are specified,
426 wxWidgets will first search for the specific face, and
427 then for a font belonging to the same family.
429 @see GetFaceName(), SetFamily()
431 bool SetFaceName(const wxString
& faceName
);
434 Sets the font family.
450 Chooses a default font.
456 wxFONTFAMILY_DECORATIVE
472 A formal, serif font.
511 wxFONTFAMILY_TELETYPE
518 @see GetFamily(), SetFaceName()
520 void SetFamily(wxFontFamily family
);
523 Creates the font corresponding to the given native font description string and
525 the creation was successful.
526 which must have been previously returned by
527 GetNativeFontInfoDesc(). If the string is
528 invalid, font is unchanged. This function is typically used for de-serializing
530 object previously saved in a string-form.
532 @see SetNativeFontInfoUserDesc()
534 bool SetNativeFontInfo(const wxString
& info
);
537 Creates the font corresponding to the given native font description string and
539 the creation was successful.
540 Unlike SetNativeFontInfo(), this function accepts
541 strings which are user-friendly.
542 Examples of accepted string formats are:
548 on @b wxGTK2: @c [FACE-NAME] [bold] [oblique|italic] [POINTSIZE]
552 on @b wxMSW: @c [light|bold] [italic] [FACE-NAME] [POINTSIZE] [ENCODING]
554 Tahoma 10 WINDOWS-1252
560 For more detailed information about the allowed syntaxes you can look at the
561 documentation of the native API used for font-rendering (e.g. pango_font_description_from_string).
563 @see SetNativeFontInfo()
565 bool SetNativeFontInfoUserDesc(const wxString
& info
);
575 void SetPointSize(int pointSize
);
581 One of wxFONTSTYLE_NORMAL, wxFONTSTYLE_SLANT and wxFONTSTYLE_ITALIC.
585 void SetStyle(int style
);
591 @true to underline, @false otherwise.
595 void SetUnderlined(const bool underlined
);
598 Sets the font weight.
640 void SetWeight(wxFontWeight weight
);
644 See @ref overview_refcountequality "reference-counted object comparison" for
647 bool operator !=(const wxFont
& font
);
650 Assignment operator, using @ref overview_trefcount "reference counting".
652 wxFont
operator =(const wxFont
& font
);
656 See @ref overview_refcountequality "reference-counted object comparison" for
659 bool operator ==(const wxFont
& font
);