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 SystemSettings.
See also
Font Overview, DC.SetFont , DC.DrawText , DC.GetTextExtent , FontDialog, SystemSettings
__init__ | Default constructor. |
Bold | Returns a bold version of this font. |
GetDefaultEncoding | Returns the current application’s default encoding. |
GetEncoding | Returns the encoding of this font. |
GetFaceName | Returns the face name associated with the font, or the empty string if there is no face information. |
GetFamily | Gets the font family if possible. |
GetNativeFontInfo | Returns the encoding of this font. |
GetNativeFontInfoDesc | Returns the platform-dependent string completely describing this font. |
GetNativeFontInfoUserDesc | Returns a user-friendly string for this font object. |
GetPixelSize | Gets the pixel size. |
GetPointSize | Gets the point size. |
GetStrikethrough | Returns True if the font is stricken-through, False otherwise. |
GetStyle | Gets the font style. |
GetUnderlined | Returns True if the font is underlined, False otherwise. |
GetWeight | Gets the font weight. |
IsFixedWidth | Returns True if the font is a fixed width (or monospaced) font, False if it is a proportional one or font is invalid. |
IsOk | Returns True if this object is a valid font, False otherwise. |
Italic | Returns an italic version of this font. |
Larger | Returns a larger version of this font. |
MakeBold | Changes this font to be bold. |
MakeItalic | Changes this font to be italic. |
MakeLarger | Changes this font to be larger. |
MakeSmaller | Changes this font to be smaller. |
MakeStrikethrough | Changes this font to be stricken-through. |
MakeUnderlined | Changes this font to be underlined. |
New | This function takes the same parameters as the relative Font constructor and returns a new font object allocated on the heap. |
Scale | Changes the size of this font. |
Scaled | Returns a scaled version of this font. |
SetDefaultEncoding | Sets the default font encoding. |
SetEncoding | Sets the encoding for this font. |
SetFaceName | Sets the facename for the font. |
SetFamily | Sets the font family. |
SetNativeFontInfo | Creates the font corresponding to the given native font description string which must have been previously returned by GetNativeFontInfoDesc . |
SetNativeFontInfoUserDesc | Creates the font corresponding to the given native font description string and returns True if the creation was successful. |
SetPixelSize | Sets the pixel size. |
SetPointSize | Sets the point size. |
SetStrikethrough | Sets strike-through attribute of the font. |
SetStyle | Sets the font style. |
SetSymbolicSize | Sets the font size using a predefined symbolic size name. |
SetSymbolicSizeRelativeTo | Sets the font size compared to the base font size. |
SetUnderlined | Sets underlining. |
SetWeight | Sets the font weight. |
Smaller | Returns a smaller version of this font. |
Strikethrough | Returns stricken-through version of this font. |
Underlined | Returns underlined version of this font. |
__nonzero__ | |
_copyFrom | For internal use only. |
__ne__ | Inequality operator. |
__eq__ | Equality operator. |
Encoding | See GetEncoding and SetEncoding |
FaceName | See GetFaceName and SetFaceName |
Family | See GetFamily and SetFamily |
NativeFontInfoDesc | See GetNativeFontInfoDesc and SetNativeFontInfo |
NativeFontInfoUserDesc | See GetNativeFontInfoUserDesc and SetNativeFontInfoUserDesc |
PixelSize | See GetPixelSize and SetPixelSize |
PointSize | See GetPointSize and SetPointSize |
Style | See GetStyle and SetStyle |
Weight | See GetWeight and SetWeight |
A font is an object which determines the appearance of text.
Possible constructors:
Font()
Font(font)
Font(pointSize, family, style, weight, underline=False,
faceName='', encoding=FONTENCODING_DEFAULT)
Font(pixelSize, family, style, weight, underline=False,
faceName='', encoding=FONTENCODING_DEFAULT)
Font(pointSize, family, flags=FONTFLAG_DEFAULT, faceName='',
encoding=FONTENCODING_DEFAULT)
Font(nativeInfoString)
Font(nativeInfo)
Overloaded Implementations:
__init__ (self)
Default constructor.
__init__ (self, font)
Copy constructor, uses reference counting.
Parameters: | font (Font) – |
---|
__init__ (self, pointSize, family, style, weight, underline=False, faceName=’‘, encoding=FONTENCODING_DEFAULT)
Creates a font object with the specified attributes and size in points.
Parameters: |
|
---|
If the specified encoding isn’t available, no font is created (see also:ref:Font Encodings). :type encoding: FontEncoding
Note
If the desired font does not exist, the closest match will be chosen. Under Windows, only scalable TrueType fonts are used.
__init__ (self, pixelSize, family, style, weight, underline=False, faceName=’‘, encoding=FONTENCODING_DEFAULT)
Creates a font object with the specified attributes and size in pixels.
Parameters: |
|
---|
If the specified encoding isn’t available, no font is created (see also:ref:Font Encodings). :type encoding: FontEncoding
Note
If the desired font does not exist, the closest match will be chosen. Under Windows, only scalable TrueType fonts are used.
__init__ (self, pointSize, family, flags=FONTFLAG_DEFAULT, faceName=’‘, encoding=FONTENCODING_DEFAULT)
Creates a font object using font flags.
This constructor is similar to the constructors above except it specifies the font styles such as underlined, italic, bold, ... in a single flags argument instead of using separate arguments for them. This parameter can be a combination of FontFlag enum elements. The meaning of the remaining arguments is the same as in the other constructors, please see their documentation for details.
Notice that this constructor provides the only way of creating fonts with strike-through style.
Parameters: |
|
---|
New in version 2.9.4.
__init__ (self, nativeInfoString)
Constructor from font description string.
This constructor uses SetNativeFontInfo to initialize the font. If fontdesc is invalid the font remains uninitialized, i.e. its IsOk method will return False.
Parameters: | nativeInfoString (string) – |
---|
__init__ (self, nativeInfo)
Construct font from a native font info structure.
Parameters: | nativeInfo (NativeFontInfo) – |
---|
Returns the current application’s default encoding.
Return type: | FontEncoding |
---|
See also
Returns the encoding of this font.
Note that under wxGTK the returned value is always FONTENCODING_UTF8 .
Return type: | FontEncoding |
---|
See also
Returns the face name associated with the font, or the empty string if there is no face information.
Return type: | string |
---|
See also
Gets the font family if possible.
As described in FontFamily docs the returned value acts as a rough, basic classification of the main font properties (look, spacing).
If the current font face name is not recognized by Font or by the underlying system, FONTFAMILY_DEFAULT is returned.
Note that currently this function is not very precise and so not particularly useful. Font families mostly make sense only for font creation, see SetFamily .
Return type: | FontFamily |
---|
See also
Returns the encoding of this font.
Note that under wxGTK the returned value is always FONTENCODING_UTF8 .
Return type: | NativeFontInfo |
---|
See also
Returns the platform-dependent string completely describing this font.
Returned string is always non-empty unless the font is invalid (in which case an assert is triggered).
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 Font object.
Return type: | string |
---|
See also
Returns a user-friendly string for this font object.
Returned string is always non-empty unless the font is invalid (in which case an assert is triggered).
The string does not encode all Font infos under all platforms; e.g. under wxMSW the font family is not present in the returned string.
Some examples of the formats of returned strings (which are platform-dependent) are in SetNativeFontInfoUserDesc .
Return type: | string |
---|
See also
Gets the pixel size.
Note that under wxMSW if you passed to SetPixelSize (or to the constructor) a Size object with a null width value, you’ll get a null width in the returned object.
Return type: | Size |
---|
See also
Gets the point size.
Return type: | int |
---|
See also
Returns True if the font is stricken-through, False otherwise.
Return type: | bool |
---|
New in version 2.9.4.
See also
Gets the font style.
See FontStyle for a list of valid styles.
Return type: | FontStyle |
---|
See also
Returns True if the font is underlined, False otherwise.
Return type: | bool |
---|
See also
Gets the font weight.
See FontWeight for a list of valid weight identifiers.
Return type: | FontWeight |
---|
See also
Returns True if the font is a fixed width (or monospaced) font, False if it is a proportional one or font is invalid.
Note that this function under some platforms is different than just testing for the font family being equal to FONTFAMILY_TELETYPE because native platform-specific functions are used for the check (resulting in a more accurate return value).
Return type: | bool |
---|
Returns True if this object is a valid font, False otherwise.
Return type: | bool |
---|
Returns an italic version of this font.
Return type: | Font |
---|
New in version 2.9.1.
See also
Returns a larger version of this font.
The font size is multiplied by 1.2 , the factor of 1.2 being inspired by the W3C CSS specification.
Return type: | Font |
---|
New in version 2.9.1.
See also
MakeLarger , Smaller , Scaled
Changes this font to be larger.
The font size is multiplied by 1.2 , the factor of 1.2 being inspired by the W3C CSS specification.
Return type: | Font |
---|
New in version 2.9.1.
See also
Larger , MakeSmaller , Scale
Changes this font to be smaller.
The font size is divided by 1.2 , the factor of 1.2 being inspired by the W3C CSS specification.
Return type: | Font |
---|
New in version 2.9.1.
See also
Smaller , MakeLarger , Scale
Changes this font to be stricken-through.
Currently stricken-through fonts are only supported in wxMSW and wxGTK.
Return type: | Font |
---|
New in version 2.9.4.
See also
Changes this font to be underlined.
Return type: | Font |
---|
New in version 2.9.2.
See also
This function takes the same parameters as the relative Font constructor and returns a new font object allocated on the heap.
Overloaded Implementations:
New (pointSize, family, style, weight, underline=False, faceName=’‘, encoding=FONTENCODING_DEFAULT)
Parameters: |
|
---|---|
Return type: |
New (pointSize, family, flags=FONTFLAG_DEFAULT, faceName=’‘, encoding=FONTENCODING_DEFAULT)
Parameters: |
|
---|---|
Return type: |
New (pixelSize, family, style, weight, underline=False, faceName=’‘, encoding=FONTENCODING_DEFAULT)
Parameters: |
|
---|---|
Return type: |
New (pixelSize, family, flags=FONTFLAG_DEFAULT, faceName=’‘, encoding=FONTENCODING_DEFAULT)
Parameters: |
|
---|---|
Return type: |
New (nativeInfo)
Parameters: | nativeInfo (NativeFontInfo) – |
---|---|
Return type: | Font |
New (nativeInfoString)
Parameters: | nativeInfoString (string) – |
---|---|
Return type: | Font |
Changes the size of this font.
The font size is multiplied by the given factor (which may be less than 1 to create a smaller version of the font).
Parameters: | x (float) – |
---|---|
Return type: | Font |
New in version 2.9.1.
See also
Returns a scaled version of this font.
The font size is multiplied by the given factor (which may be less than 1 to create a smaller version of the font).
Parameters: | x (float) – |
---|---|
Return type: | Font |
New in version 2.9.1.
Sets the default font encoding.
Parameters: | encoding (FontEncoding) – |
---|
See also
Sets the encoding for this font.
Note that under wxGTK this function has no effect (because the underlying Pango library always uses FONTENCODING_UTF8 ).
Parameters: | encoding (FontEncoding) – |
---|
See also
Sets the facename for the font.
Parameters: | faceName (string) – A valid facename, which should be on the end-user’s system. |
---|---|
Return type: | bool |
Returns: | True if the given face name exists; if the face name doesn’t exist in the user’s system then the font is invalidated (so that IsOk will return False) and False is returned. |
Note
To avoid portability problems, don’t rely on a specific face, but specify the font family instead (see FontFamily and SetFamily ).
See also
Sets the font family.
As described in FontFamily docs the given family value acts as a rough, basic indication of the main font properties (look, spacing).
Note that changing the font family results in changing the font face name.
Parameters: | family (FontFamily) – One of the FontFamily values. |
---|
See also
Overloaded Implementations:
SetNativeFontInfo (self, info)
Creates the font corresponding to the given native font description string which must have been previously returned by GetNativeFontInfoDesc .
If the string is invalid, font is unchanged. This function is typically used for de-serializing a Font object previously saved in a string-form.
Parameters: | info (string) – |
---|---|
Return type: | bool |
Returns: | True if the creation was successful. |
See also
SetNativeFontInfo (self, info)
Sets the encoding for this font.
Note that under wxGTK this function has no effect (because the underlying Pango library always uses FONTENCODING_UTF8 ).
Parameters: | info (NativeFontInfo) – |
---|
See also
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:
platform | generic syntax | example |
---|---|---|
wxGTK2 | [FACE-NAME] [bold] [oblique|italic] [POINTSIZE] | Monospace bold 10 |
wxMSW | [light|bold] [italic] [FACE-NAME] [POINTSIZE] [ENCODING] | Tahoma 10 WINDOWS-1252 |
For more detailed information about the allowed syntaxes you can look at the documentation of the native API used for font-rendering (e.g. pango_font_description_from_string on GTK).
Note that unlike SetNativeFontInfo , this function doesn’t always restore all attributes of the Font object under all platforms; e.g. on wxMSW the font family is not restored (because GetNativeFontInfoUserDesc doesn’t return it on wxMSW). If you want to serialize/deserialize a font in string form, you should use GetNativeFontInfoDesc and SetNativeFontInfo instead.
Parameters: | info (string) – |
---|---|
Return type: | bool |
See also
Todo
add an example for Mac
Sets the pixel size.
The height parameter of pixelSize must be positive while the width parameter may also be zero (to indicate that you’re not interested in the width of the characters: a suitable width will be chosen for best rendering).
This feature (specifying the font pixel size) is directly supported only under wxMSW and wxGTK currently; under other platforms a font with the closest size to the given one is found using binary search (this maybe slower).
Parameters: | pixelSize (Size) – |
---|
See also
Sets the point size.
The point size is defined as 1/72 of the anglo-Saxon inch (25.4 mm): it is approximately 0.0139 inch or 352.8 um.
Parameters: | pointSize (int) – Size in points. |
---|
See also
Sets strike-through attribute of the font.
Currently stricken-through fonts are only supported in wxMSW and wxGTK.
Parameters: | strikethrough (bool) – True to add strike-through style, False to remove it. |
---|
New in version 2.9.4.
See also
Sets the font style.
Parameters: | style (FontStyle) – One of the FontStyle enumeration values. |
---|
See also
Sets the font size using a predefined symbolic size name.
This function allows to change font size to be (very) large or small compared to the standard font size.
Parameters: | size (FontSymbolicSize) – |
---|
New in version 2.9.2.
See also
Sets the font size compared to the base font size.
This is the same as SetSymbolicSize except that it uses the given font size as the normal font size instead of the standard font size.
Parameters: |
|
---|
New in version 2.9.2.
Sets underlining.
Parameters: | underlined (bool) – True to underline, False otherwise. |
---|
See also
Sets the font weight.
Parameters: | weight (FontWeight) – One of the FontWeight values. |
---|
See also
Returns a smaller version of this font.
The font size is divided by 1.2 , the factor of 1.2 being inspired by the W3C CSS specification.
Return type: | Font |
---|
New in version 2.9.1.
See also
MakeSmaller , Larger , Scaled
Returns stricken-through version of this font.
Currently stricken-through fonts are only supported in wxMSW and wxGTK.
Return type: | Font |
---|
New in version 2.9.4.
See also
Returns underlined version of this font.
Return type: | Font |
---|
New in version 2.9.2.
See also
Return type: | int |
---|
For internal use only.
Inequality operator.
See reference-counted object comparison for more info.
Parameters: | font (Font) – |
---|
Equality operator.
See reference-counted object comparison for more info.
Parameters: | font (Font) – |
---|
See GetEncoding and SetEncoding
See GetFaceName and SetFaceName
See GetPixelSize and SetPixelSize
See GetPointSize and SetPointSize