wx.Font

Inheritance diagram for wx.Font:



Description

A font is an object which determines the appearance of text. Fonts are used for drawing text to a device context, and setting the appearance of a window’s text.

This class uses reference counting and copy-on-write internally so that assignments between two instances of this class are very cheap. You can therefore use actual objects instead of pointers without efficiency problems. If an instance of this class is changed it will create its own data internally so that other instances, which previously shared the data using the reference counting, are not affected.

You can retrieve the current system font settings with wx.SystemSettings .

Font Flags

The possible values for the family parameter of wx.Font constructor are:

Family Flag Description
wx.FONTFAMILY_DEFAULT Chooses a default font.
wx.FONTFAMILY_DECORATIVE A decorative font.
wx.FONTFAMILY_ROMAN A formal, serif font.
wx.FONTFAMILY_SCRIPT A handwriting font.
wx.FONTFAMILY_SWISS A sans-serif font.
wx.FONTFAMILY_MODERN Usually a fixed pitch font.
wx.FONTFAMILY_TELETYPE A teletype font.

The possible values for the weight parameter are:

Weight Flag Description
wx.FONTWEIGHT_NORMAL Normal font.
wx.FONTWEIGHT_LIGHT Light font.
wx.FONTWEIGHT_BOLD Bold font.

The known font encodings are:

Encoding Flag Description
wx.FONTENCODING_SYSTEM system default
wx.FONTENCODING_DEFAULT current default encoding
wx.FONTENCODING_ISO8859_1 West European (Latin1)
wx.FONTENCODING_ISO8859_2 Central and East European (Latin2)
wx.FONTENCODING_ISO8859_3 Esperanto (Latin3)
wx.FONTENCODING_ISO8859_4 Baltic (old) (Latin4)
wx.FONTENCODING_ISO8859_5 Cyrillic
wx.FONTENCODING_ISO8859_6 Arabic
wx.FONTENCODING_ISO8859_7 Greek
wx.FONTENCODING_ISO8859_8 Hebrew
wx.FONTENCODING_ISO8859_9 Turkish (Latin5)
wx.FONTENCODING_ISO8859_10 Variation of Latin4 (Latin6)
wx.FONTENCODING_ISO8859_11 Thai
wx.FONTENCODING_ISO8859_12 doesn’t exist currently, but put it here anyhow to make all ISO8859 consecutive numbers
wx.FONTENCODING_ISO8859_13 Baltic (Latin7)
wx.FONTENCODING_ISO8859_14 Latin8
wx.FONTENCODING_ISO8859_15 Latin9 (a.k.a. Latin0, includes euro)
wx.FONTENCODING_KOI8 Cyrillic charset
wx.FONTENCODING_ALTERNATIVE same as MS-DOS CP866
wx.FONTENCODING_BULGARIAN used under Linux in Bulgaria
wx.FONTENCODING_CP437 original MS-DOS codepage
wx.FONTENCODING_CP850 CP437 merged with Latin1
wx.FONTENCODING_CP852 CP437 merged with Latin2
wx.FONTENCODING_CP855 another cyrillic encoding
wx.FONTENCODING_CP866 and another one
wx.FONTENCODING_CP874 WinThai
wx.FONTENCODING_CP1250 WinLatin2
wx.FONTENCODING_CP1251 WinCyrillic
wx.FONTENCODING_CP1252 WinLatin1
wx.FONTENCODING_CP1253 WinGreek (8859-7)
wx.FONTENCODING_CP1254 WinTurkish
wx.FONTENCODING_CP1255 WinHebrew
wx.FONTENCODING_CP1256 WinArabic
wx.FONTENCODING_CP1257 WinBaltic (same as Latin 7)
wx.FONTENCODING_UTF7 UTF-7 Unicode encoding
wx.FONTENCODING_UTF8 UTF-8 Unicode encoding

Derived From

Class API

Methods

__init__(pointSize, family, style, weight, underline=False, face="", encoding=wx.FONTENCODING_DEFAULT)

Creates a font object with the specified attributes.

Parameters:

  • pointSize (int): The size of the font in points.
  • family (int): Font family. A generic way of referring to fonts without specifying actual facename. It can be one of the wx.FONTFAMILY_xxx constants.
  • style (int): One of the wx.FONTSTYLE_xxx constants.
  • weight (int): Font weight, sometimes also referred to as font boldness. One of the wx.FONTWEIGHT_xxx constants.
  • underline (bool): The value can be True or False and indicates whether the font will include an underline. This may not be supported on all platforms.
  • face (string): An optional string specifying the actual typeface to be used. If it is an empty string, a default typeface will be chosen based on the family.
  • encoding (int): An encoding which may be one of the wx.FONTENCODING_xxx constants. If the specified encoding isn’t available, no font is created.

Returns:

wx.Font


GetDefaultEncoding()

Returns the current application’s default encoding.


Returns:

int


GetEncoding()

Get the font’s encoding.


Returns:

int


GetFaceName()

Returns the typeface name associated with the font, or the empty string if there is no typeface information.


Returns:

string

See also

SetFaceName


GetFamily()

Gets the font family. See SetFamily for a list of valid family identifiers.


Returns:

int

See also

SetFamily


GetFamilyString()

Returns a string representation of the font family.


Returns:

string


GetHFONT()
No docstrings found for this method.

GetNativeFontInfo()

Constructs a wx.NativeFontInfo object from this font.


Returns:

wx.NativeFontInfo


GetNativeFontInfoDesc()

Returns the platform-dependent string completely describing this font. Returned string is always non-empty.


Returns:

string

Note

Note that the returned string is not meant to be shown or edited by the user: a typical use of this function is for serializing in string-form a wx.Font object.


GetNativeFontInfoUserDesc()

Returns a user-friendly string for this font object. Returned string is always non-empty. Some examples of the formats of returned strings (which are platform-dependent) are in SetNativeFontInfoUserDesc.


Returns:

string


GetNoAntiAliasing()
No docstrings found for this method.

GetPixelSize()

Returns the size in pixels if the font was constructed with a pixel size.


Returns:

wx.Size


GetPointSize()

Gets the point size.


Returns:

int

See also

SetPointSize


GetStyle()

Gets the font style.


Returns:

int

See also

SetStyle


GetStyleString()

Returns a string representation of the font style.


Returns:

string


GetUnderlined()

Returns True if the font is underlined, False otherwise.


Returns:

bool

See also

SetUnderlined


GetWeight()

Gets the font weight.


Returns:

int

See also

SetWeight


GetWeightString()

Return a string representation of the font weight.


Returns:

string


IsFixedWidth()

Returns True if the font is a fixed width (or monospaced) font, False if it is a proportional one or font is invalid.


Returns:

bool


IsOk()

Returns True if this object is a valid font, False otherwise.


Returns:

bool


IsUsingSizeInPixels()

Returns True if the font is using a pixelSize.


Returns:

bool


SetDefaultEncoding(encoding)

Sets the default font encoding.

Parameters:

  • encoding (int)

SetEncoding(encoding)

Set the font encoding.

Parameters:

  • encoding (int)

SetFaceName(faceName)

Sets the facename for the font. Returns True if the given face name exists; False otherwise.

Parameters:

  • faceName (string): A valid facename, which should be on the end-user’s system.

Returns:

bool

Note

To a portability problems, don’t rely on a specific face, but specify the font family instead or as well. A suitable font will be found on the end-user’s system. If both the family and the facename are specified, wxWidgets will first search for the specific face, and then for a font belonging to the same family.

See also

GetFaceName , SetFamily


SetFamily(family)

Sets the font family.

Parameters:

  • family (int): One of:

    Font Family Constant

    Description

    wx.FONTFAMILY_DEFAULT

    Chooses a default font.

    wx.FONTFAMILY_DECORATIVE

    A decorative font.

    wx.FONTFAMILY_ROMAN

    A formal, serif font.

    wx.FONTFAMILY_SCRIPT

    A handwriting font.

    wx.FONTFAMILY_SWISS

    A sans-serif font.

    wx.FONTFAMILY_MODERN

    A fixed pitch font.

    wx.FONTFAMILY_TELETYPE

    A teletype font.

See also

GetFamily , SetFaceName


SetNativeFontInfo(info)

Creates the font corresponding to the given native font description string and returns True if the creation was successful. which must have been previously returned by GetNativeFontInfoDesc .

If the string is invalid, font state is undefined (it becomes invalid in 2.8 but this shouldn’t be relied on as the next wxWidgets version leaves it unchanged instead). This function is typically used for de-serializing a wx.Font object previously saved in a string-form.

Parameters:

  • info (string)

Returns:

bool


SetNativeFontInfoFromString(info)

Set the font’s attributes from string representation of a wx.NativeFontInfo object.

Parameters:

  • info (string)

Returns:

bool


SetNativeFontInfoUserDesc(info)

Creates the font corresponding to the given native font description string and returns True if the creation was successful. Unlike SetNativeFontInfo , this function accepts strings which are user-friendly.

Examples of accepted string formats are:

Generic syntax Example
On wxGTK2: [FACE-NAME] [bold] [oblique|italic] [POINTSIZE] Monospace bold 10
On wxMSW: [light|bold] [italic] [FACE-NAME] [POINTSIZE] [ENCODING] Tahoma 10 WINDOWS-1252
On wxMac: FIXME FIXME

For more detailed information about the allowed syntaxes you can look at the documentation of the native API used for font-rendering.

Parameters:

  • info (string)

Returns:

bool


SetNoAntiAliasing(no=True)

Parameters:

  • no (bool)

SetPixelSize(pixelSize)

Sets the size in pixels rather than points. If there is platform API support for this then it is used, otherwise a font with the closest size is found using a binary search.

Parameters:


SetPointSize(pointSize)

Sets the point size.

Parameters:

  • pointSize (int): Size in points.

See also

GetPointSize


SetStyle(style)

Sets the font style.

Parameters:

  • style (int): One of wx.FONTSTYLE_NORMAL, wx.FONTSTYLE_SLANT and wx.FONTSTYLE_ITALIC.

See also

GetStyle


SetUnderlined(underlined)

Sets underlining.

Parameters:

  • underlined (bool)

See also

GetUnderlined


SetWeight(weight)

Sets the font weight.

Parameters:

  • weight (int): One of:

    Font Weight Constant

    Description

    wx.FONTWEIGHT_NORMAL

    Normal font.

    wx.FONTWEIGHT_LIGHT

    Light font.

    wx.FONTWEIGHT_BOLD

    Bold font.

See also

GetWeight


Properties

Encoding
See GetEncoding and SetEncoding
FaceName
See GetFaceName and SetFaceName
Family
See GetFamily and SetFamily
FamilyString
See GetFamilyString
NativeFontInfo
See GetNativeFontInfo and SetNativeFontInfo
NativeFontInfoDesc
See GetNativeFontInfoDesc
NativeFontInfoUserDesc
See GetNativeFontInfoUserDesc and SetNativeFontInfoUserDesc
NoAntiAliasing
See GetNoAntiAliasing and SetNoAntiAliasing
PixelSize
See GetPixelSize and SetPixelSize
PointSize
See GetPointSize and SetPointSize
Style
See GetStyle and SetStyle
StyleString
See GetStyleString
Underlined
See GetUnderlined and SetUnderlined
Weight
See GetWeight and SetWeight
WeightString
See GetWeightString