******* wx.Font ******* Inheritance diagram for `wx.Font`: | .. inheritance-diagram:: 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 `_ . .. seealso:: `wx.SystemSettings `_, `wx.DC.SetFont `_ , `wx.DC.DrawText `_, `wx.DC.GetTextExtent `_, `wx.FontDialog `_ 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 ^^^^^^^^^^^^^ * `wx.GDIObject `_ * `wx.Object `_ Methods Summary ^^^^^^^^^^^^^^^ * `__init__ <#__init__>`_ * `GetDefaultEncoding <#GetDefaultEncoding>`_ * `GetEncoding <#GetEncoding>`_ * `GetFaceName <#GetFaceName>`_ * `GetFamily <#GetFamily>`_ * `GetFamilyString <#GetFamilyString>`_ * `GetHFONT <#GetHFONT>`_ * `GetNativeFontInfo <#GetNativeFontInfo>`_ * `GetNativeFontInfoDesc <#GetNativeFontInfoDesc>`_ * `GetNativeFontInfoUserDesc <#GetNativeFontInfoUserDesc>`_ * `GetNoAntiAliasing <#GetNoAntiAliasing>`_ * `GetPixelSize <#GetPixelSize>`_ * `GetPointSize <#GetPointSize>`_ * `GetStyle <#GetStyle>`_ * `GetStyleString <#GetStyleString>`_ * `GetUnderlined <#GetUnderlined>`_ * `GetWeight <#GetWeight>`_ * `GetWeightString <#GetWeightString>`_ * `IsFixedWidth <#IsFixedWidth>`_ * `IsOk <#IsOk>`_ * `IsUsingSizeInPixels <#IsUsingSizeInPixels>`_ * `SetDefaultEncoding <#SetDefaultEncoding>`_ * `SetEncoding <#SetEncoding>`_ * `SetFaceName <#SetFaceName>`_ * `SetFamily <#SetFamily>`_ * `SetNativeFontInfo <#SetNativeFontInfo>`_ * `SetNativeFontInfoFromString <#SetNativeFontInfoFromString>`_ * `SetNativeFontInfoUserDesc <#SetNativeFontInfoUserDesc>`_ * `SetNoAntiAliasing <#SetNoAntiAliasing>`_ * `SetPixelSize <#SetPixelSize>`_ * `SetPointSize <#SetPointSize>`_ * `SetStyle <#SetStyle>`_ * `SetUnderlined <#SetUnderlined>`_ * `SetWeight <#SetWeight>`_ Properties Summary ^^^^^^^^^^^^^^^^^^ * `Encoding <#Encoding>`_ * `FaceName <#FaceName>`_ * `Family <#Family>`_ * `FamilyString <#FamilyString>`_ * `NativeFontInfo <#NativeFontInfo>`_ * `NativeFontInfoDesc <#NativeFontInfoDesc>`_ * `NativeFontInfoUserDesc <#NativeFontInfoUserDesc>`_ * `NoAntiAliasing <#NoAntiAliasing>`_ * `PixelSize <#PixelSize>`_ * `PointSize <#PointSize>`_ * `Style <#Style>`_ * `StyleString <#StyleString>`_ * `Underlined <#Underlined>`_ * `Weight <#Weight>`_ * `WeightString <#WeightString>`_ Class API ========= Methods ^^^^^^^ .. method:: __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 `_ .. seealso:: `wx.FFont <../wxFunctions.html#FFont>`_, `wx.FontFromPixelSize <../wxFunctions.html#FontFromPixelSize>`_, `wx.FFontFromPixelSize <../wxFunctions.html#FFontFromPixelSize>`_, `wx.FontFromNativeInfoString <../wxFunctions.html#FontFromNativeInfoString>`_, `wx.FontFromNativeInfo <../wxFunctions.html#FontFromNativeInfo>`_ -------- .. method:: GetDefaultEncoding() Returns the current application's default encoding. | **Returns:** `int` .. seealso:: `SetDefaultEncoding <#SetDefaultEncoding>`_ -------- .. method:: GetEncoding() Get the font's encoding. | **Returns:** `int` -------- .. method:: GetFaceName() Returns the typeface name associated with the font, or the empty string if there is no typeface information. | **Returns:** `string` .. seealso:: `SetFaceName <#SetFaceName>`_ -------- .. method:: GetFamily() Gets the font family. See `SetFamily <#SetFamily>`_ for a list of valid family identifiers. | **Returns:** `int` .. seealso:: `SetFamily <#SetFamily>`_ -------- .. method:: GetFamilyString() Returns a string representation of the font family. | **Returns:** `string` -------- .. method:: GetHFONT() `No docstrings found for this method.` -------- .. method:: GetNativeFontInfo() Constructs a `wx.NativeFontInfo `_ object from this font. | **Returns:** `wx.NativeFontInfo `_ -------- .. method:: 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. .. seealso:: `SetNativeFontInfo <#SetNativeFontInfo>`_, `GetNativeFontInfoUserDesc <#GetNativeFontInfoUserDesc>`_ -------- .. method:: 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 <#SetNativeFontInfoUserDesc>`_. | **Returns:** `string` .. seealso:: `GetNativeFontInfoDesc <#GetNativeFontInfoDesc>`_ -------- .. method:: GetNoAntiAliasing() `No docstrings found for this method.` -------- .. method:: GetPixelSize() Returns the size in pixels if the font was constructed with a pixel size. | **Returns:** `wx.Size `_ -------- .. method:: GetPointSize() Gets the point size. | **Returns:** `int` .. seealso:: `SetPointSize <#SetPointSize>`_ -------- .. method:: GetStyle() Gets the font style. | **Returns:** `int` .. seealso:: `SetStyle <#SetStyle>`_ -------- .. method:: GetStyleString() Returns a string representation of the font style. | **Returns:** `string` -------- .. method:: GetUnderlined() Returns ``True`` if the font is underlined, ``False`` otherwise. | **Returns:** `bool` .. seealso:: `SetUnderlined <#SetUnderlined>`_ -------- .. method:: GetWeight() Gets the font weight. | **Returns:** `int` .. seealso:: `SetWeight <#SetWeight>`_ -------- .. method:: GetWeightString() Return a string representation of the font weight. | **Returns:** `string` -------- .. method:: 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` -------- .. method:: IsOk() Returns ``True`` if this object is a valid font, ``False`` otherwise. | **Returns:** `bool` -------- .. method:: IsUsingSizeInPixels() Returns ``True`` if the font is using a pixelSize. | **Returns:** `bool` -------- .. method:: SetDefaultEncoding(encoding) Sets the default font encoding. **Parameters:** * `encoding` (int) .. seealso:: `GetDefaultEncoding <#GetDefaultEncoding>`_ -------- .. method:: SetEncoding(encoding) Set the font encoding. **Parameters:** * `encoding` (int) -------- .. method:: 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. .. seealso:: `GetFaceName <#GetFaceName>`_ , `SetFamily <#SetFamily>`_ -------- .. method:: 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. =============================== =================================== .. seealso:: `GetFamily <#GetFamily>`_ , `SetFaceName <#SetFaceName>`_ -------- .. method:: 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 <#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` .. seealso:: `SetNativeFontInfoUserDesc <#SetNativeFontInfoUserDesc>`_ -------- .. method:: SetNativeFontInfoFromString(info) Set the font's attributes from string representation of a `wx.NativeFontInfo `_ object. **Parameters:** * `info` (string) | **Returns:** `bool` -------- .. method:: SetNativeFontInfoUserDesc(info) Creates the font corresponding to the given native font description string and returns ``True`` if the creation was successful. Unlike `SetNativeFontInfo <#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` .. seealso:: `SetNativeFontInfo <#SetNativeFontInfo>`_ -------- .. method:: SetNoAntiAliasing(no=True) | **Parameters:** * `no` (bool) -------- .. method:: 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:** * `pixelSize` (`wx.Size `_) -------- .. method:: SetPointSize(pointSize) Sets the point size. **Parameters:** * `pointSize` (int): Size in points. .. seealso:: `GetPointSize <#GetPointSize>`_ -------- .. method:: SetStyle(style) Sets the font style. **Parameters:** * `style` (int): One of ``wx.FONTSTYLE_NORMAL``, ``wx.FONTSTYLE_SLANT`` and ``wx.FONTSTYLE_ITALIC``. .. seealso:: `GetStyle <#GetStyle>`_ -------- .. method:: SetUnderlined(underlined) Sets underlining. **Parameters:** * `underlined` (bool) .. seealso:: `GetUnderlined <#GetUnderlined>`_ -------- .. method:: 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. =========================== ============================= .. seealso:: `GetWeight <#GetWeight>`_ -------- Properties ^^^^^^^^^^ .. attribute:: Encoding See `GetEncoding <#GetEncoding>`_ and `SetEncoding <#SetEncoding>`_ .. attribute:: FaceName See `GetFaceName <#GetFaceName>`_ and `SetFaceName <#SetFaceName>`_ .. attribute:: Family See `GetFamily <#GetFamily>`_ and `SetFamily <#SetFamily>`_ .. attribute:: FamilyString See `GetFamilyString <#GetFamilyString>`_ .. attribute:: NativeFontInfo See `GetNativeFontInfo <#GetNativeFontInfo>`_ and `SetNativeFontInfo <#SetNativeFontInfo>`_ .. attribute:: NativeFontInfoDesc See `GetNativeFontInfoDesc <#GetNativeFontInfoDesc>`_ .. attribute:: NativeFontInfoUserDesc See `GetNativeFontInfoUserDesc <#GetNativeFontInfoUserDesc>`_ and `SetNativeFontInfoUserDesc <#SetNativeFontInfoUserDesc>`_ .. attribute:: NoAntiAliasing See `GetNoAntiAliasing <#GetNoAntiAliasing>`_ and `SetNoAntiAliasing <#SetNoAntiAliasing>`_ .. attribute:: PixelSize See `GetPixelSize <#GetPixelSize>`_ and `SetPixelSize <#SetPixelSize>`_ .. attribute:: PointSize See `GetPointSize <#GetPointSize>`_ and `SetPointSize <#SetPointSize>`_ .. attribute:: Style See `GetStyle <#GetStyle>`_ and `SetStyle <#SetStyle>`_ .. attribute:: StyleString See `GetStyleString <#GetStyleString>`_ .. attribute:: Underlined See `GetUnderlined <#GetUnderlined>`_ and `SetUnderlined <#SetUnderlined>`_ .. attribute:: Weight See `GetWeight <#GetWeight>`_ and `SetWeight <#SetWeight>`_ .. attribute:: WeightString See `GetWeightString <#GetWeightString>`_