FontTTF Class Reference

Implementation of font using SDL_ttf. More...

#include <font_ttf.h>

Inherits Font.

Inheritance diagram for FontTTF:

Inheritance graph
[legend]
Collaboration diagram for FontTTF:

Collaboration graph
[legend]
List of all members.

Public Member Functions

 FontTTF (const char *file, int ptsize)
virtual ~FontTTF ()
virtual void RenderUTF8 (const std::string &utf8str, float x, float y)
 Render UTF-8 encoded string.
virtual int Ascent ()
 Get line height.
virtual void cleanCache ()
 Clear the cache.
virtual int getWwidth ()
 Get width of W.
virtual int getTextWidth (const std::string &utf8str)
 Get With of text in pixels.

Private Types

typedef FontTTF::SCacheMember SCacheMember
typedef STL_EXT_NS::hash_map<
std::string, SCacheMember * > 
TStringHash

Private Attributes

TTF_Font * mFont
TStringHash mRenderedCache
 Rendered string.
int mWwidth
 -1 means invalid / not measured yet

Classes

struct  SCacheMember

Detailed Description

Implementation of font using SDL_ttf.

The font use caching of recently rendered strings. So if you render some string often it should be fast. But if you render different strings every frame the performance won't be good.

Definition at line 24 of file font_ttf.h.


Member Typedef Documentation

typedef struct FontTTF::SCacheMember FontTTF::SCacheMember [private]
 

typedef STL_EXT_NS::hash_map<std::string, SCacheMember*> FontTTF::TStringHash [private]
 

Definition at line 66 of file font_ttf.h.


Constructor & Destructor Documentation

FontTTF::FontTTF const char *  file,
int  ptsize
 

Definition at line 74 of file font_ttf.cpp.

References DIE(), and LOGE.

Here is the call graph for this function:

FontTTF::~FontTTF  )  [virtual]
 

Definition at line 94 of file font_ttf.cpp.

References cleanCache(), and mFont.

Here is the call graph for this function:


Member Function Documentation

int FontTTF::Ascent  )  [virtual]
 

Get line height.

The value is usefull if you want to render multiline text and need to know height of line.

Returns:
Height if line in font.

Implements Font.

Definition at line 317 of file font_ttf.cpp.

References assertL, and mFont.

void FontTTF::cleanCache  )  [virtual]
 

Clear the cache.

Check the whole cache and delete members that weren't used for a long time.

Reimplemented from Font.

Definition at line 271 of file font_ttf.cpp.

References LOGT, and mRenderedCache.

Referenced by ~FontTTF().

int FontTTF::getTextWidth const std::string &  utf8str  )  [virtual]
 

Get With of text in pixels.

Get width of utf-8 encoded text.

Returns:
Width of text.

Implements Font.

Definition at line 336 of file font_ttf.cpp.

References assertL, and mFont.

int FontTTF::getWwidth  )  [virtual]
 

Get width of W.

W is usuallu the most width char in font so you may use this as aproximation.

Returns:
Width of W.

Implements Font.

Definition at line 324 of file font_ttf.cpp.

References assertL, mFont, and mWwidth.

void FontTTF::RenderUTF8 const std::string &  utf8str,
float  x,
float  y
[virtual]
 

Render UTF-8 encoded string.

Render text to specified position. First call may be slower if implementation use some cache for rendered fonts.

Note:
[0,0] is left bottom corner of screen.
Parameters:
utf8str string that to be rendered
x x coodrinate if text
y y coodrinate if text

Implements Font.

Definition at line 201 of file font_ttf.cpp.

References ConvertToRGBA(), DIE(), FontTTF::SCacheMember::h, LOGE, LOGT, mFont, mRenderedCache, FontTTF::SCacheMember::surface, SwapRows(), TIN, FontTTF::SCacheMember::usages, and FontTTF::SCacheMember::w.

Here is the call graph for this function:


Member Data Documentation

TTF_Font* FontTTF::mFont [private]
 

Definition at line 54 of file font_ttf.h.

Referenced by Ascent(), getTextWidth(), getWwidth(), RenderUTF8(), and ~FontTTF().

TStringHash FontTTF::mRenderedCache [private]
 

Rendered string.

Definition at line 68 of file font_ttf.h.

Referenced by cleanCache(), and RenderUTF8().

int FontTTF::mWwidth [private]
 

-1 means invalid / not measured yet

Definition at line 70 of file font_ttf.h.

Referenced by getWwidth().


The documentation for this class was generated from the following files:
Generated on Wed Apr 12 14:14:36 2006 for bjs by  doxygen 1.4.5