JUCE
Public Types | Public Member Functions | Static Public Member Functions | Protected Member Functions | Static Protected Member Functions | Protected Attributes | List of all members
Typeface Class Referenceabstract

A typeface represents a size-independent font. More...

Inheritance diagram for Typeface:

Public Types

using Ptr = ReferenceCountedObjectPtr< Typeface >
 A handy typedef for a pointer to a typeface. More...
 

Public Member Functions

const StringgetName () const noexcept
 Returns the font family of the typeface. More...
 
const StringgetStyle () const noexcept
 Returns the font style of the typeface. More...
 
 ~Typeface () override
 Destructor. More...
 
virtual bool isSuitableForFont (const Font &) const
 Returns true if this typeface can be used to render the specified font. More...
 
virtual float getAscent () const =0
 Returns the ascent of the font, as a proportion of its height. More...
 
virtual float getDescent () const =0
 Returns the descent of the font, as a proportion of its height. More...
 
virtual float getHeightToPointsFactor () const =0
 Returns the value by which you should multiply a JUCE font-height value to convert it to the equivalent point-size. More...
 
virtual float getStringWidth (const String &text)=0
 Measures the width of a line of text. More...
 
virtual void getGlyphPositions (const String &text, Array< int > &glyphs, Array< float > &xOffsets)=0
 Converts a line of text into its glyph numbers and their positions. More...
 
virtual bool getOutlineForGlyph (int glyphNumber, Path &path)=0
 Returns the outline for a glyph. More...
 
virtual EdgeTablegetEdgeTableForGlyph (int glyphNumber, const AffineTransform &transform, float fontHeight)
 Returns a new EdgeTable that contains the path for the given glyph, with the specified transform applied. More...
 
virtual bool isHinted () const
 Returns true if the typeface uses hinting. 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...
 
- Public Member Functions inherited from ReferenceCountedObject
void incReferenceCount () noexcept
 Increments the object's reference count. More...
 
void decReferenceCount () noexcept
 Decreases the object's reference count. More...
 
bool decReferenceCountWithoutDeleting () noexcept
 Decreases the object's reference count. More...
 
int getReferenceCount () const noexcept
 Returns the object's current reference count. More...
 

Static Public Member Functions

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 setTypefaceCacheSize (int numFontsToCache)
 Changes the number of fonts that are cached in memory. More...
 
static void clearTypefaceCache ()
 Clears any fonts that are currently cached in memory. More...
 
static void scanFolderForFonts (const File &folder)
 On some platforms, this allows a specific path to be scanned. More...
 

Protected Member Functions

 Typeface (const String &name, const String &style) noexcept
 
- Protected Member Functions inherited from ReferenceCountedObject
 ReferenceCountedObject ()=default
 Creates the reference-counted object (with an initial ref count of zero). More...
 
 ReferenceCountedObject (const ReferenceCountedObject &) noexcept
 Copying from another object does not affect this one's reference-count. More...
 
 ReferenceCountedObject (ReferenceCountedObject &&) noexcept
 Copying from another object does not affect this one's reference-count. More...
 
ReferenceCountedObjectoperator= (const ReferenceCountedObject &) noexcept
 Copying from another object does not affect this one's reference-count. More...
 
ReferenceCountedObjectoperator= (ReferenceCountedObject &&) noexcept
 Copying from another object does not affect this one's reference-count. More...
 
virtual ~ReferenceCountedObject ()
 Destructor. More...
 
void resetReferenceCount () noexcept
 Resets the reference count to zero without deleting the object. More...
 

Static Protected Member Functions

static Ptr getFallbackTypeface ()
 

Protected Attributes

String name
 
String style
 

Detailed Description

A typeface represents a size-independent font.

This base class is abstract, but calling createSystemTypefaceFor() will return a platform-specific subclass that can be used.

The CustomTypeface subclass allow you to build your own typeface, and to load and save it in the JUCE typeface format.

Normally you should never need to deal directly with Typeface objects - the Font class does everything you typically need for rendering text.

See also
CustomTypeface, Font

Member Typedef Documentation

◆ Ptr

A handy typedef for a pointer to a typeface.

Constructor & Destructor Documentation

◆ ~Typeface()

Typeface::~Typeface ( )
override

Destructor.

◆ Typeface()

Typeface::Typeface ( const String name,
const String style 
)
protectednoexcept

Member Function Documentation

◆ getName()

const String& Typeface::getName ( ) const
noexcept

Returns the font family of the typeface.

See also
Font::getTypefaceName

◆ getStyle()

const String& Typeface::getStyle ( ) const
noexcept

Returns the font style of the typeface.

See also
Font::getTypefaceStyle

◆ createSystemTypefaceFor() [1/2]

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

Creates a new system typeface.

◆ createSystemTypefaceFor() [2/2]

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

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.

◆ isSuitableForFont()

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

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.

◆ getAscent()

virtual float Typeface::getAscent ( ) const
pure virtual

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.

Implemented in CustomTypeface.

◆ getDescent()

virtual float Typeface::getDescent ( ) const
pure virtual

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.

Implemented in CustomTypeface.

◆ getHeightToPointsFactor()

virtual float Typeface::getHeightToPointsFactor ( ) const
pure virtual

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

Implemented in CustomTypeface.

◆ getStringWidth()

virtual float Typeface::getStringWidth ( const String text)
pure virtual

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!

Implemented in CustomTypeface.

◆ getGlyphPositions()

virtual void Typeface::getGlyphPositions ( const String text,
Array< int > &  glyphs,
Array< float > &  xOffsets 
)
pure virtual

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!

Implemented in CustomTypeface.

◆ getOutlineForGlyph()

virtual bool Typeface::getOutlineForGlyph ( int  glyphNumber,
Path path 
)
pure virtual

Returns the outline for a glyph.

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

Implemented in CustomTypeface.

◆ getEdgeTableForGlyph()

virtual EdgeTable* Typeface::getEdgeTableForGlyph ( int  glyphNumber,
const AffineTransform transform,
float  fontHeight 
)
virtual

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

Reimplemented in CustomTypeface.

◆ isHinted()

virtual bool Typeface::isHinted ( ) const
virtual

Returns true if the typeface uses hinting.

◆ setTypefaceCacheSize()

static void Typeface::setTypefaceCacheSize ( int  numFontsToCache)
static

Changes the number of fonts that are cached in memory.

◆ clearTypefaceCache()

static void Typeface::clearTypefaceCache ( )
static

Clears any fonts that are currently cached in memory.

◆ scanFolderForFonts()

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

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

On macOS you can load .ttf and .otf files, otherwise this is only available when using FreeType.

◆ applyVerticalHintingTransform()

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

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

◆ getFallbackTypeface()

static Ptr Typeface::getFallbackTypeface ( )
staticprotected

Member Data Documentation

◆ name

String Typeface::name
protected

◆ style

String Typeface::style
protected

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