]>
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 with the specified attributes.
46 Size in pixels: this is directly supported only under MSW
47 currently where this constructor can be used directly, under other
49 font with the closest size to the given one is found using binary search and
50 the static New method must be used.
52 Font family, a generic way of referring to fonts without specifying actual
66 Chooses a default font.
72 wxFONTFAMILY_DECORATIVE
127 wxFONTFAMILY_TELETYPE
134 One of wxFONTSTYLE_NORMAL, wxFONTSTYLE_SLANT and wxFONTSTYLE_ITALIC.
136 Font weight, sometimes also referred to as font boldness. One of:
173 The value can be @true or @false. At present this has an effect on Windows
176 An optional string specifying the actual typeface to be used. If it is an
178 a default typeface will be chosen based on the family.
180 An encoding which may be one of
188 wxFONTENCODING_SYSTEM
193 Default system encoding.
199 wxFONTENCODING_DEFAULT
204 Default application encoding: this
205 is the encoding set by calls to
206 SetDefaultEncoding and which may be set to,
207 say, KOI8 to create all fonts by default with KOI8 encoding. Initially, the
208 default application encoding is the same as default system encoding.
214 wxFONTENCODING_ISO8859_1...15
230 The standard Russian encoding for Internet.
236 wxFONTENCODING_CP1250...1252
241 Windows encodings similar to ISO8859 (but not identical).
247 If the specified encoding isn't available, no font is created
248 (see also font encoding overview).
250 @remarks If the desired font does not exist, the closest match will be
251 chosen. Under Windows, only scalable TrueType fonts are
255 wxFont(const wxFont
& font
);
256 wxFont(int pointSize
, wxFontFamily family
, int style
,
258 const bool underline
= false,
259 const wxString
& faceName
= "",
260 wxFontEncoding encoding
= wxFONTENCODING_DEFAULT
);
261 wxFont(const wxSize
& pixelSize
, wxFontFamily family
,
262 int style
, wxFontWeight weight
,
263 const bool underline
= false,
264 const wxString
& faceName
= "",
265 wxFontEncoding encoding
= wxFONTENCODING_DEFAULT
);
270 See @ref overview_refcountdestruct "reference-counted object destruction" for
273 @remarks Although all remaining fonts are deleted when the application
274 exits, the application should try to clean up all fonts
275 itself. This is because wxWidgets cannot know if a
276 pointer to the font object is stored in an application
277 data structure, and there is a risk of double deletion.
282 Returns the current application's default encoding.
284 @see @ref overview_wxfontencodingoverview, SetDefaultEncoding()
286 static wxFontEncoding
GetDefaultEncoding();
289 Returns the typeface name associated with the font, or the empty string if
291 typeface information.
295 wxString
GetFaceName() const;
298 Gets the font family. See SetFamily() for a list of valid
303 wxFontFamily
GetFamily() const;
306 Returns the platform-dependent string completely describing this font.
307 Returned string is always non-empty.
308 Note that the returned string is not meant to be shown or edited by the user: a
310 use of this function is for serializing in string-form a wxFont object.
312 @see SetNativeFontInfo(),GetNativeFontInfoUserDesc()
314 wxString
GetNativeFontInfoDesc() const;
317 Returns a user-friendly string for this font object. Returned string is always
319 Some examples of the formats of returned strings (which are platform-dependent)
320 are in SetNativeFontInfoUserDesc().
322 @see GetNativeFontInfoDesc()
324 wxString
GetNativeFontInfoUserDesc();
331 int GetPointSize() const;
334 Gets the font style. See wxFont() for a list of valid
339 int GetStyle() const;
342 Returns @true if the font is underlined, @false otherwise.
346 bool GetUnderlined() const;
349 Gets the font weight. See wxFont() for a list of valid
354 wxFontWeight
GetWeight() const;
357 Returns @true if the font is a fixed width (or monospaced) font,
358 @false if it is a proportional one or font is invalid.
360 bool IsFixedWidth() const;
363 Returns @true if this object is a valid font, @false otherwise.
369 These functions take the same parameters as @ref ctor() wxFont
370 constructor and return a new font object allocated on the heap.
371 Using @c New() is currently the only way to directly create a font with
372 the given size in pixels on platforms other than wxMSW.
374 static wxFont
* New(int pointSize
, wxFontFamily family
, int style
,
376 const bool underline
= false,
377 const wxString
& faceName
= "",
378 wxFontEncoding encoding
= wxFONTENCODING_DEFAULT
);
379 static wxFont
* New(int pointSize
, wxFontFamily family
,
380 int flags
= wxFONTFLAG_DEFAULT
,
381 const wxString
& faceName
= "",
382 wxFontEncoding encoding
= wxFONTENCODING_DEFAULT
);
383 static wxFont
* New(const wxSize
& pixelSize
,
387 const bool underline
= false,
388 const wxString
& faceName
= "",
389 wxFontEncoding encoding
= wxFONTENCODING_DEFAULT
);
390 static wxFont
* New(const wxSize
& pixelSize
,
392 int flags
= wxFONTFLAG_DEFAULT
,
393 const wxString
& faceName
= "",
394 wxFontEncoding encoding
= wxFONTENCODING_DEFAULT
);
398 Sets the default font encoding.
400 @see @ref overview_wxfontencodingoverview, GetDefaultEncoding()
402 static void SetDefaultEncoding(wxFontEncoding encoding
);
405 Sets the facename for the font.
406 Returns @true if the given face name exists; @false otherwise.
409 A valid facename, which should be on the end-user's system.
411 @remarks To avoid portability problems, don't rely on a specific face,
412 but specify the font family instead or as well. A
413 suitable font will be found on the end-user's system.
414 If both the family and the facename are specified,
415 wxWidgets will first search for the specific face, and
416 then for a font belonging to the same family.
418 @see GetFaceName(), SetFamily()
420 bool SetFaceName(const wxString
& faceName
);
423 Sets the font family.
439 Chooses a default font.
445 wxFONTFAMILY_DECORATIVE
461 A formal, serif font.
500 wxFONTFAMILY_TELETYPE
507 @see GetFamily(), SetFaceName()
509 void SetFamily(wxFontFamily family
);
512 Creates the font corresponding to the given native font description string and
514 the creation was successful.
515 which must have been previously returned by
516 GetNativeFontInfoDesc(). If the string is
517 invalid, font is unchanged. This function is typically used for de-serializing
519 object previously saved in a string-form.
521 @see SetNativeFontInfoUserDesc()
523 bool SetNativeFontInfo(const wxString
& info
);
526 Creates the font corresponding to the given native font description string and
528 the creation was successful.
529 Unlike SetNativeFontInfo(), this function accepts
530 strings which are user-friendly.
531 Examples of accepted string formats are:
537 on @b wxGTK2: @c [FACE-NAME] [bold] [oblique|italic] [POINTSIZE]
541 on @b wxMSW: @c [light|bold] [italic] [FACE-NAME] [POINTSIZE] [ENCODING]
543 Tahoma 10 WINDOWS-1252
549 For more detailed information about the allowed syntaxes you can look at the
550 documentation of the native API used for font-rendering (e.g. pango_font_description_from_string).
552 @see SetNativeFontInfo()
554 bool SetNativeFontInfoUserDesc(const wxString
& info
);
564 void SetPointSize(int pointSize
);
570 One of wxFONTSTYLE_NORMAL, wxFONTSTYLE_SLANT and wxFONTSTYLE_ITALIC.
574 void SetStyle(int style
);
580 @true to underline, @false otherwise.
584 void SetUnderlined(const bool underlined
);
587 Sets the font weight.
629 void SetWeight(wxFontWeight weight
);
633 See @ref overview_refcountequality "reference-counted object comparison" for
636 bool operator !=(const wxFont
& font
);
639 Assignment operator, using @ref overview_trefcount "reference counting".
641 wxFont
operator =(const wxFont
& font
);
645 See @ref overview_refcountequality "reference-counted object comparison" for
648 bool operator ==(const wxFont
& font
);
660 wxFont wxNORMAL_FONT
;
670 wxFont wxITALIC_FONT
;
681 A font list is a list containing all fonts which have been created. There
682 is only one instance of this class: @b wxTheFontList. Use this object to search
683 for a previously created font of the desired type and create it if not already
685 In some windowing systems, the font may be a scarce resource, so it is best to
686 reuse old resources if possible. When an application finishes, all fonts will
688 deleted and their resources freed, eliminating the possibility of 'memory
696 class wxFontList
: public wxList
700 Constructor. The application should not construct its own font list:
701 use the object pointer @b wxTheFontList.
706 Finds a font of the given specification, or creates one and adds it to the
707 list. See the @ref wxFont::ctor "wxFont constructor" for
708 details of the arguments.
710 wxFont
* FindOrCreateFont(int point_size
, int family
, int style
,
712 bool underline
= false,
713 const wxString
& facename
= NULL
,
714 wxFontEncoding encoding
= wxFONTENCODING_DEFAULT
);
719 // ============================================================================
720 // Global functions/macros
721 // ============================================================================
723 /** @ingroup group_funcmacro_misc */
727 Converts string to a wxFont best represented by the given string. Returns
730 @see wxToString(const wxFont&)
734 bool wxFromString(const wxString
& string
, wxFont
* font
);
737 Converts the given wxFont into a string.
739 @see wxFromString(const wxString&, wxFont*)
743 wxString
wxToString(const wxFont
& font
);