]>
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 /////////////////////////////////////////////////////////////////////////////
11 @ingroup group_class_gdi
14 A font is an object which determines the appearance of text. Fonts are
15 used for drawing text to a device context, and setting the appearance of
18 This class uses @ref overview_trefcount "reference counting and copy-on-write"
19 internally so that assignments between two instances of this class are very
20 cheap. You can therefore use actual objects instead of pointers without
21 efficiency problems. If an instance of this class is changed it will create
22 its own data internally so that other instances, which previously shared the
23 data using the reference counting, are not affected.
25 You can retrieve the current system font settings with wxSystemSettings.
33 ::Objects:, ::wxNullFont, ::Pointers:, ::wxNORMAL_FONT, ::wxSMALL_FONT,
34 ::wxITALIC_FONT, ::wxSWISS_FONT,
36 @see @ref overview_wxfontoverview, wxDC::SetFont, wxDC::DrawText,
37 wxDC::GetTextExtent, wxFontDialog, wxSystemSettings
39 class wxFont
: public wxGDIObject
44 Creates a font object with the specified attributes.
49 Size in pixels: this is directly supported only under MSW
50 currently where this constructor can be used directly, under other
52 font with the closest size to the given one is found using binary search and
53 the static New method must be used.
55 Font family, a generic way of referring to fonts without specifying actual
69 Chooses a default font.
75 wxFONTFAMILY_DECORATIVE
130 wxFONTFAMILY_TELETYPE
137 One of wxFONTSTYLE_NORMAL, wxFONTSTYLE_SLANT and wxFONTSTYLE_ITALIC.
139 Font weight, sometimes also referred to as font boldness. One of:
176 The value can be @true or @false. At present this has an effect on Windows
179 An optional string specifying the actual typeface to be used. If it is an
181 a default typeface will be chosen based on the family.
183 An encoding which may be one of
191 wxFONTENCODING_SYSTEM
196 Default system encoding.
202 wxFONTENCODING_DEFAULT
207 Default application encoding: this
208 is the encoding set by calls to
209 SetDefaultEncoding and which may be set to,
210 say, KOI8 to create all fonts by default with KOI8 encoding. Initially, the
211 default application encoding is the same as default system encoding.
217 wxFONTENCODING_ISO8859_1...15
233 The standard Russian encoding for Internet.
239 wxFONTENCODING_CP1250...1252
244 Windows encodings similar to ISO8859 (but not identical).
250 If the specified encoding isn't available, no font is created
251 (see also font encoding overview).
253 @remarks If the desired font does not exist, the closest match will be
254 chosen. Under Windows, only scalable TrueType fonts are
258 wxFont(const wxFont
& font
);
259 wxFont(int pointSize
, wxFontFamily family
, int style
,
261 const bool underline
= false,
262 const wxString
& faceName
= "",
263 wxFontEncoding encoding
= wxFONTENCODING_DEFAULT
);
264 wxFont(const wxSize
& pixelSize
, wxFontFamily family
,
265 int style
, wxFontWeight weight
,
266 const bool underline
= false,
267 const wxString
& faceName
= "",
268 wxFontEncoding encoding
= wxFONTENCODING_DEFAULT
);
273 See @ref overview_refcountdestruct "reference-counted object destruction" for
276 @remarks Although all remaining fonts are deleted when the application
277 exits, the application should try to clean up all fonts
278 itself. This is because wxWidgets cannot know if a
279 pointer to the font object is stored in an application
280 data structure, and there is a risk of double deletion.
285 Returns the current application's default encoding.
287 @see @ref overview_wxfontencodingoverview, SetDefaultEncoding()
289 static wxFontEncoding
GetDefaultEncoding();
292 Returns the typeface name associated with the font, or the empty string if
294 typeface information.
298 wxString
GetFaceName() const;
301 Gets the font family. See SetFamily() for a list of valid
306 wxFontFamily
GetFamily() const;
309 Returns the platform-dependent string completely describing this font.
310 Returned string is always non-empty.
311 Note that the returned string is not meant to be shown or edited by the user: a
313 use of this function is for serializing in string-form a wxFont object.
315 @see SetNativeFontInfo(),GetNativeFontInfoUserDesc()
317 wxString
GetNativeFontInfoDesc() const;
320 Returns a user-friendly string for this font object. Returned string is always
322 Some examples of the formats of returned strings (which are platform-dependent)
323 are in SetNativeFontInfoUserDesc().
325 @see GetNativeFontInfoDesc()
327 wxString
GetNativeFontInfoUserDesc();
334 int GetPointSize() const;
337 Gets the font style. See wxFont() for a list of valid
342 int GetStyle() const;
345 Returns @true if the font is underlined, @false otherwise.
349 bool GetUnderlined() const;
352 Gets the font weight. See wxFont() for a list of valid
357 wxFontWeight
GetWeight() const;
360 Returns @true if the font is a fixed width (or monospaced) font,
361 @false if it is a proportional one or font is invalid.
363 bool IsFixedWidth() const;
366 Returns @true if this object is a valid font, @false otherwise.
372 These functions take the same parameters as @ref ctor() wxFont
373 constructor and return a new font object allocated on the heap.
374 Using @c New() is currently the only way to directly create a font with
375 the given size in pixels on platforms other than wxMSW.
377 static wxFont
* New(int pointSize
, wxFontFamily family
, int style
,
379 const bool underline
= false,
380 const wxString
& faceName
= "",
381 wxFontEncoding encoding
= wxFONTENCODING_DEFAULT
);
382 static wxFont
* New(int pointSize
, wxFontFamily family
,
383 int flags
= wxFONTFLAG_DEFAULT
,
384 const wxString
& faceName
= "",
385 wxFontEncoding encoding
= wxFONTENCODING_DEFAULT
);
386 static wxFont
* New(const wxSize
& pixelSize
,
390 const bool underline
= false,
391 const wxString
& faceName
= "",
392 wxFontEncoding encoding
= wxFONTENCODING_DEFAULT
);
393 static wxFont
* New(const wxSize
& pixelSize
,
395 int flags
= wxFONTFLAG_DEFAULT
,
396 const wxString
& faceName
= "",
397 wxFontEncoding encoding
= wxFONTENCODING_DEFAULT
);
401 Sets the default font encoding.
403 @see @ref overview_wxfontencodingoverview, GetDefaultEncoding()
405 static void SetDefaultEncoding(wxFontEncoding encoding
);
408 Sets the facename for the font.
409 Returns @true if the given face name exists; @false otherwise.
412 A valid facename, which should be on the end-user's system.
414 @remarks To avoid portability problems, don't rely on a specific face,
415 but specify the font family instead or as well. A
416 suitable font will be found on the end-user's system.
417 If both the family and the facename are specified,
418 wxWidgets will first search for the specific face, and
419 then for a font belonging to the same family.
421 @see GetFaceName(), SetFamily()
423 bool SetFaceName(const wxString
& faceName
);
426 Sets the font family.
442 Chooses a default font.
448 wxFONTFAMILY_DECORATIVE
464 A formal, serif font.
503 wxFONTFAMILY_TELETYPE
510 @see GetFamily(), SetFaceName()
512 void SetFamily(wxFontFamily family
);
515 Creates the font corresponding to the given native font description string and
517 the creation was successful.
518 which must have been previously returned by
519 GetNativeFontInfoDesc(). If the string is
520 invalid, font is unchanged. This function is typically used for de-serializing
522 object previously saved in a string-form.
524 @see SetNativeFontInfoUserDesc()
526 bool SetNativeFontInfo(const wxString
& info
);
529 Creates the font corresponding to the given native font description string and
531 the creation was successful.
532 Unlike SetNativeFontInfo(), this function accepts
533 strings which are user-friendly.
534 Examples of accepted string formats are:
540 on @b wxGTK2: @c [FACE-NAME] [bold] [oblique|italic] [POINTSIZE]
544 on @b wxMSW: @c [light|bold] [italic] [FACE-NAME] [POINTSIZE] [ENCODING]
546 Tahoma 10 WINDOWS-1252
552 For more detailed information about the allowed syntaxes you can look at the
553 documentation of the native API used for font-rendering (e.g. pango_font_description_from_string).
555 @see SetNativeFontInfo()
557 bool SetNativeFontInfoUserDesc(const wxString
& info
);
567 void SetPointSize(int pointSize
);
573 One of wxFONTSTYLE_NORMAL, wxFONTSTYLE_SLANT and wxFONTSTYLE_ITALIC.
577 void SetStyle(int style
);
583 @true to underline, @false otherwise.
587 void SetUnderlined(const bool underlined
);
590 Sets the font weight.
632 void SetWeight(wxFontWeight weight
);
636 See @ref overview_refcountequality "reference-counted object comparison" for
639 bool operator !=(const wxFont
& font
);
642 Assignment operator, using @ref overview_trefcount "reference counting".
644 wxFont
operator =(const wxFont
& font
);
648 See @ref overview_refcountequality "reference-counted object comparison" for
651 bool operator ==(const wxFont
& font
);
675 wxFont wxNORMAL_FONT
;
685 wxFont wxITALIC_FONT
;