Public Member Functions | Private Member Functions | Private Attributes

Font Class Reference

Font Resource. More...

#include <Font.h>

Inheritance diagram for Font:
Resource

List of all members.

Public Member Functions

 Font (const std::string &filePath, Uint ptSize)
 Font (Uint ptSize)
 Font (const Font &font)
 Font ()
 ~Font ()
Uint getWidth (const std::string &str) const
Uint getHeight () const
const std::string & getFontName () const
void setStyle (FontStyle style=STYLE_NORMAL)
TTF_Font * getFont () const

Private Member Functions

void load ()
std::string buildName ()

Private Attributes

TTF_Font * mFont
int mHeight
int mPtSize
File mFontBuffer
std::string mFontName

Detailed Description

Font Resource.

Implements a Font resource.


Constructor & Destructor Documentation

Font::Font ( const std::string &  filePath,
Uint  ptSize 
)
Font::Font ( Uint  ptSize  ) 

Another alternative way to load a Font with a specified point size.

Parameters:
ptSize Point size of the font. Defaults to 12pt.
Font::Font ( const Font font  ) 

A basic copy constructor.

Creates a new copy of a Font Resource from another Font.

Font::Font (  ) 

An alternative way to load a Font using a default point size (10).

Using the default method of instantiating a Font object will yield a 10pt default typeface.

Font::~Font (  )  [inline]

Member Function Documentation

std::string Font::buildName (  )  [private]

Build Font Name with Family Name and Style Name.

This function is called interally to create a Font name based on Font family and Font style.

TTF_Font * Font::getFont (  )  const

Should this be private and just friend the Renderer class?

Returns an SDL TTF_Font object.

Todo:
This is mostly a design issue but we should probably never pass out a data type specific to an API other than our own framework. I would simply pass out a std::string but that would require that the Renderer using Font's do conversions on the fly which can cause a real performance bottleneck. I think our best bet would be to build a resource manager within the Renderer class that handles this sort of conversion for all related resources and stores them until they're no longer needed much like the OpenGL Renderer stores converted SDL_Surface's.
const std::string & Font::getFontName (  )  const

Returns the typeface name.

Returns:
Returns NULL if an error occurs.
Uint Font::getHeight (  )  const

Returns the height in pixels of the font.

Uint Font::getWidth ( const std::string &  str  )  const
void Font::load (  )  [private, virtual]

Loads a Font file.

This is the normal method of loading a Font Resource and is called internally by the constructor. It is not publicly exposed and should never be called anywhere except the constructor.

Implements Resource.

void Font::setStyle ( FontStyle  style = STYLE_NORMAL  ) 

Sets the style of the font to use for rendering.

Parameters:
style Sets the style of the font. Can be STYLE_NORMAL (default), STYLE_BOLD, STYLE_ITALIC or STYLE_UNDERLINE.

Member Data Documentation

TTF_Font* Font::mFont [private]

True Type Font.

Persistent memory buffer for TTF_Font.

std::string Font::mFontName [private]
int Font::mHeight [private]

Font Height.

int Font::mPtSize [private]

Point Size to load the Font in.


The documentation for this class was generated from the following files:
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines