NAP
Public Member Functions | Protected Member Functions | List of all members
FontInstance Class Referencefinal

#include <font.h>

Public Member Functions

 FontInstance (FontService &service)
 
 ~FontInstance ()
 
 FontInstance (const FontInstance &rhs)=delete
 
FontInstanceoperator= (const FontInstance &rhs)=delete
 
bool create (const std::string &font, FontProperties &properties, utility::ErrorState &error)
 
const FontPropertiesgetProperties () const
 
const std::string & getFont () const
 
bool isValid () const
 
nap::uint getGlyphIndex (nap::uint character) const
 
template<typename T >
T * getOrCreateGlyphRepresentation (nap::uint index, float scale, utility::ErrorState &errorCode)
 
IGlyphRepresentationgetOrCreateGlyphRepresentation (nap::uint index, float scale, const rtti::TypeInfo &type, utility::ErrorState &errorCode)
 
const GlyphgetOrCreateGlyph (nap::uint index, float scale, utility::ErrorState &errorCode)
 
void getBoundingBox (const std::string &text, float scale, math::Rect &outRect)
 
int getCount ()
 

Protected Member Functions

void * getFace () const
 

Description

Runtime version of a font that serves characters. Internally the font caches all the requested characters and visualization modes. A character is called a Glyph and a character visualization mode is a GlyphRepresentation. The instance is created by a Font on initialization. Use the getGlyphIndex() and getOrCreateGlyph() functions to fetch characters. All the characters (glyphs) are managed and therefore owned by this font. It is possible to create a font instance dynamically at run-time.

Constructor & Destructor Documentation

◆ FontInstance() [1/2]

FontInstance ( FontService service)

Create the instance based on font properties and a service

◆ ~FontInstance()

Destructor

◆ FontInstance() [2/2]

FontInstance ( const FontInstance rhs)
delete

Font can't be copied!

Member Function Documentation

◆ create()

bool create ( const std::string &  font,
FontProperties properties,
utility::ErrorState error 
)

Creates the actual typeface associated with the font based on the incoming set of properties. Call this after construction or when you want to change the font at run-time. If for some reason construction fails the errorState holds the error code. The previous typeface, if it exists, is destroyed when a new one is created successfully. When creation fails the current typeface remains active.

Parameters
fontthe font file to load.
propertiesfont properties such as the size and resolution.
errorcontains the error message if construction of the typeface fails
Returns
if the typeface could be constructed

◆ getBoundingBox()

void getBoundingBox ( const std::string &  text,
float  scale,
math::Rect outRect 
)

Returns the bounding box in pixels associated with a string of text. This bounding box tightly wraps the text and excludes initial horizontal bearing All requested glyphs are cached internally.

Parameters
textthe string of characters to compute the bounding box for
scaleglyph scaling factor
outRectcontains the text bounds

◆ getCount()

int getCount ( )

Returns the number of glyphs in this font, -1 when the font hasn't been created yet

Returns
the number of glyphs associated with this font

◆ getFace()

void* getFace ( ) const
protected

Returns the handle to the free-type face managed by this resource Represents a FT_Face object

Returns
handle to the type face managed by this font

◆ getFont()

const std::string& getFont ( ) const
Returns
the name of the font file loaded from disk

◆ getGlyphIndex()

nap::uint getGlyphIndex ( nap::uint  character) const

Get the index of a Glyph inside this font based on a character code Use this index to get a handle to a Glyph using getOrCreateGlyph()

Parameters
characterthe character code, 0 when not identified

◆ getOrCreateGlyph()

const Glyph* getOrCreateGlyph ( nap::uint  index,
float  scale,
utility::ErrorState errorCode 
)

Returns a native Glyph object that can be represented using a Glyph Representation object. The Glyph is cached internally, to speed up future requests.

Parameters
indexthe index of the glyph inside the font.
scaleglyph scaling factor
errorCodecontains the error if the glyph could not be created or fetched
Returns
a Glyph Cache associated with a specific index of the font.

◆ getOrCreateGlyphRepresentation() [1/2]

IGlyphRepresentation* getOrCreateGlyphRepresentation ( nap::uint  index,
float  scale,
const rtti::TypeInfo type,
utility::ErrorState errorCode 
)

Use this to acquire a handle to a glyph representation, associated with a character at that index. The object can't be copied and is owned by this font. When the Glyph isn't present it is created and initialized afterwards. Use getGlyphIndex() to find the index of a specific character. type must be of type IGlyphRepresentation, multiple representations of every character are allowed. This means that you can associate multiple Glyph representations with the same character index.

Parameters
indexthe index of the glyph inside the font.
scaleglyph scaling factor
typethe type of glyph representation to create.
errorCodecontains the error if the glyph could not be created or fetched.
Returns
a glyph associated with a specific character, nullptr if retrieval fails.

◆ getOrCreateGlyphRepresentation() [2/2]

T * getOrCreateGlyphRepresentation ( nap::uint  index,
float  scale,
utility::ErrorState errorCode 
)

Use this to acquire a handle to a glyph representation, associated with a character at that index. The object can't be copied and is owned by this font. When the Glyph isn't present it is created and initialized afterwards. Use getGlyphIndex() to find the index of a specific character. T must be of type IGlyphRepresentation, multiple representations of every character are allowed. This means that you can associate multiple Glyph representations with the same character index.

Parameters
indexthe index of the glyph inside the font.
scaleglyph scaling factor
errorCodecontains the error if the glyph could not be created or fetched
Returns
a glyph associated with a specific character, nullptr if retrieval fails.

◆ getProperties()

const FontProperties& getProperties ( ) const
Returns
up to date properties associated with this font

◆ isValid()

bool isValid ( ) const
Returns
if this instance hosts a valid typeface

◆ operator=()

FontInstance& operator= ( const FontInstance rhs)
delete