Loading...
Searching...
No Matches
juce::Font Class Referencefinal

## Detailed Description

Represents a particular font, including its size, style, etc.

Apart from the typeface to be used, a Font object also dictates whether the font is bold, italic, underlined, how big it is, and its kerning and horizontal scale factor.

See also
  Typeface

The documentation for this class was generated from the following file:

- juce_graphics/fonts/juce_Font.h

## Public Types

enum | FontStyleFlags { plain = 0 , bold = 1 , italic = 2 , underlined = 4 }
| A combination of these values is used by the constructor to specify the style of font to use. More...

## Public Member Functions

| Font (FontOptions options)
| Constructs a Font from a set of options describing the font.
| Font (float fontHeight, int styleFlags=plain)
| Creates a sans-serif font in a given size.
| Font (const String &typefaceName, float fontHeight, int styleFlags)
| Creates a font with a given typeface and parameters.
| Font (const String &typefaceName, const String &typefaceStyle, float fontHeight)
| Creates a font with a given typeface and parameters.
| Font (const Typeface::Ptr &typeface)
| Creates a font for a typeface.
| Font ()
| Creates a basic sans-serif font at a default height.
| Font (const Font &other) noexcept
| Creates a copy of another Font object.
| Font (Font &&other) noexcept
| Move constructor.
Font & | operator= (Font &&other) noexcept
| Move assignment operator.
Font & | operator= (const Font &other) noexcept
| Copies this font from another one.
bool | operator== (const Font &other) const noexcept
bool | operator!= (const Font &other) const noexcept
| ~Font () noexcept
| Destructor.
void | setTypefaceName (const String &faceName)
| Changes the font family of the typeface.
String | getTypefaceName () const noexcept
| Returns the font family of the typeface that this font uses.
String | getTypefaceStyle () const noexcept
| Returns the font style of the typeface that this font uses.
void | setTypefaceStyle (const String &newStyle)
| Changes the font style of the typeface.
Font | withTypefaceStyle (const String &newStyle) const
| Returns a copy of this font with a new typeface style.
StringArray | getAvailableStyles () const
| Returns a list of the styles that this font can use.
void | setPreferredFallbackFamilies (const StringArray &fallbacks)
| Sets the names of the fallback font families that should be tried, in order, when searching for glyphs that are missing in the main typeface, specified via setTypefaceName() or Font(const Typeface::Ptr&).
StringArray | getPreferredFallbackFamilies () const
| Returns the names of the fallback font families.
void | setFallbackEnabled (bool enabled)
| When drawing text using this Font, specifies whether glyphs that are missing in the main typeface should be replaced with glyphs from other fonts.
bool | getFallbackEnabled () const
| Returns true if fallback is enabled, or false otherwise.
Font | withHeight (float height) const
| Returns a copy of this font with a new height.
Font | withPointHeight (float heightInPoints) const
| Returns a copy of this font with a new height, specified in points.
void | setHeight (float newHeight)
| Changes the font's height.
void | setPointHeight (float newHeight)
| Changes the font's height.
void | setHeightWithoutChangingWidth (float newHeight)
| Changes the font's height without changing its width.
float | getHeight () const noexcept
| Returns the total height of this font, in pixels.
float | getHeightInPoints () const
| Returns the total height of this font, in points.
float | getAscent () const
| Returns the height of the font above its baseline, in pixels.
float | getAscentInPoints () const
| Returns the height of the font above its baseline, in points.
float | getDescent () const
| Returns the amount that the font descends below its baseline, in pixels.
float | getDescentInPoints () const
| Returns the amount that the font descends below its baseline, in points.
int | getStyleFlags () const noexcept
| Returns the font's style flags.
Font | withStyle (int styleFlags) const
| Returns a copy of this font with the given set of style flags.
void | setStyleFlags (int newFlags)
| Changes the font's style.
void | setBold (bool shouldBeBold)
| Makes the font bold or non-bold.
Font | boldened () const
| Returns a copy of this font with the bold attribute set.
bool | isBold () const noexcept
| Returns true if the font is bold.
void | setItalic (bool shouldBeItalic)
| Makes the font italic or non-italic.
Font | italicised () const
| Returns a copy of this font with the italic attribute set.
bool | isItalic () const noexcept
| Returns true if the font is italic.
void | setUnderline (bool shouldBeUnderlined)
| Makes the font underlined or non-underlined.
bool | isUnderlined () const noexcept
| Returns true if the font is underlined.
TypefaceMetricsKind | getMetricsKind () const noexcept
| Returns the kind of metrics used by this Font.
Span< const FontFeatureSetting > | getFeatureSettings () const &
| Returns an Span view of the features configured for this font instance.
Span< const FontFeatureSetting > | getFeatureSettings () const &&=delete
void | setFeatureSetting (FontFeatureSetting featureSetting)
| Enables or disables a font feature.
void | removeFeatureSetting (FontFeatureTag featureToRemove)
| Removes a specific feature setting from this font.
float | getHorizontalScale () const noexcept
| Returns the font's horizontal scale.
Font | withHorizontalScale (float scaleFactor) const
| Returns a copy of this font with a new horizontal scale.
void | setHorizontalScale (float scaleFactor)
| Changes the font's horizontal scale factor.
float | getExtraKerningFactor () const noexcept
| Returns the font's tracking, i.e.
Font | withExtraKerningFactor (float extraKerning) const
| Returns a copy of this font with a new tracking factor.
void | setExtraKerningFactor (float extraKerning)
| Changes the font's tracking.
std::optional< float > | getAscentOverride () const noexcept
void | setAscentOverride (std::optional< float >)
| This is designed to mirror CSS's ascent-override property.
std::optional< float > | getDescentOverride () const noexcept
void | setDescentOverride (std::optional< float >)
| This is designed to mirror CSS's descent-override property.
void | setSizeAndStyle (float newHeight, int newStyleFlags, float newHorizontalScale, float newKerningAmount)
| Changes all the font's characteristics with one call.
void | setSizeAndStyle (float newHeight, const String &newStyle, float newHorizontalScale, float newKerningAmount)
| Changes all the font's characteristics with one call.
int | getStringWidth (const String &text) const
| Returns the total width of a string as it would be drawn using this font.
float | getStringWidthFloat (const String &text) const
| Returns the total width of a string as it would be drawn using this font.
Typeface::Ptr | getTypefacePtr () const
| Returns the main typeface used by this font.
Font | findSuitableFontForText (const String &text, const String &language={}) const
| Attempts to locate a visually similar font that is capable of rendering the provided string.
String | toString () const
| Creates a string to describe this font.
Native | getNativeDetails () const
float | getHeightToPointsFactor () const

## Static Public Member Functions

static const String & | getDefaultSansSerifFontName ()
| Returns a typeface font family that represents the default sans-serif font.
static const String & | getSystemUIFontName ()
| Returns a typeface font family that represents the system UI font.
static const String & | getDefaultSerifFontName ()
| Returns a typeface font family that represents the default serif font.
static const String & | getDefaultMonospacedFontName ()
| Returns a typeface font family that represents the default monospaced font.
static const String & | getDefaultStyle ()
| Returns a font style name that represents the default style.
static Typeface::Ptr | getDefaultTypefaceForFont (const Font &font)
| Returns the default system typeface for the given font.
static float | getDefaultMinimumHorizontalScaleFactor () noexcept
| Returns the minimum horizontal scale to which fonts may be squashed when trying to create a layout.
static void | setDefaultMinimumHorizontalScaleFactor (float newMinimumScaleFactor) noexcept
| Sets the minimum horizontal scale to which fonts may be squashed when trying to create a text layout.
static void | findFonts (Array< Font > &results)
| Creates an array of Font objects to represent all the fonts on the system.
static StringArray | findAllTypefaceNames ()
| Returns a list of all the available typeface font families.
static StringArray | findAllTypefaceStyles (const String &family)
| Returns a list of all the available typeface font styles.
static Font | fromString (const String &fontDescription)
| Recreates a font from its stringified encoding.

## Member Enums

## FontStyleFlags

enum juce::Font::FontStyleFlags

A combination of these values is used by the constructor to specify the style of font to use.

Enumerator

plain

indicates a plain, non-bold, non-italic version of the font.

See also
  setStyleFlags

bold

boldens the font.

See also
  setStyleFlags

italic

finds an italic version of the font.

See also
  setStyleFlags

underlined

underlines the font.

See also
  setStyleFlags

## Constructors and Destructors

## Font() [1/8]

juce::Font::Font | ( | FontOptions | options | ) |

Constructs a Font from a set of options describing the font.

Referenced by boldened(), findFonts(), findSuitableFontForText(), Font(), Font(), fromString(), getDefaultTypefaceForFont(), getHeightToPointsFactor(), GraphicsFontHelpers, italicised(), operator!=(), operator=(), operator=(), operator==(), withExtraKerningFactor(), withHeight(), withHorizontalScale(), withPointHeight(), withStyle(), and withTypefaceStyle().

## Font() [2/8]

juce::Font::Font | ( | float | fontHeight,
|  | int | styleFlags = plain )

Creates a sans-serif font in a given size.

Parameters

  fontHeight | the height in pixels (can be fractional)
  styleFlags | the style to use - this can be a combination of the Font::bold, Font::italic and Font::underlined, or just Font::plain for the normal style.

See also
  FontStyleFlags, getDefaultSansSerifFontName

References plain.

## Font() [3/8]

juce::Font::Font | ( | const String & | typefaceName,
|  | float | fontHeight,
|  | int | styleFlags )

Creates a font with a given typeface and parameters.

Parameters

  typefaceName | the font family of the typeface to use
  fontHeight | the height in pixels (can be fractional)
  styleFlags | the style to use - this can be a combination of the Font::bold, Font::italic and Font::underlined, or just Font::plain for the normal style.

See also
  FontStyleFlags, getDefaultSansSerifFontName

## Font() [4/8]

juce::Font::Font | ( | const String & | typefaceName,
|  | const String & | typefaceStyle,
|  | float | fontHeight )

Creates a font with a given typeface and parameters.

Parameters

  typefaceName | the font family of the typeface to use
  typefaceStyle | the font style of the typeface to use
  fontHeight | the height in pixels (can be fractional)

## Font() [5/8]

juce::Font::Font | ( | const Typeface::Ptr & | typeface | ) |

Creates a font for a typeface.

## Font() [6/8]

juce::Font::Font | ( |  | ) |

Creates a basic sans-serif font at a default height.

You should use one of the other constructors for creating a font that you're planning on drawing with - this constructor is here to help initialise objects before changing the font's settings later.

## Font() [7/8]

juce::Font::Font | ( | const Font & | other | ) |

noexcept

Creates a copy of another Font object.

References Font().

## Font() [8/8]

juce::Font::Font | ( | Font && | other | ) |

noexcept

Move constructor.

References Font().

## ~Font()

juce::Font::~Font | ( |  | ) |

noexcept

Destructor.

## Member Functions

## operator=() [1/2]

Font & juce::Font::operator= | ( | Font && | other | ) |

noexcept

Move assignment operator.

References Font().

## operator=() [2/2]

Font & juce::Font::operator= | ( | const Font & | other | ) |

noexcept

Copies this font from another one.

References Font().

## operator==()

bool juce::Font::operator== | ( | const Font & | other | ) | const

noexcept

References Font().

## operator!=()

bool juce::Font::operator!= | ( | const Font & | other | ) | const

noexcept

References Font().

## setTypefaceName()

void juce::Font::setTypefaceName | ( | const String & | faceName | ) |

Changes the font family of the typeface.

e.g. "Arial", "Courier", etc.

This may also be set to Font::getDefaultSansSerifFontName(), Font::getDefaultSerifFontName(), or Font::getDefaultMonospacedFontName(), which are not actual platform-specific font family names, but are generic font family names that are used to represent the various default fonts. If you need to know the exact typeface font family being used, you can call Font::getTypefacePtr()->getName(), which will give you the platform-specific font family.

If a suitable font isn't found on the machine, it'll just use a default instead.

References setTypefaceName().

Referenced by setTypefaceName().

## getTypefaceName()

String juce::Font::getTypefaceName | ( |  | ) | const

noexcept

Returns the font family of the typeface that this font uses.

e.g. "Arial", "Courier", etc.

This may also be set to Font::getDefaultSansSerifFontName(), Font::getDefaultSerifFontName(), or Font::getDefaultMonospacedFontName(), which are not actual platform-specific font family names, but are generic font family names that are used to represent the various default fonts.

If you need to know the exact typeface font family being used, you can call Font::getTypefacePtr()->getName(), which will give you the platform-specific font family.

References getTypefaceName().

Referenced by getTypefaceName().

## getTypefaceStyle()

String juce::Font::getTypefaceStyle | ( |  | ) | const

noexcept

Returns the font style of the typeface that this font uses.

See also
  withTypefaceStyle, getAvailableStyles()

References getTypefaceStyle().

Referenced by getTypefaceStyle().

## setTypefaceStyle()

void juce::Font::setTypefaceStyle | ( | const String & | newStyle | ) |

Changes the font style of the typeface.

See also
  getAvailableStyles()

References setTypefaceStyle().

Referenced by setTypefaceStyle().

## withTypefaceStyle()

Font juce::Font::withTypefaceStyle | ( | const String & | newStyle | ) | const

nodiscard

Returns a copy of this font with a new typeface style.

See also
  getAvailableStyles()

References Font(), and withTypefaceStyle().

Referenced by withTypefaceStyle().

## getAvailableStyles()

StringArray juce::Font::getAvailableStyles | ( |  | ) | const

Returns a list of the styles that this font can use.

References getAvailableStyles().

Referenced by getAvailableStyles().

## setPreferredFallbackFamilies()

void juce::Font::setPreferredFallbackFamilies | ( | const StringArray & | fallbacks | ) |

Sets the names of the fallback font families that should be tried, in order, when searching for glyphs that are missing in the main typeface, specified via setTypefaceName() or Font(const Typeface::Ptr&).

References setPreferredFallbackFamilies().

Referenced by setPreferredFallbackFamilies().

## getPreferredFallbackFamilies()

StringArray juce::Font::getPreferredFallbackFamilies | ( |  | ) | const

Returns the names of the fallback font families.

References getPreferredFallbackFamilies().

Referenced by getPreferredFallbackFamilies().

## setFallbackEnabled()

void juce::Font::setFallbackEnabled | ( | bool | enabled | ) |

When drawing text using this Font, specifies whether glyphs that are missing in the main typeface should be replaced with glyphs from other fonts.

To find missing glyphs, the typefaces for the preferred fallback families will be checked in order, followed by the system fallback fonts. The system fallback font is likely to be different on each platform.

Fallback is enabled by default.

References setFallbackEnabled().

Referenced by setFallbackEnabled().

## getFallbackEnabled()

bool juce::Font::getFallbackEnabled | ( |  | ) | const

Returns true if fallback is enabled, or false otherwise.

References getFallbackEnabled().

Referenced by getFallbackEnabled().

## getDefaultSansSerifFontName()

const String & juce::Font::getDefaultSansSerifFontName | ( |  | ) |

static

Returns a typeface font family that represents the default sans-serif font.

This is also the typeface that will be used when a font is created without specifying any typeface details.

Note that this method just returns a generic placeholder string that means "the default sans-serif font" - it's not the actual font family of this font.

See also
  setTypefaceName, getDefaultSerifFontName, getDefaultMonospacedFontName

References getDefaultSansSerifFontName().

Referenced by getDefaultSansSerifFontName().

## getSystemUIFontName()

const String & juce::Font::getSystemUIFontName | ( |  | ) |

static

Returns a typeface font family that represents the system UI font.

Note that this method just returns a generic placeholder string that means "the default UI font" - it's not the actual font family of this font.

See also
  getDefaultSansSerifFontName, setTypefaceName

References getSystemUIFontName().

Referenced by getSystemUIFontName().

## getDefaultSerifFontName()

const String & juce::Font::getDefaultSerifFontName | ( |  | ) |

static

Returns a typeface font family that represents the default serif font.

Note that this method just returns a generic placeholder string that means "the default serif font" - it's not the actual font family of this font.

See also
  setTypefaceName, getDefaultSansSerifFontName, getDefaultMonospacedFontName

References getDefaultSerifFontName().

Referenced by getDefaultSerifFontName().

## getDefaultMonospacedFontName()

const String & juce::Font::getDefaultMonospacedFontName | ( |  | ) |

static

Returns a typeface font family that represents the default monospaced font.

Note that this method just returns a generic placeholder string that means "the default monospaced font" - it's not the actual font family of this font.

See also
  setTypefaceName, getDefaultSansSerifFontName, getDefaultSerifFontName

References getDefaultMonospacedFontName().

Referenced by getDefaultMonospacedFontName().

## getDefaultStyle()

const String & juce::Font::getDefaultStyle | ( |  | ) |

static

Returns a font style name that represents the default style.

Note that this method just returns a generic placeholder string that means "the default font style" - it's not the actual name of the font style of any particular font.

See also
  setTypefaceStyle

References getDefaultStyle().

Referenced by getDefaultStyle().

## getDefaultTypefaceForFont()

Typeface::Ptr juce::Font::getDefaultTypefaceForFont | ( | const Font & | font | ) |

static

Returns the default system typeface for the given font.

Note: This will only ever return the typeface for the font's "main" family. Before attempting to render glyphs from this typeface, it's a good idea to check that those glyphs are present in the typeface, and to select a different face if necessary.

References Font(), and getDefaultTypefaceForFont().

Referenced by getDefaultTypefaceForFont().

## withHeight()

Font juce::Font::withHeight | ( | float | height | ) | const

nodiscard

Returns a copy of this font with a new height.

References Font(), and withHeight().

Referenced by withHeight().

## withPointHeight()

Font juce::Font::withPointHeight | ( | float | heightInPoints | ) | const

nodiscard

Returns a copy of this font with a new height, specified in points.

References Font(), and withPointHeight().

Referenced by withPointHeight().

## setHeight()

void juce::Font::setHeight | ( | float | newHeight | ) |

Changes the font's height.

The font will be scaled so that the sum of the ascender and descender is equal to the provided height in logical pixels.

See also
  setPointHeight, getHeight, withHeight, setHeightWithoutChangingWidth

References setHeight().

Referenced by setHeight().

## setPointHeight()

void juce::Font::setPointHeight | ( | float | newHeight | ) |

Changes the font's height.

The argument specifies the size of the font's em-square in logical pixels.

See also
  setHeight, getHeight, withHeight, setHeightWithoutChangingWidth

References setPointHeight().

Referenced by setPointHeight().

## setHeightWithoutChangingWidth()

void juce::Font::setHeightWithoutChangingWidth | ( | float | newHeight | ) |

Changes the font's height without changing its width.

This alters the horizontal scale to compensate for the change in height.

References setHeightWithoutChangingWidth().

Referenced by setHeightWithoutChangingWidth().

## getHeight()

float juce::Font::getHeight | ( |  | ) | const

noexcept

Returns the total height of this font, in pixels.

This is the maximum height, from the top of the ascent to the bottom of the descenders.

There can be a notable exception to this rule however, if you use the ascent/descent override feature. This feature follows CSS semantics and acts on the point height of the Font. So if you specified the font's height using setHeight() and also specified an ascent or descent override, then the visually rendered height of the Font can be different from the value returned by getHeight().

See also
  withHeight, setHeightWithoutChangingWidth, getAscent, setAscentOverride

References getHeight().

Referenced by getHeight().

## getHeightInPoints()

float juce::Font::getHeightInPoints | ( |  | ) | const

Returns the total height of this font, in points.

This is the maximum height, from the top of the ascent to the bottom of the descenders.

This value is not affected by the optional ascent or descent override.

See also
  withPointHeight, getHeight

References getHeightInPoints().

Referenced by getHeightInPoints().

## getAscent()

float juce::Font::getAscent | ( |  | ) | const

Returns the height of the font above its baseline, in pixels.

This is the maximum height from the baseline to the top.

See also
  getHeight, getDescent

References getAscent().

Referenced by getAscent().

## getAscentInPoints()

float juce::Font::getAscentInPoints | ( |  | ) | const

Returns the height of the font above its baseline, in points.

This is the maximum height from the baseline to the top.

This value is affected by the optional ascent override.

See also
  getAscentOverride, getHeightInPoints, getDescentInPoints

References getAscentInPoints().

Referenced by getAscentInPoints().

## getDescent()

float juce::Font::getDescent | ( |  | ) | const

Returns the amount that the font descends below its baseline, in pixels.

This is calculated as (getHeight() - getAscent()).

See also
  getAscent, getHeight

References getDescent().

Referenced by getDescent().

## getDescentInPoints()

float juce::Font::getDescentInPoints | ( |  | ) | const

Returns the amount that the font descends below its baseline, in points.

This is calculated as (getHeight() - getAscent()).

This value is affected by the optional descent override.

See also
  getDescentOverride, getHeightInPoints, getAscentInPoints

References getDescentInPoints().

Referenced by getDescentInPoints().

## getStyleFlags()

int juce::Font::getStyleFlags | ( |  | ) | const

noexcept

Returns the font's style flags.

This will return a bitwise-or'ed combination of values from the FontStyleFlags enum, to describe whether the font is bold, italic, etc.

See also
  FontStyleFlags, withStyle

References getStyleFlags().

Referenced by getStyleFlags().

## withStyle()

Font juce::Font::withStyle | ( | int | styleFlags | ) | const

nodiscard

Returns a copy of this font with the given set of style flags.

Parameters

  styleFlags | a bitwise-or'ed combination of values from the FontStyleFlags enum.

See also
  FontStyleFlags, getStyleFlags

References Font(), and withStyle().

Referenced by withStyle().

## setStyleFlags()

void juce::Font::setStyleFlags | ( | int | newFlags | ) |

Changes the font's style.

Parameters

  newFlags | a bitwise-or'ed combination of values from the FontStyleFlags enum.

See also
  FontStyleFlags, withStyle

References setStyleFlags().

Referenced by setStyleFlags().

## setBold()

void juce::Font::setBold | ( | bool | shouldBeBold | ) |

Makes the font bold or non-bold.

References setBold().

Referenced by setBold().

## boldened()

Font juce::Font::boldened | ( |  | ) | const

nodiscard

Returns a copy of this font with the bold attribute set.

If the font does not have a bold version, this will return the default font.

References boldened(), and Font().

Referenced by boldened().

## isBold()

bool juce::Font::isBold | ( |  | ) | const

noexcept

Returns true if the font is bold.

References isBold().

Referenced by isBold().

## setItalic()

void juce::Font::setItalic | ( | bool | shouldBeItalic | ) |

Makes the font italic or non-italic.

References setItalic().

Referenced by setItalic().

## italicised()

Font juce::Font::italicised | ( |  | ) | const

nodiscard

Returns a copy of this font with the italic attribute set.

References Font(), and italicised().

Referenced by italicised().

## isItalic()

bool juce::Font::isItalic | ( |  | ) | const

noexcept

Returns true if the font is italic.

References isItalic().

Referenced by isItalic().

## setUnderline()

void juce::Font::setUnderline | ( | bool | shouldBeUnderlined | ) |

Makes the font underlined or non-underlined.

References setUnderline().

Referenced by setUnderline().

## isUnderlined()

bool juce::Font::isUnderlined | ( |  | ) | const

noexcept

Returns true if the font is underlined.

References isUnderlined().

Referenced by isUnderlined().

## getMetricsKind()

TypefaceMetricsKind juce::Font::getMetricsKind | ( |  | ) | const

noexcept

Returns the kind of metrics used by this Font.

References getMetricsKind().

Referenced by getMetricsKind().

## getFeatureSettings() [1/2]

Span< const FontFeatureSetting > juce::Font::getFeatureSettings | ( |  | ) | const &

Returns an Span view of the features configured for this font instance.

Use Typeface::getSupportedFeatures() to determine what features this font supports.

See also
  setFeatureEnabled, setFeatureDisabled, removeFeature, Typeface::getSupportedFeatures

References getFeatureSettings().

Referenced by getFeatureSettings(), and getFeatureSettings().

## getFeatureSettings() [2/2]

Span< const FontFeatureSetting > juce::Font::getFeatureSettings | ( |  | ) | const &&

delete

References getFeatureSettings().

## setFeatureSetting()

void juce::Font::setFeatureSetting | ( | FontFeatureSetting | featureSetting | ) |

Enables or disables a font feature.

Use Typeface::getSupportedFeatures() to determine what features this font supports.

See also
  setFeatureEnabled, setFeatureDisabled, removeFeature, Typeface::getSupportedFeatures

References setFeatureSetting().

Referenced by setFeatureSetting().

## removeFeatureSetting()

void juce::Font::removeFeatureSetting | ( | FontFeatureTag | featureToRemove | ) |

Removes a specific feature setting from this font.

If featureToRemove corresponds to a feature that is typically enabled by default (e.g., "calt" for contextual alternates, "liga" for standard ligatures), calling this method will reset it to its default-enabled state.

See also
  setFeatureEnabled, setFeatureDisabled, Typeface::getSupportedFeatures

References removeFeatureSetting().

Referenced by removeFeatureSetting().

## getHorizontalScale()

float juce::Font::getHorizontalScale | ( |  | ) | const

noexcept

Returns the font's horizontal scale.

A value of 1.0 is the normal scale, less than this will be narrower, greater than 1.0 will be stretched out.

See also
  withHorizontalScale

References getHorizontalScale().

Referenced by getHorizontalScale().

## withHorizontalScale()

Font juce::Font::withHorizontalScale | ( | float | scaleFactor | ) | const

nodiscard

Returns a copy of this font with a new horizontal scale.

Parameters

  scaleFactor | a value of 1.0 is the normal scale, less than this will be narrower, greater than 1.0 will be stretched out.

See also
  getHorizontalScale

References Font(), and withHorizontalScale().

Referenced by withHorizontalScale().

## setHorizontalScale()

void juce::Font::setHorizontalScale | ( | float | scaleFactor | ) |

Changes the font's horizontal scale factor.

Parameters

  scaleFactor | a value of 1.0 is the normal scale, less than this will be narrower, greater than 1.0 will be stretched out.

References setHorizontalScale().

Referenced by setHorizontalScale().

## getDefaultMinimumHorizontalScaleFactor()

float juce::Font::getDefaultMinimumHorizontalScaleFactor | ( |  | ) |

static noexcept

Returns the minimum horizontal scale to which fonts may be squashed when trying to create a layout.

See also
  setDefaultMinimumHorizontalScaleFactor

References getDefaultMinimumHorizontalScaleFactor().

Referenced by getDefaultMinimumHorizontalScaleFactor().

## setDefaultMinimumHorizontalScaleFactor()

void juce::Font::setDefaultMinimumHorizontalScaleFactor | ( | float | newMinimumScaleFactor | ) |

static noexcept

Sets the minimum horizontal scale to which fonts may be squashed when trying to create a text layout.

See also
  getDefaultMinimumHorizontalScaleFactor

References setDefaultMinimumHorizontalScaleFactor().

Referenced by setDefaultMinimumHorizontalScaleFactor().

## getExtraKerningFactor()

float juce::Font::getExtraKerningFactor | ( |  | ) | const

noexcept

Returns the font's tracking, i.e.

spacing applied between characters in addition to the kerning defined by the font.

This is the extra space added between adjacent characters, as a proportion of the font's height.

A value of zero is normal spacing, positive values will spread the letters out more, and negative values make them closer together.

References getExtraKerningFactor().

Referenced by getExtraKerningFactor().

## withExtraKerningFactor()

Font juce::Font::withExtraKerningFactor | ( | float | extraKerning | ) | const

nodiscard

Returns a copy of this font with a new tracking factor.

Parameters

  extraKerning | a multiple of the font's height that will be added to space between the characters. So a value of zero is normal spacing, positive values spread the letters out, negative values make them closer together.

References Font(), and withExtraKerningFactor().

Referenced by withExtraKerningFactor().

## setExtraKerningFactor()

void juce::Font::setExtraKerningFactor | ( | float | extraKerning | ) |

Changes the font's tracking.

Parameters

  extraKerning | a multiple of the font's height that will be added to space between the characters. So a value of zero is normal spacing, positive values spread the letters out, negative values make them closer together.

References setExtraKerningFactor().

Referenced by setExtraKerningFactor().

## getAscentOverride()

std::optional< float > juce::Font::getAscentOverride | ( |  | ) | const

noexcept

See also
  setAscentOverride()

References getAscentOverride().

Referenced by getAscentOverride().

## setAscentOverride()

void juce::Font::setAscentOverride | ( | std::optional< float > |  | ) |

This is designed to mirror CSS's ascent-override property.

When the font size is specified in points (using setPointHeight(), FontOptions::withPointHeight(), etc.), then the font's ascent value in points will be equal to the font's size in points multiplied by the override value. That is, if the font size is 14pt and the ascent override is 0.5f, then the ascent will be 7pt.

When the font size is not specified in points (using setHeight(), FontOptions::withHeight(), etc.), then the behaviour is more subtle. The ascent override still specifies the size of the font's ascender as a proportion of the font's em size. However, the point size of the font is now found by multiplying the JUCE height by the height-to-point factor, where this factor is equal to (1.0f / (ascent-in-em-units + descent-in-em-units)). As an example, if the JUCE font height is 14, the ascent override is 0.5f, and the descent override is 0.5f, then the font size will be 14pt and the ascent will be 7pt. Changing the ascent override to 1.0f and the descent override to 0.0f will preserve the font size of 14pt but give an ascender of 14pt and a descender of 0pt. Changing the ascent and descent overrides both to 1.0f will result in the font's size changing to 7pt with an ascent of 3.5pt.

See also
  setDescentOverride()

References setAscentOverride().

Referenced by setAscentOverride().

## getDescentOverride()

std::optional< float > juce::Font::getDescentOverride | ( |  | ) | const

noexcept

See also
  setDescentOverride()

References getDescentOverride().

Referenced by getDescentOverride().

## setDescentOverride()

void juce::Font::setDescentOverride | ( | std::optional< float > |  | ) |

This is designed to mirror CSS's descent-override property.

Specifies a value to replace the built-in typeface descent metric. The final descent value will be found by multiplying the provided value by the font size. You may also pass std::nullopt to use the descent value specified in the typeface.

The documentation for setAscentOverride() includes a more thorough discussion of the mechanism used for overriding.

See also
  setAscentOverride()

References setDescentOverride().

Referenced by setDescentOverride().

## setSizeAndStyle() [1/2]

void juce::Font::setSizeAndStyle | ( | float | newHeight,
|  | int | newStyleFlags,
|  | float | newHorizontalScale,
|  | float | newKerningAmount )

Changes all the font's characteristics with one call.

References setSizeAndStyle().

Referenced by setSizeAndStyle(), and setSizeAndStyle().

## setSizeAndStyle() [2/2]

void juce::Font::setSizeAndStyle | ( | float | newHeight,
|  | const String & | newStyle,
|  | float | newHorizontalScale,
|  | float | newKerningAmount )

Changes all the font's characteristics with one call.

References setSizeAndStyle().

## getStringWidth()

int juce::Font::getStringWidth | ( | const String & | text | ) | const

Returns the total width of a string as it would be drawn using this font.

For a more accurate floating-point result, use getStringWidthFloat().

This function does not take font fallback into account. If this font doesn't include glyphs to represent all characters in the string, then the width will be computed as though those characters were replaced with the "glyph not found" character.

If you are trying to find the amount of space required to display a given string, you'll get more accurate results by actually measuring the results of whichever text layout engine (e.g. GlyphArrangement, TextLayout) you'll use when displaying the string.

See also
  TextLayout::getStringWidth(), GlyphArrangement::getStringWidthInt()

References getStringWidth().

Referenced by getStringWidth().

## getStringWidthFloat()

float juce::Font::getStringWidthFloat | ( | const String & | text | ) | const

Returns the total width of a string as it would be drawn using this font.

See also
  getStringWidth

This function does not take font fallback into account. If this font doesn't include glyphs to represent all characters in the string, then the width will be computed as though those characters were replaced with the "glyph not found" character.

If you are trying to find the amount of space required to display a given string, you'll get more accurate results by actually measuring the results of whichever text layout engine (e.g. GlyphArrangement, TextLayout) you'll use when displaying the string.

See also
  TextLayout::getStringWidth(), GlyphArrangement::getStringWidth()

References getStringWidthFloat().

Referenced by getStringWidthFloat().

## getTypefacePtr()

Typeface::Ptr juce::Font::getTypefacePtr | ( |  | ) | const

Returns the main typeface used by this font.

Note: This will only ever return the typeface for the "main" family. Before attempting to render glyphs from this typeface, it's a good idea to check that those glyphs are present in the typeface, and to select a different face if necessary.

References getTypefacePtr().

Referenced by getTypefacePtr().

## findFonts()

void juce::Font::findFonts | ( | Array< Font > & | results | ) |

static

Creates an array of Font objects to represent all the fonts on the system.

If you just need the font family names of the typefaces, you can also use findAllTypefaceNames() instead.

Parameters

  results | the array to which new Font objects will be added.

References findFonts(), and Font().

Referenced by findFonts().

## findAllTypefaceNames()

StringArray juce::Font::findAllTypefaceNames | ( |  | ) |

static

Returns a list of all the available typeface font families.

The names returned can be passed into setTypefaceName().

You can use this instead of findFonts() if you only need their font family names, and not font objects.

References findAllTypefaceNames().

Referenced by findAllTypefaceNames().

## findAllTypefaceStyles()

StringArray juce::Font::findAllTypefaceStyles | ( | const String & | family | ) |

static

Returns a list of all the available typeface font styles.

The names returned can be passed into setTypefaceStyle().

You can use this instead of findFonts() if you only need their styles, and not font objects.

References findAllTypefaceStyles().

Referenced by findAllTypefaceStyles().

## findSuitableFontForText()

Font juce::Font::findSuitableFontForText | ( | const String & | text,
|  | const String & | language = {} ) const

Attempts to locate a visually similar font that is capable of rendering the provided string.

If fallback is disabled on this Font by setFallbackEnabled(), then this will always return a copy of the current Font.

Otherwise, the current font, then each of the fallback fonts specified by setPreferredFallbackFamilies() will be checked, and the first Font that is capable of rendering the string will be returned. If none of these fonts is suitable, then the system font fallback mechanism will be used to locate a font from the currently installed fonts. If the system also cannot find any suitable font, then a copy of the original Font will be returned.

Note that most fonts don't contain glyphs for all possible unicode codepoints, and instead may contain e.g. just the glyphs required for a specific script. So, if the provided text would be displayed using several scripts (multiple languages, emoji, etc.) then there's a good chance that no single font will be able to render the entire text. Shorter strings will generally produce better fallback results than longer strings, with the caveat that the system may take control characters such as combining marks and variation selectors into account when selecting suitable fonts, so querying fallbacks character-by-character is likely to produce poor results.

References findSuitableFontForText(), and Font().

Referenced by findSuitableFontForText().

## toString()

String juce::Font::toString | ( |  | ) | const

Creates a string to describe this font.

The string will contain information to describe the font's typeface, size, and style. To recreate the font from this string, use fromString().

## fromString()

Font juce::Font::fromString | ( | const String & | fontDescription | ) |

static

Recreates a font from its stringified encoding.

This method takes a string that was created by toString(), and recreates the original font.

References Font().

## getNativeDetails()

Native juce::Font::getNativeDetails | ( |  | ) | const

## getHeightToPointsFactor()

float juce::Font::getHeightToPointsFactor | ( |  | ) | const

References Font().

### Purchase

Get JUCE

### Discover

What's New in JUCE Features

### Learn

Documentaion Tutorials Made with JUCE Resources

### Support

JUCE Forum Newsletter Archive

### About

Contact Us JUCE Legal JUCE Licensing FAQ

### Events

Audio Developer Conference
© Raw Material Software Limited