]>
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 ::wxNullFont, ::wxNORMAL_FONT, ::wxSMALL_FONT, ::wxITALIC_FONT, ::wxSWISS_FONT
34 @see @ref overview_wxfontoverview, wxDC::SetFont, wxDC::DrawText,
35 wxDC::GetTextExtent, wxFontDialog, wxSystemSettings
37 class wxFont
: public wxGDIObject
42 Creates a font object with the specified attributes.
47 Size in pixels: this is directly supported only under MSW
48 currently where this constructor can be used directly, under other
50 font with the closest size to the given one is found using binary search and
51 the static New method must be used.
53 Font family, a generic way of referring to fonts without specifying actual
67 Chooses a default font.
73 wxFONTFAMILY_DECORATIVE
128 wxFONTFAMILY_TELETYPE
135 One of wxFONTSTYLE_NORMAL, wxFONTSTYLE_SLANT and wxFONTSTYLE_ITALIC.
137 Font weight, sometimes also referred to as font boldness. One of:
174 The value can be @true or @false. At present this has an effect on Windows
177 An optional string specifying the actual typeface to be used. If it is an
179 a default typeface will be chosen based on the family.
181 An encoding which may be one of
189 wxFONTENCODING_SYSTEM
194 Default system encoding.
200 wxFONTENCODING_DEFAULT
205 Default application encoding: this
206 is the encoding set by calls to
207 SetDefaultEncoding and which may be set to,
208 say, KOI8 to create all fonts by default with KOI8 encoding. Initially, the
209 default application encoding is the same as default system encoding.
215 wxFONTENCODING_ISO8859_1...15
231 The standard Russian encoding for Internet.
237 wxFONTENCODING_CP1250...1252
242 Windows encodings similar to ISO8859 (but not identical).
248 If the specified encoding isn't available, no font is created
249 (see also font encoding overview).
251 @remarks If the desired font does not exist, the closest match will be
252 chosen. Under Windows, only scalable TrueType fonts are
256 wxFont(const wxFont
& font
);
257 wxFont(int pointSize
, wxFontFamily family
, int style
,
259 const bool underline
= false,
260 const wxString
& faceName
= "",
261 wxFontEncoding encoding
= wxFONTENCODING_DEFAULT
);
262 wxFont(const wxSize
& pixelSize
, wxFontFamily family
,
263 int style
, wxFontWeight weight
,
264 const bool underline
= false,
265 const wxString
& faceName
= "",
266 wxFontEncoding encoding
= wxFONTENCODING_DEFAULT
);
271 See @ref overview_refcountdestruct "reference-counted object destruction" for
274 @remarks Although all remaining fonts are deleted when the application
275 exits, the application should try to clean up all fonts
276 itself. This is because wxWidgets cannot know if a
277 pointer to the font object is stored in an application
278 data structure, and there is a risk of double deletion.
283 Returns the current application's default encoding.
285 @see @ref overview_wxfontencodingoverview, SetDefaultEncoding()
287 static wxFontEncoding
GetDefaultEncoding();
290 Returns the typeface name associated with the font, or the empty string if
292 typeface information.
296 wxString
GetFaceName() const;
299 Gets the font family. See SetFamily() for a list of valid
304 wxFontFamily
GetFamily() const;
307 Returns the platform-dependent string completely describing this font.
308 Returned string is always non-empty.
309 Note that the returned string is not meant to be shown or edited by the user: a
311 use of this function is for serializing in string-form a wxFont object.
313 @see SetNativeFontInfo(),GetNativeFontInfoUserDesc()
315 wxString
GetNativeFontInfoDesc() const;
318 Returns a user-friendly string for this font object. Returned string is always
320 Some examples of the formats of returned strings (which are platform-dependent)
321 are in SetNativeFontInfoUserDesc().
323 @see GetNativeFontInfoDesc()
325 wxString
GetNativeFontInfoUserDesc();
332 int GetPointSize() const;
335 Gets the font style. See wxFont() for a list of valid
340 int GetStyle() const;
343 Returns @true if the font is underlined, @false otherwise.
347 bool GetUnderlined() const;
350 Gets the font weight. See wxFont() for a list of valid
355 wxFontWeight
GetWeight() const;
358 Returns @true if the font is a fixed width (or monospaced) font,
359 @false if it is a proportional one or font is invalid.
361 bool IsFixedWidth() const;
364 Returns @true if this object is a valid font, @false otherwise.
370 These functions take the same parameters as @ref ctor() wxFont
371 constructor and return a new font object allocated on the heap.
372 Using @c New() is currently the only way to directly create a font with
373 the given size in pixels on platforms other than wxMSW.
375 static wxFont
* New(int pointSize
, wxFontFamily family
, int style
,
377 const bool underline
= false,
378 const wxString
& faceName
= "",
379 wxFontEncoding encoding
= wxFONTENCODING_DEFAULT
);
380 static wxFont
* New(int pointSize
, wxFontFamily family
,
381 int flags
= wxFONTFLAG_DEFAULT
,
382 const wxString
& faceName
= "",
383 wxFontEncoding encoding
= wxFONTENCODING_DEFAULT
);
384 static wxFont
* New(const wxSize
& pixelSize
,
388 const bool underline
= false,
389 const wxString
& faceName
= "",
390 wxFontEncoding encoding
= wxFONTENCODING_DEFAULT
);
391 static wxFont
* New(const wxSize
& pixelSize
,
393 int flags
= wxFONTFLAG_DEFAULT
,
394 const wxString
& faceName
= "",
395 wxFontEncoding encoding
= wxFONTENCODING_DEFAULT
);
399 Sets the default font encoding.
401 @see @ref overview_wxfontencodingoverview, GetDefaultEncoding()
403 static void SetDefaultEncoding(wxFontEncoding encoding
);
406 Sets the facename for the font.
407 Returns @true if the given face name exists; @false otherwise.
410 A valid facename, which should be on the end-user's system.
412 @remarks To avoid portability problems, don't rely on a specific face,
413 but specify the font family instead or as well. A
414 suitable font will be found on the end-user's system.
415 If both the family and the facename are specified,
416 wxWidgets will first search for the specific face, and
417 then for a font belonging to the same family.
419 @see GetFaceName(), SetFamily()
421 bool SetFaceName(const wxString
& faceName
);
424 Sets the font family.
440 Chooses a default font.
446 wxFONTFAMILY_DECORATIVE
462 A formal, serif font.
501 wxFONTFAMILY_TELETYPE
508 @see GetFamily(), SetFaceName()
510 void SetFamily(wxFontFamily family
);
513 Creates the font corresponding to the given native font description string and
515 the creation was successful.
516 which must have been previously returned by
517 GetNativeFontInfoDesc(). If the string is
518 invalid, font is unchanged. This function is typically used for de-serializing
520 object previously saved in a string-form.
522 @see SetNativeFontInfoUserDesc()
524 bool SetNativeFontInfo(const wxString
& info
);
527 Creates the font corresponding to the given native font description string and
529 the creation was successful.
530 Unlike SetNativeFontInfo(), this function accepts
531 strings which are user-friendly.
532 Examples of accepted string formats are:
538 on @b wxGTK2: @c [FACE-NAME] [bold] [oblique|italic] [POINTSIZE]
542 on @b wxMSW: @c [light|bold] [italic] [FACE-NAME] [POINTSIZE] [ENCODING]
544 Tahoma 10 WINDOWS-1252
550 For more detailed information about the allowed syntaxes you can look at the
551 documentation of the native API used for font-rendering (e.g. pango_font_description_from_string).
553 @see SetNativeFontInfo()
555 bool SetNativeFontInfoUserDesc(const wxString
& info
);
565 void SetPointSize(int pointSize
);
571 One of wxFONTSTYLE_NORMAL, wxFONTSTYLE_SLANT and wxFONTSTYLE_ITALIC.
575 void SetStyle(int style
);
581 @true to underline, @false otherwise.
585 void SetUnderlined(const bool underlined
);
588 Sets the font weight.
630 void SetWeight(wxFontWeight weight
);
634 See @ref overview_refcountequality "reference-counted object comparison" for
637 bool operator !=(const wxFont
& font
);
640 Assignment operator, using @ref overview_trefcount "reference counting".
642 wxFont
operator =(const wxFont
& font
);
646 See @ref overview_refcountequality "reference-counted object comparison" for
649 bool operator ==(const wxFont
& font
);
661 wxFont wxNORMAL_FONT
;
671 wxFont wxITALIC_FONT
;
683 A font list is a list containing all fonts which have been created. There
684 is only one instance of this class: @b wxTheFontList. Use this object to search
685 for a previously created font of the desired type and create it if not already
687 In some windowing systems, the font may be a scarce resource, so it is best to
688 reuse old resources if possible. When an application finishes, all fonts will
690 deleted and their resources freed, eliminating the possibility of 'memory
698 class wxFontList
: public wxList
702 Constructor. The application should not construct its own font list:
703 use the object pointer @b wxTheFontList.
708 Finds a font of the given specification, or creates one and adds it to the
709 list. See the @ref wxFont::ctor "wxFont constructor" for
710 details of the arguments.
712 wxFont
* FindOrCreateFont(int point_size
, int family
, int style
,
714 bool underline
= false,
715 const wxString
& facename
= NULL
,
716 wxFontEncoding encoding
= wxFONTENCODING_DEFAULT
);
721 // ============================================================================
722 // Global functions/macros
723 // ============================================================================
725 /** @ingroup group_funcmacro_misc */
729 Converts string to a wxFont best represented by the given string. Returns
732 @see wxToString(const wxFont&)
736 bool wxFromString(const wxString
& string
, wxFont
* font
);
739 Converts the given wxFont into a string.
741 @see wxFromString(const wxString&, wxFont*)
745 wxString
wxToString(const wxFont
& font
);