]>
git.saurik.com Git - wxWidgets.git/blob - interface/font.h
1 /////////////////////////////////////////////////////////////////////////////
3 // Purpose: interface of wxFont
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.
32 ::Objects:, ::wxNullFont, ::Pointers:, ::wxNORMAL_FONT, ::wxSMALL_FONT,
33 ::wxITALIC_FONT, ::wxSWISS_FONT,
35 @see @ref overview_wxfontoverview, wxDC::SetFont, wxDC::DrawText,
36 wxDC::GetTextExtent, wxFontDialog, wxSystemSettings
38 class wxFont
: public wxGDIObject
43 Creates a font object with the specified attributes.
48 Size in pixels: this is directly supported only under MSW
49 currently where this constructor can be used directly, under other
51 font with the closest size to the given one is found using binary search and
52 the static New method must be used.
54 Font family, a generic way of referring to fonts without specifying actual
68 Chooses a default font.
74 wxFONTFAMILY_DECORATIVE
129 wxFONTFAMILY_TELETYPE
136 One of wxFONTSTYLE_NORMAL, wxFONTSTYLE_SLANT and wxFONTSTYLE_ITALIC.
138 Font weight, sometimes also referred to as font boldness. One of:
175 The value can be @true or @false. At present this has an effect on Windows
178 An optional string specifying the actual typeface to be used. If it is an
180 a default typeface will be chosen based on the family.
182 An encoding which may be one of
190 wxFONTENCODING_SYSTEM
195 Default system encoding.
201 wxFONTENCODING_DEFAULT
206 Default application encoding: this
207 is the encoding set by calls to
208 SetDefaultEncoding and which may be set to,
209 say, KOI8 to create all fonts by default with KOI8 encoding. Initially, the
210 default application encoding is the same as default system encoding.
216 wxFONTENCODING_ISO8859_1...15
232 The standard Russian encoding for Internet.
238 wxFONTENCODING_CP1250...1252
243 Windows encodings similar to ISO8859 (but not identical).
249 If the specified encoding isn't available, no font is created
250 (see also font encoding overview).
252 @remarks If the desired font does not exist, the closest match will be
253 chosen. Under Windows, only scalable TrueType fonts are
257 wxFont(const wxFont
& font
);
258 wxFont(int pointSize
, wxFontFamily family
, int style
,
260 const bool underline
= false,
261 const wxString
& faceName
= "",
262 wxFontEncoding encoding
= wxFONTENCODING_DEFAULT
);
263 wxFont(const wxSize
& pixelSize
, wxFontFamily family
,
264 int style
, wxFontWeight weight
,
265 const bool underline
= false,
266 const wxString
& faceName
= "",
267 wxFontEncoding encoding
= wxFONTENCODING_DEFAULT
);
272 See @ref overview_refcountdestruct "reference-counted object destruction" for
275 @remarks Although all remaining fonts are deleted when the application
276 exits, the application should try to clean up all fonts
277 itself. This is because wxWidgets cannot know if a
278 pointer to the font object is stored in an application
279 data structure, and there is a risk of double deletion.
284 Returns the current application's default encoding.
286 @see @ref overview_wxfontencodingoverview, SetDefaultEncoding()
288 static wxFontEncoding
GetDefaultEncoding();
291 Returns the typeface name associated with the font, or the empty string if
293 typeface information.
297 wxString
GetFaceName() const;
300 Gets the font family. See SetFamily() for a list of valid
305 wxFontFamily
GetFamily() const;
308 Returns the platform-dependent string completely describing this font.
309 Returned string is always non-empty.
310 Note that the returned string is not meant to be shown or edited by the user: a
312 use of this function is for serializing in string-form a wxFont object.
314 @see SetNativeFontInfo(),GetNativeFontInfoUserDesc()
316 wxString
GetNativeFontInfoDesc() const;
319 Returns a user-friendly string for this font object. Returned string is always
321 Some examples of the formats of returned strings (which are platform-dependent)
322 are in SetNativeFontInfoUserDesc().
324 @see GetNativeFontInfoDesc()
326 wxString
GetNativeFontInfoUserDesc();
333 int GetPointSize() const;
336 Gets the font style. See wxFont() for a list of valid
341 int GetStyle() const;
344 Returns @true if the font is underlined, @false otherwise.
348 bool GetUnderlined() const;
351 Gets the font weight. See wxFont() for a list of valid
356 wxFontWeight
GetWeight() const;
359 Returns @true if the font is a fixed width (or monospaced) font,
360 @false if it is a proportional one or font is invalid.
362 bool IsFixedWidth() const;
365 Returns @true if this object is a valid font, @false otherwise.
371 These functions take the same parameters as @ref ctor() wxFont
372 constructor and return a new font object allocated on the heap.
373 Using @c New() is currently the only way to directly create a font with
374 the given size in pixels on platforms other than wxMSW.
376 static wxFont
* New(int pointSize
, wxFontFamily family
, int style
,
378 const bool underline
= false,
379 const wxString
& faceName
= "",
380 wxFontEncoding encoding
= wxFONTENCODING_DEFAULT
);
381 static wxFont
* New(int pointSize
, wxFontFamily family
,
382 int flags
= wxFONTFLAG_DEFAULT
,
383 const wxString
& faceName
= "",
384 wxFontEncoding encoding
= wxFONTENCODING_DEFAULT
);
385 static wxFont
* New(const wxSize
& pixelSize
,
389 const bool underline
= false,
390 const wxString
& faceName
= "",
391 wxFontEncoding encoding
= wxFONTENCODING_DEFAULT
);
392 static wxFont
* New(const wxSize
& pixelSize
,
394 int flags
= wxFONTFLAG_DEFAULT
,
395 const wxString
& faceName
= "",
396 wxFontEncoding encoding
= wxFONTENCODING_DEFAULT
);
400 Sets the default font encoding.
402 @see @ref overview_wxfontencodingoverview, GetDefaultEncoding()
404 static void SetDefaultEncoding(wxFontEncoding encoding
);
407 Sets the facename for the font.
408 Returns @true if the given face name exists; @false otherwise.
411 A valid facename, which should be on the end-user's system.
413 @remarks To avoid portability problems, don't rely on a specific face,
414 but specify the font family instead or as well. A
415 suitable font will be found on the end-user's system.
416 If both the family and the facename are specified,
417 wxWidgets will first search for the specific face, and
418 then for a font belonging to the same family.
420 @see GetFaceName(), SetFamily()
422 bool SetFaceName(const wxString
& faceName
);
425 Sets the font family.
441 Chooses a default font.
447 wxFONTFAMILY_DECORATIVE
463 A formal, serif font.
502 wxFONTFAMILY_TELETYPE
509 @see GetFamily(), SetFaceName()
511 void SetFamily(wxFontFamily family
);
514 Creates the font corresponding to the given native font description string and
516 the creation was successful.
517 which must have been previously returned by
518 GetNativeFontInfoDesc(). If the string is
519 invalid, font is unchanged. This function is typically used for de-serializing
521 object previously saved in a string-form.
523 @see SetNativeFontInfoUserDesc()
525 bool SetNativeFontInfo(const wxString
& info
);
528 Creates the font corresponding to the given native font description string and
530 the creation was successful.
531 Unlike SetNativeFontInfo(), this function accepts
532 strings which are user-friendly.
533 Examples of accepted string formats are:
539 on @b wxGTK2: @c [FACE-NAME] [bold] [oblique|italic] [POINTSIZE]
543 on @b wxMSW: @c [light|bold] [italic] [FACE-NAME] [POINTSIZE] [ENCODING]
545 Tahoma 10 WINDOWS-1252
551 For more detailed information about the allowed syntaxes you can look at the
552 documentation of the native API used for font-rendering (e.g. pango_font_description_from_string).
554 @see SetNativeFontInfo()
556 bool SetNativeFontInfoUserDesc(const wxString
& info
);
566 void SetPointSize(int pointSize
);
572 One of wxFONTSTYLE_NORMAL, wxFONTSTYLE_SLANT and wxFONTSTYLE_ITALIC.
576 void SetStyle(int style
);
582 @true to underline, @false otherwise.
586 void SetUnderlined(const bool underlined
);
589 Sets the font weight.
631 void SetWeight(wxFontWeight weight
);
635 See @ref overview_refcountequality "reference-counted object comparison" for
638 bool operator !=(const wxFont
& font
);
641 Assignment operator, using @ref overview_trefcount "reference counting".
643 wxFont
operator =(const wxFont
& font
);
647 See @ref overview_refcountequality "reference-counted object comparison" for
650 bool operator ==(const wxFont
& font
);
662 wxFont wxNORMAL_FONT
;
672 wxFont wxITALIC_FONT
;
681 // ============================================================================
682 // Global functions/macros
683 // ============================================================================
685 /** @ingroup group_funcmacro_misc */
689 Converts string to a wxFont best represented by the given string. Returns
692 @see wxToString(const wxFont&)
696 bool wxFromString(const wxString
& string
, wxFont
* font
);
699 Converts the given wxFont into a string.
701 @see wxFromString(const wxString&, wxFont*)
705 wxString
wxToString(const wxFont
& font
);