JUCE  v5.1.1-3-g1a0b28c73
JUCE API
CustomTypeface Class Reference

A typeface that can be populated with custom glyphs. More...

#include <juce_CustomTypeface.h>

Inheritance diagram for CustomTypeface:
Collaboration diagram for CustomTypeface:

Public Types

typedef ReferenceCountedObjectPtr< TypefacePtr
 A handy typedef for a pointer to a typeface. More...
 

Public Member Functions

 CustomTypeface ()
 Creates a new, empty typeface. More...
 
 CustomTypeface (InputStream &serialisedTypefaceStream)
 Loads a typeface from a previously saved stream. More...
 
 ~CustomTypeface ()
 Destructor. More...
 
void addGlyph (juce_wchar character, const Path &path, float width) noexcept
 Adds a glyph to the typeface. More...
 
void addGlyphsFromOtherTypeface (Typeface &typefaceToCopy, juce_wchar characterStartIndex, int numCharacters) noexcept
 Adds a range of glyphs from another typeface. More...
 
void addKerningPair (juce_wchar char1, juce_wchar char2, float extraAmount) noexcept
 Specifies an extra kerning amount to be used between a pair of characters. More...
 
void applyVerticalHintingTransform (float fontHeight, Path &path)
 Makes an attempt at performing a good overall distortion that will scale a font of the given size to align vertically with the pixel grid. More...
 
void clear ()
 Resets this typeface, deleting all its glyphs and settings. More...
 
void decReferenceCount () noexcept
 Decreases the object's reference count. More...
 
bool decReferenceCountWithoutDeleting () noexcept
 Decreases the object's reference count. More...
 
float getAscent () const override
 Returns the ascent of the font, as a proportion of its height. More...
 
float getDescent () const override
 Returns the descent of the font, as a proportion of its height. More...
 
EdgeTablegetEdgeTableForGlyph (int glyphNumber, const AffineTransform &, float fontHeight) override
 Returns a new EdgeTable that contains the path for the givem glyph, with the specified transform applied. More...
 
void getGlyphPositions (const String &, Array< int > &glyphs, Array< float > &xOffsets) override
 Converts a line of text into its glyph numbers and their positions. More...
 
float getHeightToPointsFactor () const override
 Returns the value by which you should multiply a juce font-height value to convert it to the equivalent point-size. More...
 
const StringgetName () const noexcept
 Returns the font family of the typeface. More...
 
bool getOutlineForGlyph (int glyphNumber, Path &) override
 Returns the outline for a glyph. More...
 
int getReferenceCount () const noexcept
 Returns the object's current reference count. More...
 
float getStringWidth (const String &) override
 Measures the width of a line of text. More...
 
const StringgetStyle () const noexcept
 Returns the font style of the typeface. More...
 
void incReferenceCount () noexcept
 Increments the object's reference count. More...
 
virtual bool isHinted () const
 Returns true if the typeface uses hinting. More...
 
virtual bool isSuitableForFont (const Font &) const
 Returns true if this typeface can be used to render the specified font. More...
 
void setCharacteristics (const String &fontFamily, float ascent, bool isBold, bool isItalic, juce_wchar defaultCharacter) noexcept
 Sets the vital statistics for the typeface. More...
 
void setCharacteristics (const String &fontFamily, const String &fontStyle, float ascent, juce_wchar defaultCharacter) noexcept
 Sets the vital statistics for the typeface. More...
 
bool writeToStream (OutputStream &outputStream)
 Saves this typeface as a Juce-formatted font file. More...
 

Static Public Member Functions

static void clearTypefaceCache ()
 Clears any fonts that are currently cached in memory. More...
 
static Ptr createSystemTypefaceFor (const Font &font)
 Creates a new system typeface. More...
 
static Ptr createSystemTypefaceFor (const void *fontFileData, size_t fontFileDataSize)
 Attempts to create a font from some raw font file data (e.g. More...
 
static void scanFolderForFonts (const File &folder)
 On some platforms, this allows a specific path to be scanned. More...
 
static void setTypefaceCacheSize (int numFontsToCache)
 Changes the number of fonts that are cached in memory. More...
 

Protected Member Functions

virtual bool loadGlyphIfPossible (juce_wchar characterNeeded)
 If a subclass overrides this, it can load glyphs into the font on-demand. More...
 
void resetReferenceCount () noexcept
 Resets the reference count to zero without deleting the object. More...
 

Static Protected Member Functions

static Ptr getFallbackTypeface ()
 

Protected Attributes

float ascent
 
juce_wchar defaultCharacter
 
String name
 
String style
 

Private Member Functions

GlyphInfo * findGlyph (const juce_wchar character, bool loadIfNeeded) noexcept
 

Private Attributes

OwnedArray< GlyphInfo > glyphs
 
short lookupTable [128]
 

Friends

struct ContainerDeletePolicy< GlyphInfo >
 

Detailed Description

A typeface that can be populated with custom glyphs.

You can create a CustomTypeface if you need one that contains your own glyphs, or if you need to load a typeface from a Juce-formatted binary stream.

If you want to create a copy of a native face, you can use addGlyphsFromOtherTypeface() to copy glyphs into this face.

NOTE! For most people this class is almost certainly NOT the right tool to use! If what you want to do is to embed a font into your exe, then your best plan is probably to embed your TTF/OTF font file into your binary using the Projucer, and then call Typeface::createSystemTypefaceFor() to load it from memory.

See also
Typeface, Font

Member Typedef Documentation

◆ Ptr

A handy typedef for a pointer to a typeface.

Constructor & Destructor Documentation

◆ CustomTypeface() [1/2]

CustomTypeface::CustomTypeface ( )

Creates a new, empty typeface.

◆ CustomTypeface() [2/2]

CustomTypeface::CustomTypeface ( InputStream serialisedTypefaceStream)
explicit

Loads a typeface from a previously saved stream.

The stream must have been created by writeToStream().

NOTE! Since this class was written, support was added for loading real font files from memory, so for most people, using Typeface::createSystemTypefaceFor() to load a real font is more appropriate than using this class to store it in a proprietary format.

See also
writeToStream

◆ ~CustomTypeface()

CustomTypeface::~CustomTypeface ( )

Destructor.

Member Function Documentation

◆ addGlyph()

void CustomTypeface::addGlyph ( juce_wchar  character,
const Path path,
float  width 
)
noexcept

Adds a glyph to the typeface.

The path that is passed in is normalised so that the font height is 1.0, and its origin is the anchor point of the character on its baseline.

The width is the nominal width of the character, and any extra kerning values that are specified will be added to this width.

◆ addGlyphsFromOtherTypeface()

void CustomTypeface::addGlyphsFromOtherTypeface ( Typeface typefaceToCopy,
juce_wchar  characterStartIndex,
int  numCharacters 
)
noexcept

Adds a range of glyphs from another typeface.

This will attempt to pull in the paths and kerning information from another typeface and add it to this one.

◆ addKerningPair()

void CustomTypeface::addKerningPair ( juce_wchar  char1,
juce_wchar  char2,
float  extraAmount 
)
noexcept

Specifies an extra kerning amount to be used between a pair of characters.

The amount will be added to the nominal width of the first character when laying out a string.

◆ applyVerticalHintingTransform()

void Typeface::applyVerticalHintingTransform ( float  fontHeight,
Path path 
)
inherited

Makes an attempt at performing a good overall distortion that will scale a font of the given size to align vertically with the pixel grid.

The path should be an unscaled (i.e. normalised to height of 1.0) path for a glyph.

◆ clear()

void CustomTypeface::clear ( )

Resets this typeface, deleting all its glyphs and settings.

◆ clearTypefaceCache()

static void Typeface::clearTypefaceCache ( )
staticinherited

Clears any fonts that are currently cached in memory.

◆ createSystemTypefaceFor() [1/2]

static Ptr Typeface::createSystemTypefaceFor ( const Font font)
staticinherited

Creates a new system typeface.

◆ createSystemTypefaceFor() [2/2]

static Ptr Typeface::createSystemTypefaceFor ( const void *  fontFileData,
size_t  fontFileDataSize 
)
staticinherited

Attempts to create a font from some raw font file data (e.g.

a TTF or OTF file image). The system will take its own internal copy of the data, so you can free the block once this method has returned.

◆ decReferenceCount()

void ReferenceCountedObject::decReferenceCount ( )
inlinenoexceptinherited

Decreases the object's reference count.

If the count gets to zero, the object will be deleted.

References jassert.

◆ decReferenceCountWithoutDeleting()

bool ReferenceCountedObject::decReferenceCountWithoutDeleting ( )
inlinenoexceptinherited

Decreases the object's reference count.

If the count gets to zero, the object will not be deleted, but this method will return true, allowing the caller to take care of deletion.

References jassert.

◆ findGlyph()

GlyphInfo* CustomTypeface::findGlyph ( const juce_wchar  character,
bool  loadIfNeeded 
)
privatenoexcept

◆ getAscent()

float CustomTypeface::getAscent ( ) const
overridevirtual

Returns the ascent of the font, as a proportion of its height.

The height is considered to always be normalised as 1.0, so this will be a value less that 1.0, indicating the proportion of the font that lies above its baseline.

Implements Typeface.

◆ getDescent()

float CustomTypeface::getDescent ( ) const
overridevirtual

Returns the descent of the font, as a proportion of its height.

The height is considered to always be normalised as 1.0, so this will be a value less that 1.0, indicating the proportion of the font that lies below its baseline.

Implements Typeface.

◆ getEdgeTableForGlyph()

EdgeTable* CustomTypeface::getEdgeTableForGlyph ( int  glyphNumber,
const AffineTransform transform,
float  fontHeight 
)
overridevirtual

Returns a new EdgeTable that contains the path for the givem glyph, with the specified transform applied.

Reimplemented from Typeface.

◆ getFallbackTypeface()

static Ptr Typeface::getFallbackTypeface ( )
staticprotectedinherited

◆ getGlyphPositions()

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

Converts a line of text into its glyph numbers and their positions.

The distances returned are based on the font having an normalised height of 1.0. You should never need to call this directly! Use Font::getGlyphPositions() instead!

Implements Typeface.

◆ getHeightToPointsFactor()

float CustomTypeface::getHeightToPointsFactor ( ) const
overridevirtual

Returns the value by which you should multiply a juce font-height value to convert it to the equivalent point-size.

Implements Typeface.

◆ getName()

const String& Typeface::getName ( ) const
inlinenoexceptinherited

Returns the font family of the typeface.

See also
Font::getTypefaceName

◆ getOutlineForGlyph()

bool CustomTypeface::getOutlineForGlyph ( int  glyphNumber,
Path path 
)
overridevirtual

Returns the outline for a glyph.

The path returned will be normalised to a font height of 1.0.

Implements Typeface.

◆ getReferenceCount()

int ReferenceCountedObject::getReferenceCount ( ) const
inlinenoexceptinherited

Returns the object's current reference count.

◆ getStringWidth()

float CustomTypeface::getStringWidth ( const String text)
overridevirtual

Measures the width of a line of text.

The distance returned is based on the font having an normalised height of 1.0. You should never need to call this directly! Use Font::getStringWidth() instead!

Implements Typeface.

◆ getStyle()

const String& Typeface::getStyle ( ) const
inlinenoexceptinherited

Returns the font style of the typeface.

See also
Font::getTypefaceStyle

◆ incReferenceCount()

void ReferenceCountedObject::incReferenceCount ( )
inlinenoexceptinherited

Increments the object's reference count.

This is done automatically by the smart pointer, but is public just in case it's needed for nefarious purposes.

◆ isHinted()

virtual bool Typeface::isHinted ( ) const
inlinevirtualinherited

Returns true if the typeface uses hinting.

Referenced by RenderingHelpers::CachedGlyphEdgeTable< RendererType >::generate().

◆ isSuitableForFont()

virtual bool Typeface::isSuitableForFont ( const Font ) const
inlinevirtualinherited

Returns true if this typeface can be used to render the specified font.

When called, the font will already have been checked to make sure that its name and style flags match the typeface.

◆ loadGlyphIfPossible()

virtual bool CustomTypeface::loadGlyphIfPossible ( juce_wchar  characterNeeded)
protectedvirtual

If a subclass overrides this, it can load glyphs into the font on-demand.

When methods such as getGlyphPositions() or getOutlineForGlyph() are asked for a particular character and there's no corresponding glyph, they'll call this method so that a subclass can try to add that glyph, returning true if it manages to do so.

◆ resetReferenceCount()

void ReferenceCountedObject::resetReferenceCount ( )
inlineprotectednoexceptinherited

Resets the reference count to zero without deleting the object.

You should probably never need to use this!

◆ scanFolderForFonts()

static void Typeface::scanFolderForFonts ( const File folder)
staticinherited

On some platforms, this allows a specific path to be scanned.

Currently only available when using FreeType.

◆ setCharacteristics() [1/2]

void CustomTypeface::setCharacteristics ( const String fontFamily,
float  ascent,
bool  isBold,
bool  isItalic,
juce_wchar  defaultCharacter 
)
noexcept

Sets the vital statistics for the typeface.

Parameters
fontFamilythe typeface's font family
ascentthe ascent - this is normalised to a height of 1.0 and this is the value that will be returned by Typeface::getAscent(). The descent is assumed to be (1.0 - ascent)
isBoldshould be true if the typeface is bold
isItalicshould be true if the typeface is italic
defaultCharacterthe character to be used as a replacement if there's no glyph available for the character that's being drawn

◆ setCharacteristics() [2/2]

void CustomTypeface::setCharacteristics ( const String fontFamily,
const String fontStyle,
float  ascent,
juce_wchar  defaultCharacter 
)
noexcept

Sets the vital statistics for the typeface.

Parameters
fontFamilythe typeface's font family
fontStylethe typeface's font style
ascentthe ascent - this is normalised to a height of 1.0 and this is the value that will be returned by Typeface::getAscent(). The descent is assumed to be (1.0 - ascent)
defaultCharacterthe character to be used as a replacement if there's no glyph available for the character that's being drawn

◆ setTypefaceCacheSize()

static void Typeface::setTypefaceCacheSize ( int  numFontsToCache)
staticinherited

Changes the number of fonts that are cached in memory.

◆ writeToStream()

bool CustomTypeface::writeToStream ( OutputStream outputStream)

Saves this typeface as a Juce-formatted font file.

A CustomTypeface can be created to reload the data that is written - see the CustomTypeface constructor.

NOTE! Since this class was written, support was added for loading real font files from memory, so for most people, using Typeface::createSystemTypefaceFor() to load a real font is more appropriate than using this class to store it in a proprietary format.

Friends And Related Function Documentation

◆ ContainerDeletePolicy< GlyphInfo >

friend struct ContainerDeletePolicy< GlyphInfo >
friend

Member Data Documentation

◆ ascent

float CustomTypeface::ascent
protected

◆ defaultCharacter

juce_wchar CustomTypeface::defaultCharacter
protected

◆ glyphs

OwnedArray<GlyphInfo> CustomTypeface::glyphs
private

◆ lookupTable

short CustomTypeface::lookupTable[128]
private

◆ name

String Typeface::name
protectedinherited

◆ style

String Typeface::style
protectedinherited

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