nomlib
Loading...
Searching...
No Matches
nom::Font Class Reference

Font interface wrapper for nom::IFont derived objects. More...

#include <Font.hpp>

Public Types

typedef Font self_type
typedef IFont font_type

Public Member Functions

 Font ()
 Default constructor; initialize the font to NULL and the sharable state to false.
 ~Font ()
 Destructor.
 Font (const std::shared_ptr< font_type > &font)
 Constructor for initializing an object from a std::shared_ptr object<nom::IFont> object.
 Font (font_type *font)
 Constructor for initializing an object from a nom::IFont derived raw pointer.
font_type * operator-> () const
 Read-write pointer operator overload.
bool operator== (const self_type &rhs) const
 Equality comparison overload.
bool operator!= (const self_type &rhs) const
 In-equality comparison overload.
bool unique () const
 Get the object's unique state.
IFont::FontType type (const std::string &filename) const
 Determine the type of font by filename extension.
bool load (const std::string &filename)
 Load a font from a filename.

Private Attributes

std::shared_ptr< Font::font_type > font_

Detailed Description

Font interface wrapper for nom::IFont derived objects.

See also
nom::IFont, nom::BitmapFont, nom::TrueTypeFont, nom::BMFont

A class wrapper interface for a nom::IFont derived objects. This wrapper has the side intention of being conveniently used within a nom::ResourceCache (it does not support pure abstract objects, such as nom::IFont).

// Automatic initialization of an object; uses filename extension to
// determine the type of object to initialize / use:
nom::Font font;
if( font.load( file_path ) == false )
{
// Handle Err
}
if( font.valid() )
{
font.set_point_size( 24 );
}
// Manual initialization of an object (the old style used in the engine):
nom::Font font( std::shared_ptr<IFont>( new BitmapFont() );
// nom::Font font( std::shared_ptr<IFont>( new TrueTypeFont() );
if( font->load( file_path ) == false )
{
// Handle err
}
if( font->valid() )
{
font->set_point_size( 24 );
}
Font interface wrapper for nom::IFont derived objects.
Definition Font.hpp:41
bool load(const std::string &filename)
Load a font from a filename.
virtual bool load(const std::string &filename)=0

Definition at line 40 of file Font.hpp.

Member Typedef Documentation

◆ font_type

typedef IFont nom::Font::font_type

Definition at line 44 of file Font.hpp.

◆ self_type

typedef Font nom::Font::self_type

Definition at line 43 of file Font.hpp.

Member Function Documentation

◆ load()

bool nom::Font::load ( const std::string & filename)

Load a font from a filename.

Remarks
This is a convenience method provided for ease of access.
Note
If you bypass this method (not recommended), you must ensure that you have constructed the nom::Font object with a valid nom::IFont-derived object that has been loaded into memory with its appropriate ::load call. The nom::Font(font_type* font) constructor is used for the constructing call.
Todo
Rename to load_file

◆ operator!=()

bool nom::Font::operator!= ( const self_type & rhs) const

In-equality comparison overload.

Remarks
The comparison check is done only on the pointers to the stored font object – whether or not the objects point to the same memory location – not the actual data stored in the font (as this would be inefficient).

◆ operator->()

font_type * nom::Font::operator-> ( ) const

Read-write pointer operator overload.

Remarks
This method allows you to access the wrapped font object directly. This will be one of the nom::IFont object types.
See also
nom::BitmapFont, nom::TrueTypeFont.

◆ operator==()

bool nom::Font::operator== ( const self_type & rhs) const

Equality comparison overload.

Remarks
The comparison check is done only on the pointers to the stored font object – whether or not the objects point to the same memory location – not the actual data stored in the font (as this would be inefficient).

◆ type()

IFont::FontType nom::Font::type ( const std::string & filename) const

Determine the type of font by filename extension.

Parameters
filenameThe file name (absolute or relative) with the full extension. File extensions recognized are 'png', 'bmp', 'ttf', 'ttc' 'otf', 'ttf' and 'fnt'.
Returns
One of the IFont::FontType enumerations.
Remarks
This method is used by ::load in order to determine the type of font interface to initialize.

◆ unique()

bool nom::Font::unique ( ) const

Get the object's unique state.

Remarks
The uniqueness of the object – whether or not it is being held by multiple objects – depends on the implementation of std::shared_ptr.

Member Data Documentation

◆ font_

std::shared_ptr<Font::font_type> nom::Font::font_
private

Definition at line 117 of file Font.hpp.


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