wxWidgets: wxFontInfo Class Reference

| Version: 3.2.7

Public Member Functions | Static Public Member Functions | List of all members
wxFontInfo Class Reference

`#include <wx/font.h>`

## Detailed Description

This class is a helper used for wxFont creation using named parameter idiom: it allows specifying various wxFont attributes using the chained calls to its clearly named methods instead of passing them in the fixed order to wxFont constructors.

For example, to create an italic font with the given face name and size you could use:

wxFont font(wxFontInfo(12).FaceName("Helvetica").Italic());
wxFont
A font is an object which determines the appearance of text.
Definition: font.h:510
wxFontInfo::wxFontInfo
wxFontInfo()
Default constructor uses the default font size for the current platform.
wxFontInfo::Italic
wxFontInfo & Italic(bool italic=true)
Use an italic version of the font.
wxFontInfo::FaceName
wxFontInfo & FaceName(const wxString &faceName)
Set the font face name to use.

Notice that all of the methods of this object return a reference to the object itself, allowing the calls to them to be chained as in the example above.

All methods taking boolean parameters can be used to turn the specified font attribute on or off and turn it on by default.

Since
  2.9.5

## Public Member Functions
| wxFontInfo ()
| Default constructor uses the default font size for the current platform. More...
| wxFontInfo (double pointSize)
| Constructor setting the font size in points to use. More...
| wxFontInfo (const wxSize &pixelSize)
| Constructor setting the font size in pixels to use. More...
wxFontInfo & | Family (wxFontFamily family)
| Set the font family. More...
wxFontInfo & | FaceName (const wxString &faceName)
| Set the font face name to use. More...
wxFontInfo & | Weight (int weight)
| Specify the weight of the font. More...
wxFontInfo & | Bold (bool bold=true)
| Use a bold version of the font. More...
wxFontInfo & | Light (bool light=true)
| Use a lighter version of the font. More...
wxFontInfo & | Italic (bool italic=true)
| Use an italic version of the font. More...
wxFontInfo & | Slant (bool slant=true)
| Use a slanted version of the font. More...
wxFontInfo & | Style (wxFontStyle style)
| Specify the style of the font using one of wxFontStyle constants. More...
wxFontInfo & | AntiAliased (bool antiAliased=true)
| Set anti-aliasing flag. More...
wxFontInfo & | Underlined (bool underlined=true)
| Use an underlined version of the font. More...
wxFontInfo & | Strikethrough (bool strikethrough=true)
| Use a strike-through version of the font. More...
wxFontInfo & | Encoding (wxFontEncoding encoding)
| Set the font encoding to use. More...
wxFontInfo & | AllFlags (int flags)
| Set all the font attributes at once. More...

## Static Public Member Functions
static wxFontWeight | GetWeightClosestToNumericValue (int numWeight)
| Get the symbolic weight closest to the given raw weight value. More...

## Constructor & Destructor Documentation

## ◆ wxFontInfo() [1/3]

wxFontInfo::wxFontInfo | ( |  | ) |

Default constructor uses the default font size for the current platform.

## ◆ wxFontInfo() [2/3]

wxFontInfo::wxFontInfo | ( | double | pointSize | ) |
| explicit

Constructor setting the font size in points to use.

Note that until wxWidgets 3.1.2 fractional point sizes were not supported, and the type of pointSize was `int`.

See also
  wxFont::SetPointSize()

## ◆ wxFontInfo() [3/3]

wxFontInfo::wxFontInfo | ( | const wxSize & | pixelSize | ) |
| explicit

Constructor setting the font size in pixels to use.

See also
  wxFont::SetPixelSize()

## Member Function Documentation

## ◆ AllFlags()

wxFontInfo& wxFontInfo::AllFlags | ( | int | flags | ) |

Set all the font attributes at once.

See wxFontFlag for the various flags that can be used.

Note that calling this method affects the font weight stored in this object: it is set to wxFONTWEIGHT_LIGHT or wxFONTWEIGHT_BOLD if the corresponding flag is present in flags, or wxFONTWEIGHT_NORMAL otherwise.

## ◆ AntiAliased()

wxFontInfo& wxFontInfo::AntiAliased | ( | bool | antiAliased = `true` | ) |

Set anti-aliasing flag.

Force the use of anti-aliasing on or off.

Currently this is not implemented, i.e. using this method doesn't do anything.

## ◆ Bold()

wxFontInfo& wxFontInfo::Bold | ( | bool | bold = `true` | ) |

Use a bold version of the font.

This is a wrapper for Weight() calling it with wxFONTWEIGHT_BOLD argument.

See also
  wxFontWeight, wxFont::SetWeight()

## ◆ Encoding()

wxFontInfo& wxFontInfo::Encoding | ( | wxFontEncoding | encoding | ) |

Set the font encoding to use.

This is mostly unneeded in Unicode builds of wxWidgets.

See also
  wxFontEncoding, wxFont::SetEncoding()

## ◆ FaceName()

wxFontInfo& wxFontInfo::FaceName | ( | const wxString & | faceName | ) |

Set the font face name to use.

Face names are not portable, so prefer to use Family() in portable code.

See also
  wxFont::SetFaceName()

## ◆ Family()

wxFontInfo& wxFontInfo::Family | ( | wxFontFamily | family | ) |

Set the font family.

The family is a generic portable way of referring to fonts without specifying a precise face name. This parameter must be one of the wxFontFamily enumeration values.

If the FaceName() is used, then it overrides the font family.

See also
  wxFont::SetFamily()

## ◆ GetWeightClosestToNumericValue()

static wxFontWeight wxFontInfo::GetWeightClosestToNumericValue | ( | int | numWeight | ) |
| static

Get the symbolic weight closest to the given raw weight value.

Parameters

  numWeight | A valid raw weight value, i.e. a value in the range 1 to 1000, inclusive.

Returns
  A valid element of wxFontWeight enum.

Since
  3.1.2

## ◆ Italic()

wxFontInfo& wxFontInfo::Italic | ( | bool | italic = `true` | ) |

Use an italic version of the font.

This is a wrapper for Style() calling it with wxFONTSTYLE_ITALIC argument.

See also
  wxFontStyle, wxFont::SetStyle()

## ◆ Light()

wxFontInfo& wxFontInfo::Light | ( | bool | light = `true` | ) |

Use a lighter version of the font.

This is a wrapper for Weight() calling it with wxFONTWEIGHT_LIGHT argument.

See also
  wxFontWeight, wxFont::SetWeight()

## ◆ Slant()

wxFontInfo& wxFontInfo::Slant | ( | bool | slant = `true` | ) |

Use a slanted version of the font.

This is a wrapper for Style() calling it with wxFONTSTYLE_SLANT argument.

See also
  wxFontStyle, wxFont::SetStyle()

## ◆ Strikethrough()

wxFontInfo& wxFontInfo::Strikethrough | ( | bool | strikethrough = `true` | ) |

Use a strike-through version of the font.

Currently this is only implemented in wxMSW, wxGTK, and wxOSX.

## ◆ Style()

wxFontInfo& wxFontInfo::Style | ( | wxFontStyle | style | ) |

Specify the style of the font using one of wxFontStyle constants.

Since
  3.1.2

## ◆ Underlined()

wxFontInfo& wxFontInfo::Underlined | ( | bool | underlined = `true` | ) |

Use an underlined version of the font.

## ◆ Weight()

wxFontInfo& wxFontInfo::Weight | ( | int | weight | ) |

Specify the weight of the font.

Parameters

  weight | A font weight in the range from 1 to 1000, inclusive, with 1 being the thinnest and 1000 the heaviest possible font variant. `wxFONTWEIGHT_XXX` values from wxFontWeight enum can be used here.

Since
  3.1.2