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

#include <juce_Font.h>

Classes

class  SharedFontInternal

Public Types

enum  FontStyleFlags { plain = 0 , bold = 1 , italic = 2 , underlined = 4 }

Public Member Functions

 Font (float fontHeight, int styleFlags=plain)
 Font (const String &typefaceName, float fontHeight, int styleFlags)
 Font (const String &typefaceName, const String &typefaceStyle, float fontHeight)
 Font (const Font &other) noexcept
 Font (const Typeface::Ptr &typeface)
 Font ()
 Font (Font &&other) noexcept
Fontoperator= (Font &&other) noexcept
Fontoperator= (const Font &other) noexcept
bool operator== (const Font &other) const noexcept
bool operator!= (const Font &other) const noexcept
 ~Font () noexcept
void setTypefaceName (const String &faceName)
String getTypefaceName () const noexcept
String getTypefaceStyle () const noexcept
void setTypefaceStyle (const String &newStyle)
JUCE_NODISCARD Font withTypefaceStyle (const String &newStyle) const
StringArray getAvailableStyles () const
JUCE_NODISCARD Font withHeight (float height) const
JUCE_NODISCARD Font withPointHeight (float heightInPoints) const
void setHeight (float newHeight)
void setHeightWithoutChangingWidth (float newHeight)
float getHeight () const noexcept
float getHeightInPoints () const
float getAscent () const
float getAscentInPoints () const
float getDescent () const
float getDescentInPoints () const
int getStyleFlags () const noexcept
JUCE_NODISCARD Font withStyle (int styleFlags) const
void setStyleFlags (int newFlags)
void setBold (bool shouldBeBold)
JUCE_NODISCARD Font boldened () const
bool isBold () const noexcept
void setItalic (bool shouldBeItalic)
JUCE_NODISCARD Font italicised () const
bool isItalic () const noexcept
void setUnderline (bool shouldBeUnderlined)
bool isUnderlined () const noexcept
float getHorizontalScale () const noexcept
JUCE_NODISCARD Font withHorizontalScale (float scaleFactor) const
void setHorizontalScale (float scaleFactor)
float getExtraKerningFactor () const noexcept
JUCE_NODISCARD Font withExtraKerningFactor (float extraKerning) const
void setExtraKerningFactor (float extraKerning)
void setSizeAndStyle (float newHeight, int newStyleFlags, float newHorizontalScale, float newKerningAmount)
void setSizeAndStyle (float newHeight, const String &newStyle, float newHorizontalScale, float newKerningAmount)
int getStringWidth (const String &text) const
float getStringWidthFloat (const String &text) const
void getGlyphPositions (const String &text, Array< int > &glyphs, Array< float > &xOffsets) const
TypefacegetTypeface () const
Typeface::Ptr getTypefacePtr () const
String toString () const

Static Public Member Functions

static const StringgetDefaultSansSerifFontName ()
static const StringgetDefaultSerifFontName ()
static const StringgetDefaultMonospacedFontName ()
static const StringgetDefaultStyle ()
static Typeface::Ptr getDefaultTypefaceForFont (const Font &font)
static float getDefaultMinimumHorizontalScaleFactor () noexcept
static void setDefaultMinimumHorizontalScaleFactor (float newMinimumScaleFactor) noexcept
static void findFonts (Array< Font > &results)
static StringArray findAllTypefaceNames ()
static StringArray findAllTypefaceStyles (const String &family)
static const StringgetFallbackFontName ()
static void setFallbackFontName (const String &name)
static const StringgetFallbackFontStyle ()
static void setFallbackFontStyle (const String &style)
static Font fromString (const String &fontDescription)

Private Member Functions

void dupeInternalIfShared ()
void checkTypefaceSuitability ()
float getHeightToPointsFactor () const

Static Private Member Functions

static bool compare (const Font &, const Font &) noexcept

Private Attributes

ReferenceCountedObjectPtr< SharedFontInternalfont

Friends

struct GraphicsFontHelpers

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

@tags{Graphics}

Member Enumeration Documentation

◆ 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

Constructor & Destructor Documentation

◆ Font() [1/7]

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

Creates a sans-serif font in a given size.

Parameters
fontHeightthe height in pixels (can be fractional)
styleFlagsthe 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() [2/7]

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

Creates a font with a given typeface and parameters.

Parameters
typefaceNamethe font family of the typeface to use
fontHeightthe height in pixels (can be fractional)
styleFlagsthe 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() [3/7]

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

Creates a font with a given typeface and parameters.

Parameters
typefaceNamethe font family of the typeface to use
typefaceStylethe font style of the typeface to use
fontHeightthe height in pixels (can be fractional)

◆ Font() [4/7]

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

Creates a copy of another Font object.

◆ Font() [5/7]

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

Creates a font for a typeface.

◆ Font() [6/7]

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/7]

juce::Font::Font ( Font && other)
noexcept

Move constructor

◆ ~Font()

juce::Font::~Font ( )
defaultnoexcept

Destructor.

Member Function Documentation

◆ boldened()

Font juce::Font::boldened ( ) const

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.

◆ checkTypefaceSuitability()

void juce::Font::checkTypefaceSuitability ( )
private

◆ compare()

bool juce::Font::compare ( const Font & a,
const Font & b )
staticprivatenoexcept

◆ dupeInternalIfShared()

void juce::Font::dupeInternalIfShared ( )
private

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

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

◆ 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
resultsthe array to which new Font objects will be added.

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

◆ 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

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

See also
getHeight, getDescent

◆ getAvailableStyles()

StringArray juce::Font::getAvailableStyles ( ) const

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

◆ getDefaultMinimumHorizontalScaleFactor()

float juce::Font::getDefaultMinimumHorizontalScaleFactor ( )
staticnoexcept

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

See also
setDefaultMinimumHorizontalScaleFactor

◆ 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

◆ 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

◆ 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

◆ 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

◆ getDefaultTypefaceForFont()

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

Returns the default system typeface for the given font.

◆ 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

◆ getDescentInPoints()

float juce::Font::getDescentInPoints ( ) const

Returns the amount that the font descends below its baseline, in points. This is calculated as (getHeight() - getAscent()).

See also
getAscent, getHeight

◆ getExtraKerningFactor()

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

Returns the font's kerning.

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.

◆ getFallbackFontName()

const String & juce::Font::getFallbackFontName ( )
static

Returns the font family of the typeface to be used for rendering glyphs that aren't found in the requested typeface.

◆ getFallbackFontStyle()

const String & juce::Font::getFallbackFontStyle ( )
static

Returns the font style of the typeface to be used for rendering glyphs that aren't found in the requested typeface.

◆ getGlyphPositions()

void juce::Font::getGlyphPositions ( const String & text,
Array< int > & glyphs,
Array< float > & xOffsets ) const

Returns the series of glyph numbers and their x offsets needed to represent a string.

An extra x offset is added at the end of the run, to indicate where the right hand edge of the last character is.

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

See also
withHeight, setHeightWithoutChangingWidth, getAscent

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

See also
withPointHeight, getHeight

◆ getHeightToPointsFactor()

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

◆ 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

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

◆ 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

◆ 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

◆ getTypeface()

Typeface * juce::Font::getTypeface ( ) const

Returns the typeface used by this font.

Note that the object returned may go out of scope if this font is deleted or has its style changed.

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

◆ getTypefacePtr()

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

Returns the typeface used by this font.

◆ getTypefaceStyle()

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

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

See also
withTypefaceStyle, getAvailableStyles()

◆ isBold()

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

Returns true if the font is bold.

◆ isItalic()

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

Returns true if the font is italic.

◆ isUnderlined()

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

Returns true if the font is underlined.

◆ italicised()

Font juce::Font::italicised ( ) const

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

◆ operator!=()

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

◆ operator=() [1/2]

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

Copies this font from another one.

◆ operator=() [2/2]

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

Move assignment operator

◆ operator==()

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

◆ setBold()

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

Makes the font bold or non-bold.

◆ setDefaultMinimumHorizontalScaleFactor()

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

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

See also
getDefaultMinimumHorizontalScaleFactor

◆ setExtraKerningFactor()

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

Changes the font's kerning.

Parameters
extraKerninga 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.

◆ setFallbackFontName()

void juce::Font::setFallbackFontName ( const String & name)
static

Sets the (platform-specific) font family of the typeface to use to find glyphs that aren't available in whatever font you're trying to use.

◆ setFallbackFontStyle()

void juce::Font::setFallbackFontStyle ( const String & style)
static

Sets the (platform-specific) font style of the typeface to use to find glyphs that aren't available in whatever font you're trying to use.

◆ setHeight()

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

Changes the font's height.

See also
getHeight, withHeight, setHeightWithoutChangingWidth

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

◆ setHorizontalScale()

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

Changes the font's horizontal scale factor.

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

◆ setItalic()

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

Makes the font italic or non-italic.

◆ setSizeAndStyle() [1/2]

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

Changes all the font's characteristics with one call.

◆ setSizeAndStyle() [2/2]

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

Changes all the font's characteristics with one call.

◆ setStyleFlags()

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

Changes the font's style.

Parameters
newFlagsa bitwise-or'ed combination of values from the FontStyleFlags enum.
See also
FontStyleFlags, withStyle

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

◆ setTypefaceStyle()

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

Changes the font style of the typeface.

See also
getAvailableStyles()

◆ setUnderline()

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

Makes the font underlined or non-underlined.

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

◆ withExtraKerningFactor()

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

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

Parameters
extraKerninga 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.

◆ withHeight()

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

Returns a copy of this font with a new height.

◆ withHorizontalScale()

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

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

Parameters
scaleFactora 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

◆ withPointHeight()

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

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

◆ withStyle()

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

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

Parameters
styleFlagsa bitwise-or'ed combination of values from the FontStyleFlags enum.
See also
FontStyleFlags, getStyleFlags

◆ withTypefaceStyle()

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

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

See also
getAvailableStyles()

◆ GraphicsFontHelpers

friend struct GraphicsFontHelpers
friend

Member Data Documentation

◆ font

ReferenceCountedObjectPtr<SharedFontInternal> juce::Font::font
private

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