| Version: 3.3.1

Public Member Functions | Static Public Member Functions | List of all members
wxFont Class Reference
Class List by Category » Graphics Device Interface (GDI)

`#include <wx/font.h>`

Inheritance diagram for wxFont:
[legend]

## Detailed 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, see wxDC::SetFont() and wxWindow::SetFont().

The easiest way to create a custom font is to use wxFontInfo object to specify the font attributes and then use wxFont::wxFont(const wxFontInfo&) constructor. Alternatively, you could start with one of the pre-defined fonts or use wxWindow::GetFont() and modify the font, e.g. by increasing its size using MakeLarger() or changing its weight using MakeBold().

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 wxSystemSettings.

##

Library: wxCore
Category: Graphics Device Interface (GDI)

Predefined objects/pointers: wxNullFont, wxNORMAL_FONT, wxSMALL_FONT, wxITALIC_FONT, wxSWISS_FONT

See also
  wxFont Overview, wxDC::SetFont, wxDC::DrawText, wxDC::GetTextExtent, wxFontDialog, wxSystemSettings

## Getters
wxFont | GetBaseFont () const
| Returns a font with the same face/size as the given one but with normal weight and style and not underlined nor stricken through. More...
virtual wxFontEncoding | GetEncoding () const
| Returns the encoding of this font. More...
virtual wxString | GetFaceName () const
| Returns the face name associated with the font, or the empty string if there is no face information. More...
virtual wxFontFamily | GetFamily () const
| Gets the font family if possible. More...
wxString | GetNativeFontInfoDesc () const
| Returns the platform-dependent string completely describing this font. More...
wxString | GetNativeFontInfoUserDesc () const
| Returns a user-friendly string for this font object. More...
const wxNativeFontInfo * | GetNativeFontInfo () const
| Returns a font with the same face/size as the given one but with normal weight and style and not underlined nor stricken through. More...
virtual int | GetPointSize () const
| Gets the point size as an integer number. More...
virtual double | GetFractionalPointSize () const
| Gets the point size as a floating number. More...
virtual wxSize | GetPixelSize () const
| Gets the pixel size. More...
virtual wxFontStyle | GetStyle () const
| Gets the font style. More...
virtual bool | GetUnderlined () const
| Returns true if the font is underlined, false otherwise. More...
virtual bool | GetStrikethrough () const
| Returns true if the font is stricken-through, false otherwise. More...
virtual wxFontWeight | GetWeight () const
| Gets the font weight. More...
virtual int | GetNumericWeight () const
| Gets the font weight as an integer value. More...
virtual bool | IsFixedWidth () const
| Returns true if the font is a fixed width (or monospaced) font, false if it is a proportional one or font is invalid. More...
virtual bool | IsOk () const
| Returns true if this object is a valid font, false otherwise. More...
static bool | AddPrivateFont (const wxString &filename)
| Specify the name of a file containing a TrueType font to be made available to the current application. More...

## Public Member Functions
| wxFont ()
| Default ctor. More...
| wxFont (const wxFont &font)
| Copy constructor, uses reference counting. More...
| wxFont (const wxFontInfo &fontInfo)
| Creates a font object using the specified font description. More...
| wxFont (int pointSize, wxFontFamily family, wxFontStyle style, wxFontWeight weight, bool underline=false, const wxString &faceName=wxEmptyString, wxFontEncoding encoding=wxFONTENCODING_DEFAULT)
| Creates a font object with the specified attributes and size in points. More...
| wxFont (const wxSize &pixelSize, wxFontFamily family, wxFontStyle style, wxFontWeight weight, bool underline=false, const wxString &faceName=wxEmptyString, wxFontEncoding encoding=wxFONTENCODING_DEFAULT)
| Creates a font object with the specified attributes and size in pixels. More...
| wxFont (const wxString &nativeInfoString)
| Constructor from font description string. More...
| wxFont (const wxNativeFontInfo &nativeInfo)
| Construct font from a native font info structure. More...
bool | operator!= (const wxFont &font) const
| Inequality operator. More...
bool | operator== (const wxFont &font) const
| Equality operator. More...
wxFont & | operator= (const wxFont &font)
| Assignment operator, using reference counting. More...
Similar fonts creation
The functions in this section either modify the font in place or create a new font similar to the given one but with its weight, style or size changed.
wxFont | Bold () const
| Returns a bold version of this font. More...
wxFont | Italic () const
| Returns an italic version of this font. More...
wxFont | Larger () const
| Returns a larger version of this font. More...
wxFont | Smaller () const
| Returns a smaller version of this font. More...
wxFont | Underlined () const
| Returns underlined version of this font. More...
wxFont | Strikethrough () const
| Returns stricken-through version of this font. More...
wxFont & | MakeBold ()
| Changes this font to be bold. More...
wxFont & | MakeItalic ()
| Changes this font to be italic. More...
wxFont & | MakeLarger ()
| Changes this font to be larger. More...
wxFont & | MakeSmaller ()
| Changes this font to be smaller. More...
wxFont & | MakeUnderlined ()
| Changes this font to be underlined. More...
wxFont & | MakeStrikethrough ()
| Changes this font to be stricken-through. More...
wxFont & | Scale (float x)
| Changes the size of this font. More...
wxFont | Scaled (float x) const
| Returns a scaled version of this font. More...
Setters
These functions internally recreate the native font object with the new specified property.
virtual void | SetEncoding (wxFontEncoding encoding)
| Sets the encoding for this font. More...
virtual bool | SetFaceName (const wxString &faceName)
| Sets the facename for the font. More...
virtual void | SetFamily (wxFontFamily family)
| Sets the font family. More...
bool | SetNativeFontInfo (const wxString &info)
| Creates the font corresponding to the given native font description string which must have been previously returned by GetNativeFontInfoDesc(). More...
bool | SetNativeFontInfoUserDesc (const wxString &info)
| Creates the font corresponding to the given native font description string and returns true if the creation was successful. More...
void | SetNativeFontInfo (const wxNativeFontInfo &info)
| Sets the encoding for this font. More...
virtual void | SetPointSize (int pointSize)
| Sets the font size in points to an integer value. More...
virtual void | SetFractionalPointSize (double pointSize)
| Sets the font size in points. More...
virtual void | SetPixelSize (const wxSize &pixelSize)
| Sets the pixel size. More...
virtual void | SetStyle (wxFontStyle style)
| Sets the font style. More...
void | SetSymbolicSize (wxFontSymbolicSize size)
| Sets the font size using a predefined symbolic size name. More...
void | SetSymbolicSizeRelativeTo (wxFontSymbolicSize size, int base)
| Sets the font size compared to the base font size. More...
virtual void | SetUnderlined (bool underlined)
| Sets underlining. More...
virtual void | SetStrikethrough (bool strikethrough)
| Sets strike-through attribute of the font. More...
virtual void | SetWeight (wxFontWeight weight)
| Sets the font weight. More...
virtual void | SetNumericWeight (int weight)
| Sets the font weight using an integer value. More...
Public Member Functions inherited from wxGDIObject
| wxGDIObject ()
| Default constructor. More...
Public Member Functions inherited from wxObject
| wxObject ()
| Default ctor; initializes to nullptr the internal reference data. More...
| wxObject (const wxObject &other)
| Copy ctor. More...
virtual | ~wxObject ()
| Destructor. More...
virtual wxClassInfo * | GetClassInfo () const
| This virtual function is redefined for every class that requires run-time type information, when using the wxDECLARE_CLASS macro (or similar). More...
wxObjectRefData * | GetRefData () const
| Returns the wxObject::m_refData pointer, i.e. the data referenced by this object. More...
bool | IsKindOf (const wxClassInfo *info) const
| Determines whether this class is a subclass of (or the same class as) the given class. More...
bool | IsSameAs (const wxObject &obj) const
| Returns true if this object has the same data pointer as obj. More...
void | Ref (const wxObject &clone)
| Makes this object refer to the data in clone. More...
void | SetRefData (wxObjectRefData *data)
| Sets the wxObject::m_refData pointer. More...
void | UnRef ()
| Decrements the reference count in the associated data, and if it is zero, deletes the data. More...
void | UnShare ()
| This is the same of AllocExclusive() but this method is public. More...
void | operator delete (void *buf)
| The delete operator is defined for debugging versions of the library only, when the identifier `__WXDEBUG__` is defined. More...
void * | operator new (size_t size, const wxString &filename=nullptr, int lineNum=0)
| The new operator is defined for debugging versions of the library only, when the identifier `__WXDEBUG__` is defined. More...

## Static Public Member Functions
static wxFontEncoding | GetDefaultEncoding ()
| Returns the current application's default encoding. More...
static void | SetDefaultEncoding (wxFontEncoding encoding)
| Sets the default font encoding. More...
static int | GetNumericWeightOf (wxFontWeight weight)
| Get the raw weight value corresponding to the given symbolic constant. More...
static wxFont * | New (int pointSize, wxFontFamily family, wxFontStyle style, wxFontWeight weight, bool underline=false, const wxString &faceName=wxEmptyString, wxFontEncoding encoding=wxFONTENCODING_DEFAULT)
| This function takes the same parameters as the relative wxFont constructor and returns a new font object allocated on the heap. More...
static wxFont * | New (int pointSize, wxFontFamily family, int flags=wxFONTFLAG_DEFAULT, const wxString &faceName=wxEmptyString, wxFontEncoding encoding=wxFONTENCODING_DEFAULT)
| This function takes the same parameters as the relative wxFont constructor and returns a new font object allocated on the heap. More...
static wxFont * | New (const wxSize &pixelSize, wxFontFamily family, wxFontStyle style, wxFontWeight weight, bool underline=false, const wxString &faceName=wxEmptyString, wxFontEncoding encoding=wxFONTENCODING_DEFAULT)
| This function takes the same parameters as the relative wxFont constructor and returns a new font object allocated on the heap. More...
static wxFont * | New (const wxSize &pixelSize, wxFontFamily family, int flags=wxFONTFLAG_DEFAULT, const wxString &faceName=wxEmptyString, wxFontEncoding encoding=wxFONTENCODING_DEFAULT)
| This function takes the same parameters as the relative wxFont constructor and returns a new font object allocated on the heap. More...
static wxFont * | New (const wxNativeFontInfo &nativeInfo)
| This function takes the same parameters as the relative wxFont constructor and returns a new font object allocated on the heap. More...
static wxFont * | New (const wxString &nativeInfoString)
| This function takes the same parameters as the relative wxFont constructor and returns a new font object allocated on the heap. More...

## Additional Inherited Members
Protected Member Functions inherited from wxObject
void | AllocExclusive ()
| Ensure that this object's data is not shared with any other object. More...
virtual wxObjectRefData * | CreateRefData () const
| Creates a new instance of the wxObjectRefData-derived class specific to this object and returns it. More...
virtual wxObjectRefData * | CloneRefData (const wxObjectRefData *data) const
| Creates a new instance of the wxObjectRefData-derived class specific to this object and initializes it copying data. More...
Protected Attributes inherited from wxObject
wxObjectRefData * | m_refData
| Pointer to an object which is the object's reference-counted data. More...

## Constructor & Destructor Documentation

## ◆ wxFont() [1/7]

wxFont::wxFont | ( |  | ) |

Default ctor.

## ◆ wxFont() [2/7]

wxFont::wxFont | ( | const wxFont & | font | ) |

Copy constructor, uses reference counting.

## ◆ wxFont() [3/7]

wxFont::wxFont | ( | const wxFontInfo & | fontInfo | ) |

Creates a font object using the specified font description.

This is the preferred way to create font objects as using this ctor results in more readable code and it is also extensible, e.g. it could continue to be used if support for more font attributes is added in the future. For example, this constructor provides the only way of creating fonts with strike-through style.

Example of creating a font using this ctor:

wxFont font(wxFontInfo(10).Bold().Underlined());
wxFont
A font is an object which determines the appearance of text.
Definition: font.h:510
wxFont::Underlined
wxFont Underlined() const
Returns underlined version of this font.
wxFont::Bold
wxFont Bold() const
Returns a bold version of this font.
wxFontInfo
This class is a helper used for wxFont creation using named parameter idiom: it allows specifying var...
Definition: font.h:314

Since
  2.9.5

## ◆ wxFont() [4/7]

wxFont::wxFont | ( | int | pointSize,
|  | wxFontFamily | family,
|  | wxFontStyle | style,
|  | wxFontWeight | weight,
|  | bool | underline = `false`,
|  | const wxString & | faceName = `wxEmptyString`,
|  | wxFontEncoding | encoding = `wxFONTENCODING_DEFAULT`
| ) |  |

Creates a font object with the specified attributes and size in points.

Notice that the use of this constructor is often more verbose and less readable than using wxFont(const wxFontInfo& font), e.g. the example in that constructor documentation would need to be written as:

wxFont font(10, wxFONTFAMILY_DEFAULT, wxFONTSTYLE_NORMAL,
wxFONTWEIGHT_BOLD, true);
wxFONTFAMILY_DEFAULT
@ wxFONTFAMILY_DEFAULT
Chooses a default font.
Definition: font.h:20
wxFONTWEIGHT_BOLD
@ wxFONTWEIGHT_BOLD
Bold font (weight = 700).
Definition: font.h:80
wxFONTSTYLE_NORMAL
@ wxFONTSTYLE_NORMAL
The font is drawn without slant.
Definition: font.h:50

Parameters

  pointSize | Size in points. See SetPointSize() for more info. Notice that, for historical reasons, the value 70 here is interpreted at `wxDEFAULT` and results in creation of the font with the default size and not of a font with the size of 70pt. If you really need the latter, please use SetPointSize(70). Note that this constructor and the matching Create() method overload are the only places in wxFont API handling `wxDEFAULT` specially: neither SetPointSize() nor the constructor taking wxFontInfo handle this value in this way.
  family | The font family: a generic portable way of referring to fonts without specifying a facename. This parameter must be one of the wxFontFamily enumeration values. If the faceName argument is provided, then it overrides the font family.
  style | One of `wxFONTSTYLE_NORMAL`, `wxFONTSTYLE_SLANT` and `wxFONTSTYLE_ITALIC`.
  weight | Font weight, sometimes also referred to as font boldness. One of the wxFontWeight enumeration values.
  underline | The value can be true or false.
  faceName | An optional string specifying the face name to be used. If it is an empty string, a default face name will be chosen based on the family.
  encoding | An encoding which may be one of the enumeration values of wxFontEncoding. If the specified encoding isn't available, no font is created (see also Font Encodings).

Remarks
  If the desired font does not exist, the closest match will be chosen. Under Windows, only scalable TrueType fonts are used.

## ◆ wxFont() [5/7]

wxFont::wxFont | ( | const wxSize & | pixelSize,
|  | wxFontFamily | family,
|  | wxFontStyle | style,
|  | wxFontWeight | weight,
|  | bool | underline = `false`,
|  | const wxString & | faceName = `wxEmptyString`,
|  | wxFontEncoding | encoding = `wxFONTENCODING_DEFAULT`
| ) |  |

Creates a font object with the specified attributes and size in pixels.

Notice that the use of this constructor is often more verbose and less readable than the use of constructor from wxFontInfo, consider using that constructor instead.

Parameters

  pixelSize | Size in pixels. See SetPixelSize() for more info.
  family | The font family: a generic portable way of referring to fonts without specifying a facename. This parameter must be one of the wxFontFamily enumeration values. If the faceName argument is provided, then it overrides the font family.
  style | One of `wxFONTSTYLE_NORMAL`, `wxFONTSTYLE_SLANT` and `wxFONTSTYLE_ITALIC`.
  weight | Font weight, sometimes also referred to as font boldness. One of the wxFontWeight enumeration values.
  underline | The value can be true or false.
  faceName | An optional string specifying the face name to be used. If it is an empty string, a default face name will be chosen based on the family.
  encoding | An encoding which may be one of the enumeration values of wxFontEncoding. If the specified encoding isn't available, no font is created (see also Font Encodings).

Remarks
  If the desired font does not exist, the closest match will be chosen. Under Windows, only scalable TrueType fonts are used.

## ◆ wxFont() [6/7]

wxFont::wxFont | ( | const wxString & | 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.

## ◆ wxFont() [7/7]

wxFont::wxFont | ( | const wxNativeFontInfo & | nativeInfo | ) |

Construct font from a native font info structure.

## Member Function Documentation

## ◆ AddPrivateFont()

static bool wxFont::AddPrivateFont | ( | const wxString & | filename | ) |
| static

Specify the name of a file containing a TrueType font to be made available to the current application.

This method can be used to allow this application to use the font from the given file even if it is not globally installed on the system.

Under macOS this method actually doesn't do anything other than check for the existence of the file and that it is located inside the "Fonts" subdirectory of the application bundle "Resources" directory. You are responsible for actually making the font file available in this directory and setting `ATSApplicationFontsPath` to `Fonts` value in your `Info.plist` file. See also wxStandardPaths::GetResourcesDir().

Under MSW this method must be called before any wxGraphicsContext objects have been created, otherwise the private font won't be usable from them.

Under Unix this method requires Pango 1.38 or later and will return false and log an error message explaining the problem if this requirement is not satisfied either at compile- or run-time.

Currently this method is implemented for all major platforms (subject to having Pango 1.38 or later when running configure under Unix) and `wxUSE_PRIVATE_FONTS` is always set to 0 under the other platforms, making this function unavailable at compile-time.

Parameters

  filename | Absolute path of the font file.

Returns
  true if the font was added and can now be used.

Since
  3.1.1

## ◆ Bold()

wxFont wxFont::Bold | ( |  | ) | const

Returns a bold version of this font.

See also
  MakeBold()

Since
  2.9.1

## ◆ GetBaseFont()

wxFont wxFont::GetBaseFont | ( |  | ) | const

Returns a font with the same face/size as the given one but with normal weight and style and not underlined nor stricken through.

Since
  3.1.0

## ◆ GetDefaultEncoding()

static wxFontEncoding wxFont::GetDefaultEncoding | ( |  | ) |
| static

Returns the current application's default encoding.

See also
  Font Encodings, SetDefaultEncoding()

## ◆ GetEncoding()

virtual wxFontEncoding wxFont::GetEncoding | ( |  | ) | const
| virtual

Returns the encoding of this font.

Note that under wxGTK the returned value is always `wxFONTENCODING_UTF8`.

See also
  SetEncoding()

## ◆ GetFaceName()

virtual wxString wxFont::GetFaceName | ( |  | ) | const
| virtual

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

See also
  SetFaceName()

## ◆ GetFamily()

virtual wxFontFamily wxFont::GetFamily | ( |  | ) | const
| virtual

Gets the font family if possible.

As described in wxFontFamily 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 wxFont or by the underlying system, `wxFONTFAMILY_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().

See also
  SetFamily()

## ◆ GetFractionalPointSize()

virtual double wxFont::GetFractionalPointSize | ( |  | ) | const
| virtual

Gets the point size as a floating number.

See also
  SetPointSize(float)

Since
  3.1.2

## ◆ GetNativeFontInfo()

const wxNativeFontInfo* wxFont::GetNativeFontInfo | ( |  | ) | const

Returns a font with the same face/size as the given one but with normal weight and style and not underlined nor stricken through.

Since
  3.1.0

## ◆ GetNativeFontInfoDesc()

wxString wxFont::GetNativeFontInfoDesc | ( |  | ) | const

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 wxFont object.

See also
  SetNativeFontInfo(), GetNativeFontInfoUserDesc()

## ◆ GetNativeFontInfoUserDesc()

wxString wxFont::GetNativeFontInfoUserDesc | ( |  | ) | const

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 wxFont 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().

See also
  SetNativeFontInfoUserDesc(), GetNativeFontInfoDesc()

## ◆ GetNumericWeight()

virtual int wxFont::GetNumericWeight | ( |  | ) | const
| virtual

Gets the font weight as an integer value.

See wxFontWeight for a list of valid weight identifiers and their corresponding integer value.

See also
  SetWeight()
  SetNumericWeight()

Since
  3.1.2

## ◆ GetNumericWeightOf()

static int wxFont::GetNumericWeightOf | ( | wxFontWeight | weight | ) |
| static

Get the raw weight value corresponding to the given symbolic constant.

For compatibility, this function handles the values `wxNORMAL`, `wxLIGHT` and `wxBOLD`, that have values 90, 91 and 92, specially and converts them to the corresponding `wxFONTWEIGHT_XXX` weight value.

Parameters

  weight | A valid element of wxFontWeight enum, i.e. this argument can't have value wxFONTWEIGHT_INVALID.

Returns
  Numeric weight, between 1 and 1000.

Since
  3.1.2

## ◆ GetPixelSize()

virtual wxSize wxFont::GetPixelSize | ( |  | ) | const
| virtual

Gets the pixel size.

Note that under wxMSW if you passed to SetPixelSize() (or to the ctor) a wxSize object with a null width value, you'll get a null width in the returned object.

See also
  SetPixelSize()

## ◆ GetPointSize()

virtual int wxFont::GetPointSize | ( |  | ) | const
| virtual

Gets the point size as an integer number.

This function is kept for compatibility reasons. New code should use GetFractionalPointSize() and support fractional point sizes.

See also
  SetPointSize(),
  GetFractionalPointSize()

## ◆ GetStrikethrough()

virtual bool wxFont::GetStrikethrough | ( |  | ) | const
| virtual

Returns true if the font is stricken-through, false otherwise.

See also
  SetStrikethrough()

Since
  2.9.4

## ◆ GetStyle()

virtual wxFontStyle wxFont::GetStyle | ( |  | ) | const
| virtual

Gets the font style.

See wxFontStyle for a list of valid styles.

See also
  SetStyle()

## ◆ GetUnderlined()

virtual bool wxFont::GetUnderlined | ( |  | ) | const
| virtual

Returns true if the font is underlined, false otherwise.

See also
  SetUnderlined()

## ◆ GetWeight()

virtual wxFontWeight wxFont::GetWeight | ( |  | ) | const
| virtual

Gets the font weight.

See wxFontWeight for a list of valid weight identifiers.

See also
  SetWeight()

## ◆ IsFixedWidth()

virtual bool wxFont::IsFixedWidth | ( |  | ) | const
| virtual

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 from just testing for the font family being equal to `wxFONTFAMILY_TELETYPE` because native platform-specific functions are used for the check (resulting in a more accurate return value).

## ◆ IsOk()

virtual bool wxFont::IsOk | ( |  | ) | const
| virtual

Returns true if this object is a valid font, false otherwise.

## ◆ Italic()

wxFont wxFont::Italic | ( |  | ) | const

Returns an italic version of this font.

See also
  MakeItalic()

Since
  2.9.1

## ◆ Larger()

wxFont wxFont::Larger | ( |  | ) | const

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.

See also
  MakeLarger(), Smaller(), Scaled()

Since
  2.9.1

## ◆ MakeBold()

wxFont& wxFont::MakeBold | ( |  | ) |

Changes this font to be bold.

See also
  Bold()

Since
  2.9.1

## ◆ MakeItalic()

wxFont& wxFont::MakeItalic | ( |  | ) |

Changes this font to be italic.

See also
  Italic()

Since
  2.9.1

## ◆ MakeLarger()

wxFont& wxFont::MakeLarger | ( |  | ) |

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.

See also
  Larger(), MakeSmaller(), Scale()

Since
  2.9.1

## ◆ MakeSmaller()

wxFont& wxFont::MakeSmaller | ( |  | ) |

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.

See also
  Smaller(), MakeLarger(), Scale()

Since
  2.9.1

## ◆ MakeStrikethrough()

wxFont& wxFont::MakeStrikethrough | ( |  | ) |

Changes this font to be stricken-through.

Currently stricken-through fonts are only supported in wxMSW, wxGTK, and wxOSX.

See also
  Strikethrough()

Since
  2.9.4

## ◆ MakeUnderlined()

wxFont& wxFont::MakeUnderlined | ( |  | ) |

Changes this font to be underlined.

See also
  Underlined()

Since
  2.9.2

## ◆ New() [1/6]

static wxFont* wxFont::New | ( | const wxNativeFontInfo & | nativeInfo | ) |
| static

This function takes the same parameters as the relative wxFont constructor and returns a new font object allocated on the heap.

Their use is discouraged, use wxFont constructor from wxFontInfo instead.

## ◆ New() [2/6]

static wxFont* wxFont::New | ( | const wxSize & | pixelSize,
|  | wxFontFamily | family,
|  | int | flags = `wxFONTFLAG_DEFAULT`,
|  | const wxString & | faceName = `wxEmptyString`,
|  | wxFontEncoding | encoding = `wxFONTENCODING_DEFAULT`
| ) |  |
| static

This function takes the same parameters as the relative wxFont constructor and returns a new font object allocated on the heap.

Their use is discouraged, use wxFont constructor from wxFontInfo instead.

## ◆ New() [3/6]

static wxFont* wxFont::New | ( | const wxSize & | pixelSize,
|  | wxFontFamily | family,
|  | wxFontStyle | style,
|  | wxFontWeight | weight,
|  | bool | underline = `false`,
|  | const wxString & | faceName = `wxEmptyString`,
|  | wxFontEncoding | encoding = `wxFONTENCODING_DEFAULT`
| ) |  |
| static

This function takes the same parameters as the relative wxFont constructor and returns a new font object allocated on the heap.

Their use is discouraged, use wxFont constructor from wxFontInfo instead.

## ◆ New() [4/6]

static wxFont* wxFont::New | ( | const wxString & | nativeInfoString | ) |
| static

This function takes the same parameters as the relative wxFont constructor and returns a new font object allocated on the heap.

Their use is discouraged, use wxFont constructor from wxFontInfo instead.

## ◆ New() [5/6]

static wxFont* wxFont::New | ( | int | pointSize,
|  | wxFontFamily | family,
|  | int | flags = `wxFONTFLAG_DEFAULT`,
|  | const wxString & | faceName = `wxEmptyString`,
|  | wxFontEncoding | encoding = `wxFONTENCODING_DEFAULT`
| ) |  |
| static

This function takes the same parameters as the relative wxFont constructor and returns a new font object allocated on the heap.

Their use is discouraged, use wxFont constructor from wxFontInfo instead.

## ◆ New() [6/6]

static wxFont* wxFont::New | ( | int | pointSize,
|  | wxFontFamily | family,
|  | wxFontStyle | style,
|  | wxFontWeight | weight,
|  | bool | underline = `false`,
|  | const wxString & | faceName = `wxEmptyString`,
|  | wxFontEncoding | encoding = `wxFONTENCODING_DEFAULT`
| ) |  |
| static

This function takes the same parameters as the relative wxFont constructor and returns a new font object allocated on the heap.

Their use is discouraged, use wxFont constructor from wxFontInfo instead.

## ◆ operator!=()

bool wxFont::operator!= | ( | const wxFont & | font | ) | const

Inequality operator.

See reference-counted object comparison for more info.

## ◆ operator=()

wxFont& wxFont::operator= | ( | const wxFont & | font | ) |

Assignment operator, using reference counting.

## ◆ operator==()

bool wxFont::operator== | ( | const wxFont & | font | ) | const

Equality operator.

See reference-counted object comparison for more info.

## ◆ Scale()

wxFont& wxFont::Scale | ( | float | x | ) |

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).

See also
  Scaled(), MakeLarger(), MakeSmaller()

Since
  2.9.1

## ◆ Scaled()

wxFont wxFont::Scaled | ( | float | x | ) | const

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).

See also
  Scale(), Larger(), Smaller()

Since
  2.9.1

## ◆ SetDefaultEncoding()

static void wxFont::SetDefaultEncoding | ( | wxFontEncoding | encoding | ) |
| static

Sets the default font encoding.

See also
  Font Encodings, GetDefaultEncoding()

## ◆ SetEncoding()

virtual void wxFont::SetEncoding | ( | wxFontEncoding | encoding | ) |
| virtual

Sets the encoding for this font.

Note that under wxGTK this function has no effect (because the underlying Pango library always uses `wxFONTENCODING_UTF8`).

See also
  GetEncoding()

## ◆ SetFaceName()

virtual bool wxFont::SetFaceName | ( | const wxString & | faceName | ) |
| virtual

Sets the facename for the font.

Parameters

  faceName | A valid facename, which should be on the end-user's system.

Remarks
  To avoid portability problems, don't rely on a specific face, but specify the font family instead (see wxFontFamily and SetFamily()).

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.

See also
  GetFaceName(), SetFamily()

## ◆ SetFamily()

virtual void wxFont::SetFamily | ( | wxFontFamily | family | ) |
| virtual

Sets the font family.

As described in wxFontFamily 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 | One of the wxFontFamily values.

See also
  GetFamily(), SetFaceName()

## ◆ SetFractionalPointSize()

virtual void wxFont::SetFractionalPointSize | ( | double | pointSize | ) |
| virtual

Sets the font size in points.

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 | Size in points. This can also be a fractional point size like 11.5.

See also
  GetFractionalPointSize(), SetPointSize()

Since
  3.1.2

## ◆ SetNativeFontInfo() [1/2]

void wxFont::SetNativeFontInfo | ( | const wxNativeFontInfo & | info | ) |

Sets the encoding for this font.

Note that under wxGTK this function has no effect (because the underlying Pango library always uses `wxFONTENCODING_UTF8`).

See also
  GetEncoding()

## ◆ SetNativeFontInfo() [2/2]

bool wxFont::SetNativeFontInfo | ( | const wxString & | 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 wxFont object previously saved in a string-form.

Returns
  true if the creation was successful.

See also
  SetNativeFontInfoUserDesc()

## ◆ SetNativeFontInfoUserDesc()

bool wxFont::SetNativeFontInfoUserDesc | ( | const wxString & | 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:

platform | generic syntax | example
--- | --- | ---
wxGTK2 | `[underlined] [strikethrough] [FACE-NAME] [bold] [oblique|italic] [POINTSIZE]` | Monospace bold 10
wxMSW | `[light|bold] [italic] [FACE-NAME] [POINTSIZE] [ENCODING]` | Tahoma 10 WINDOWS-1252

Todo:
  add an example for wxMac

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` under GTK, although notice that it doesn't support the "underlined" and "strikethrough" attributes and so those are handled by wxWidgets itself).

Note that unlike SetNativeFontInfo(), this function doesn't always restore all attributes of the wxFont 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.

See also
  SetNativeFontInfo()

## ◆ SetNumericWeight()

virtual void wxFont::SetNumericWeight | ( | int | weight | ) |
| virtual

Sets the font weight using an integer value.

See wxFontWeight for a list of valid weight identifiers and their corresponding integer value.

Parameters

  weight | An integer value int the range 1-1000.

See also
  GetNumericWeight()

## ◆ SetPixelSize()

virtual void wxFont::SetPixelSize | ( | const wxSize & | pixelSize | ) |
| virtual

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).

See also
  GetPixelSize()

## ◆ SetPointSize()

virtual void wxFont::SetPointSize | ( | int | pointSize | ) |
| virtual

Sets the font size in points to an integer value.

This is a legacy version of the function only supporting integer point sizes. It can still be used, but to avoid unnecessarily restricting the font size in points to integer values, consider using the new (added in wxWidgets 3.1.2) SetFractionalPointSize() function instead.

## ◆ SetStrikethrough()

virtual void wxFont::SetStrikethrough | ( | bool | strikethrough | ) |
| virtual

Sets strike-through attribute of the font.

Currently stricken-through fonts are only supported in wxMSW, wxGTK, and wxOSX.

Parameters

  strikethrough | true to add strike-through style, false to remove it.

See also
  GetStrikethrough()

Since
  2.9.4

## ◆ SetStyle()

virtual void wxFont::SetStyle | ( | wxFontStyle | style | ) |
| virtual

Sets the font style.

Parameters

  style | One of the wxFontStyle enumeration values.

See also
  GetStyle()

## ◆ SetSymbolicSize()

void wxFont::SetSymbolicSize | ( | wxFontSymbolicSize | size | ) |

Sets the font size using a predefined symbolic size name.

This function allows changing font size to be (very) large or small compared to the standard font size.

See also
  SetSymbolicSizeRelativeTo().

Since
  2.9.2

## ◆ SetSymbolicSizeRelativeTo()

void wxFont::SetSymbolicSizeRelativeTo | ( | wxFontSymbolicSize | size,
|  | int | base
| ) |  |

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.

Since
  2.9.2

## ◆ SetUnderlined()

virtual void wxFont::SetUnderlined | ( | bool | underlined | ) |
| virtual

Sets underlining.

Parameters

  underlined | true to underline, false otherwise.

See also
  GetUnderlined()

## ◆ SetWeight()

virtual void wxFont::SetWeight | ( | wxFontWeight | weight | ) |
| virtual

Sets the font weight.

Parameters

  weight | One of the wxFontWeight values.

See also
  GetWeight()

## ◆ Smaller()

wxFont wxFont::Smaller | ( |  | ) | const

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.

See also
  MakeSmaller(), Larger(), Scaled()

Since
  2.9.1

## ◆ Strikethrough()

wxFont wxFont::Strikethrough | ( |  | ) | const

Returns stricken-through version of this font.

Currently stricken-through fonts are only supported in wxMSW, wxGTK, and wxOSX.

See also
  MakeStrikethrough()

Since
  2.9.4

## ◆ Underlined()

wxFont wxFont::Underlined | ( |  | ) | const

Returns underlined version of this font.

See also
  MakeUnderlined()

Since
  2.9.2