LMMS
Loading...
Searching...
No Matches
juce::CustomTypeface Class Reference

#include <juce_CustomTypeface.h>

Inheritance diagram for juce::CustomTypeface:
juce::Typeface juce::ReferenceCountedObject juce::FreeTypeTypeface

Classes

class  GlyphInfo

Public Member Functions

 CustomTypeface ()
 CustomTypeface (InputStream &serialisedTypefaceStream)
 ~CustomTypeface () override
void clear ()
void setCharacteristics (const String &fontFamily, float ascent, bool isBold, bool isItalic, juce_wchar defaultCharacter) noexcept
void setCharacteristics (const String &fontFamily, const String &fontStyle, float ascent, juce_wchar defaultCharacter) noexcept
void addGlyph (juce_wchar character, const Path &path, float width) noexcept
void addKerningPair (juce_wchar char1, juce_wchar char2, float extraAmount) noexcept
void addGlyphsFromOtherTypeface (Typeface &typefaceToCopy, juce_wchar characterStartIndex, int numCharacters) noexcept
bool writeToStream (OutputStream &outputStream)
float getAscent () const override
float getDescent () const override
float getHeightToPointsFactor () const override
float getStringWidth (const String &) override
void getGlyphPositions (const String &, Array< int > &glyphs, Array< float > &xOffsets) override
bool getOutlineForGlyph (int glyphNumber, Path &) override
EdgeTablegetEdgeTableForGlyph (int glyphNumber, const AffineTransform &, float fontHeight) override
Public Member Functions inherited from juce::Typeface
const StringgetName () const noexcept
const StringgetStyle () const noexcept
 ~Typeface () override
virtual bool isSuitableForFont (const Font &) const
virtual bool isHinted () const
void applyVerticalHintingTransform (float fontHeight, Path &path)
Public Member Functions inherited from juce::ReferenceCountedObject
void incReferenceCount () noexcept
void decReferenceCount () noexcept
bool decReferenceCountWithoutDeleting () noexcept
int getReferenceCount () const noexcept

Protected Member Functions

virtual bool loadGlyphIfPossible (juce_wchar characterNeeded)
Protected Member Functions inherited from juce::Typeface
 Typeface (const String &name, const String &style) noexcept
Protected Member Functions inherited from juce::ReferenceCountedObject
 ReferenceCountedObject ()=default
 ReferenceCountedObject (const ReferenceCountedObject &) noexcept
 ReferenceCountedObject (ReferenceCountedObject &&) noexcept
ReferenceCountedObjectoperator= (const ReferenceCountedObject &) noexcept
ReferenceCountedObjectoperator= (ReferenceCountedObject &&) noexcept
virtual ~ReferenceCountedObject ()
void resetReferenceCount () noexcept

Protected Attributes

juce_wchar defaultCharacter
float ascent
Protected Attributes inherited from juce::Typeface
String name
String style

Private Member Functions

GlyphInfofindGlyph (const juce_wchar character, bool loadIfNeeded) noexcept

Private Attributes

OwnedArray< GlyphInfoglyphs
short lookupTable [128]

Additional Inherited Members

Public Types inherited from juce::Typeface
using Ptr = ReferenceCountedObjectPtr<Typeface>
Static Public Member Functions inherited from juce::Typeface
static Ptr createSystemTypefaceFor (const Font &font)
static Ptr createSystemTypefaceFor (const void *fontFileData, size_t fontFileDataSize)
static void setTypefaceCacheSize (int numFontsToCache)
static void clearTypefaceCache ()
static void scanFolderForFonts (const File &folder)
Static Protected Member Functions inherited from juce::Typeface
static Ptr getFallbackTypeface ()

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

@tags{Graphics}

Constructor & Destructor Documentation

◆ CustomTypeface() [1/2]

juce::CustomTypeface::CustomTypeface ( )

Creates a new, empty typeface.

◆ CustomTypeface() [2/2]

juce::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()

juce::CustomTypeface::~CustomTypeface ( )
override

Destructor.

Member Function Documentation

◆ addGlyph()

void juce::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 juce::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 juce::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.

◆ clear()

void juce::CustomTypeface::clear ( )

Resets this typeface, deleting all its glyphs and settings.

◆ findGlyph()

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

◆ getAscent()

float juce::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 juce::Typeface.

◆ getDescent()

float juce::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 juce::Typeface.

◆ getEdgeTableForGlyph()

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

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

Reimplemented from juce::Typeface.

◆ getGlyphPositions()

void juce::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 juce::Typeface.

◆ getHeightToPointsFactor()

float juce::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 juce::Typeface.

◆ getOutlineForGlyph()

bool juce::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 juce::Typeface.

◆ getStringWidth()

float juce::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 juce::Typeface.

◆ loadGlyphIfPossible()

bool juce::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.

Reimplemented in juce::FreeTypeTypeface.

◆ setCharacteristics() [1/2]

void juce::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

◆ setCharacteristics() [2/2]

void juce::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

◆ writeToStream()

bool juce::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.

Member Data Documentation

◆ ascent

float juce::CustomTypeface::ascent
protected

◆ defaultCharacter

juce_wchar juce::CustomTypeface::defaultCharacter
protected

◆ glyphs

OwnedArray<GlyphInfo> juce::CustomTypeface::glyphs
private

◆ lookupTable

short juce::CustomTypeface::lookupTable[128]
private

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