Back to index

extremetuxracer  0.5beta
Public Member Functions | Static Public Member Functions | Private Attributes | Static Private Attributes
pp::Font Class Reference

#include <font.h>

Collaboration diagram for pp::Font:
Collaboration graph
[legend]

List of all members.

Public Member Functions

 Font (const char *fileName, unsigned int size, const pp::Color &color)
 Font (const char *fileName, unsigned int size, const pp::Color &color, bool isOutline)
 Font (FTFont *font, const pp::Color &color)
 ~Font ()
void draw (const char *string, float x, float y)
 draws the utf8 string at position x,y
void draw (const char *string, pp::Vec2d position)
 draws the utf8 string at the specified position
void draw (const wchar_t *string, float x, float y)
 draws the unicode string at position x,y
void draw (const wchar_t *string, pp::Vec2d position)
 draws the unicode string at the specified position
float ascender ()
float descender ()
float advance (const char *string)
float advance (const wchar_t *string)
pp::ColorgetColor ()
void setColor (pp::Color &c)
FTFont * getFTFont ()

Static Public Member Functions

static bool registerFont (const char *binding, const char *fileName, unsigned int size, const pp::Color &color)
 loads and registers the ttf file to the specified binding
static bool registerFont (const char *binding, const char *fileName, unsigned int size, const pp::Color &color, bool isOutline)
static bool bindFont (const char *binding, const char *fontName)
 bind font to the specified font
static bool bindFont (const char *binding, const char *fontName, const pp::Color &color)
 bind font to the specified font with a different color
static Fontget (const char *binding)
 returns a pointer to a font
static void draw (const char *binding, const char *string, float x, float y)
static wchar_t * utf8ToUnicode (const char *string)
 returns the unicode of the utf8 string.
static void utf8ToUnicode (wchar_t *buff, const char *string)
 fills the buff array with the unicode string.

Private Attributes

FTFont * mp_font
pp::Color m_color

Static Private Attributes

static std::map< std::string,
pp::Font * > 
sm_bindings
 stores the font bindings

Detailed Description

Definition at line 31 of file font.h.


Constructor & Destructor Documentation

pp::Font::Font ( const char *  fileName,
unsigned int  size,
const pp::Color color 
)

Definition at line 46 of file font.cpp.

 : mp_font(NULL),
   m_color(color)
{
       mp_font = new FTGLTextureFont(fileName);
       
       mp_font->FaceSize(size);
       mp_font->CharMap(ft_encoding_unicode);    
}

Here is the caller graph for this function:

pp::Font::Font ( const char *  fileName,
unsigned int  size,
const pp::Color color,
bool  isOutline 
)

Definition at line 56 of file font.cpp.

 : mp_font(NULL),
   m_color(color)
{
    if(isOutline) {
        mp_font = new FTGLOutlineFont(fileName);
    }else{
        mp_font = new FTGLTextureFont(fileName);
    };
       
       mp_font->FaceSize(size);
       mp_font->CharMap(ft_encoding_unicode);    
}
pp::Font::Font ( FTFont *  font,
const pp::Color color 
)

Definition at line 72 of file font.cpp.

 : mp_font(font),
   m_color(color)
{
}

Definition at line 78 of file font.cpp.

{
       /* we don't have a refpointer yet...      
       if(mp_font!=NULL){
              delete mp_font;
       }
       */
}

Member Function Documentation

float pp::Font::advance ( const char *  string)

Definition at line 141 of file font.cpp.

{
       const wchar_t* u_string;
       u_string = Font::utf8ToUnicode(string);   
       
       float adv = mp_font->Advance(u_string);
       
       delete u_string;
       return adv;   
}

Here is the call graph for this function:

Here is the caller graph for this function:

float pp::Font::advance ( const wchar_t *  string)

Definition at line 153 of file font.cpp.

{
       return mp_font->Advance(string);   
}
float pp::Font::ascender ( )

Definition at line 129 of file font.cpp.

{
       return mp_font->Ascender();
}

Here is the caller graph for this function:

bool pp::Font::bindFont ( const char *  binding,
const char *  fontName 
) [static]

bind font to the specified font

Definition at line 197 of file font.cpp.

{
       pp::Font *font = pp::Font::get(fontName);
       if(font==NULL) return false;
              
       sm_bindings[binding] = new pp::Font(font->getFTFont(), font->getColor());
       return true;
}      

Here is the call graph for this function:

Here is the caller graph for this function:

bool pp::Font::bindFont ( const char *  binding,
const char *  fontName,
const pp::Color color 
) [static]

bind font to the specified font with a different color

Definition at line 207 of file font.cpp.

{
       pp::Font *font = pp::Font::get(fontName);
       if(font==NULL) return false;
              
       sm_bindings[binding] = new pp::Font(font->getFTFont(), color);
       return true;
}

Here is the call graph for this function:

Definition at line 135 of file font.cpp.

{
       return mp_font->Descender();
}

Here is the caller graph for this function:

void pp::Font::draw ( const char *  string,
float  x,
float  y 
)

draws the utf8 string at position x,y

Definition at line 88 of file font.cpp.

{
       const wchar_t* u_string;
       u_string = Font::utf8ToUnicode(string);   

       glPushMatrix();
       {
              glColor4dv( (double*)&m_color );
              glTranslatef(x, y, 0);
              mp_font->Render(u_string);
       }
       glPopMatrix();

       delete u_string;
}

Here is the call graph for this function:

Here is the caller graph for this function:

void pp::Font::draw ( const char *  string,
pp::Vec2d  position 
)

draws the utf8 string at the specified position

Definition at line 105 of file font.cpp.

{
       draw(string, position.x, position.y);
}

Here is the call graph for this function:

void pp::Font::draw ( const wchar_t *  string,
float  x,
float  y 
)

draws the unicode string at position x,y

Definition at line 111 of file font.cpp.

{
       glPushMatrix();
       {
              glColor4dv( (double*)&m_color );
              glTranslatef(x, y, 0);
              mp_font->Render(string);
       }
       glPopMatrix();
}
void pp::Font::draw ( const wchar_t *  string,
pp::Vec2d  position 
)

draws the unicode string at the specified position

Definition at line 123 of file font.cpp.

{
       draw(string, position.x, position.y);
}

Here is the call graph for this function:

void pp::Font::draw ( const char *  binding,
const char *  string,
float  x,
float  y 
) [static]

Definition at line 233 of file font.cpp.

{
       pp::Font* font = pp::Font::get(binding);
       
       if(font!=NULL){      
              font->draw(string, x, y);
       }
}

Here is the call graph for this function:

Font * pp::Font::get ( const char *  binding) [static]

returns a pointer to a font

Definition at line 217 of file font.cpp.

{
       if(binding==NULL){
              return NULL;
       }
       
       std::map<std::string, pp::Font*>::iterator it;
       it = sm_bindings.find(binding);
       if (it != sm_bindings.end()){
              return (*it).second;
       }else{
              return NULL;
       }      
}

Here is the caller graph for this function:

Definition at line 159 of file font.cpp.

{
       return m_color;
}

Here is the caller graph for this function:

FTFont * pp::Font::getFTFont ( )

Definition at line 170 of file font.cpp.

{
       return mp_font;
}

Here is the caller graph for this function:

bool pp::Font::registerFont ( const char *  binding,
const char *  fileName,
unsigned int  size,
const pp::Color color 
) [static]

loads and registers the ttf file to the specified binding

Definition at line 181 of file font.cpp.

{
       //todo: check wether the font alrady exists      
       sm_bindings[binding] = new pp::Font(fileName, size, color);
       return true;
}

Here is the call graph for this function:

Here is the caller graph for this function:

bool pp::Font::registerFont ( const char *  binding,
const char *  fileName,
unsigned int  size,
const pp::Color color,
bool  isOutline 
) [static]

Definition at line 189 of file font.cpp.

{
       //todo: check wether the font alrady exists      
       sm_bindings[binding] = new pp::Font(fileName, size, color, isOutline);
       return true;
}

Here is the call graph for this function:

Definition at line 164 of file font.cpp.

                              {
    m_color = c;
}

Here is the caller graph for this function:

wchar_t * pp::Font::utf8ToUnicode ( const char *  string) [static]

returns the unicode of the utf8 string.

Definition at line 243 of file font.cpp.

{
       wchar_t ch;
       int len = strlen(string);
       wchar_t *u_string = new wchar_t[len+1];
       int j=0;
              
       for (int i=0; i < len; ++i, ++j ) {
              ch = ((const unsigned char *)string)[i];
              if ( ch >= 0xF0 ) {
                     ch  =  (wchar_t)(string[i]&0x07) << 18;
                     ch |=  (wchar_t)(string[++i]&0x3F) << 12;
                     ch |=  (wchar_t)(string[++i]&0x3F) << 6;
                     ch |=  (wchar_t)(string[++i]&0x3F);
              } else
              if ( ch >= 0xE0 ) {
                     ch  =  (wchar_t)(string[i]&0x0F) << 12;
                     ch |=  (wchar_t)(string[++i]&0x3F) << 6;
                     ch |=  (wchar_t)(string[++i]&0x3F);
              } else
              if ( ch >= 0xC0 ) {
                     ch  =  (wchar_t)(string[i]&0x1F) << 6;
                     ch |=  (wchar_t)(string[++i]&0x3F);
              }
              u_string[j] = ch;
       }
       u_string[j] = 0;
       
       return u_string;
}

Here is the caller graph for this function:

void pp::Font::utf8ToUnicode ( wchar_t *  buff,
const char *  string 
) [static]

fills the buff array with the unicode string.

Definition at line 275 of file font.cpp.

{
       wchar_t ch;
       int len = strlen(string);
       int j=0;
              
       for (int i=0; i < len; ++i, ++j ) {
              ch = ((const unsigned char *)string)[i];
              if ( ch >= 0xF0 ) {
                     ch  =  (wchar_t)(string[i]&0x07) << 18;
                     ch |=  (wchar_t)(string[++i]&0x3F) << 12;
                     ch |=  (wchar_t)(string[++i]&0x3F) << 6;
                     ch |=  (wchar_t)(string[++i]&0x3F);
              } else
              if ( ch >= 0xE0 ) {
                     ch  =  (wchar_t)(string[i]&0x0F) << 12;
                     ch |=  (wchar_t)(string[++i]&0x3F) << 6;
                     ch |=  (wchar_t)(string[++i]&0x3F);
              } else
              if ( ch >= 0xC0 ) {
                     ch  =  (wchar_t)(string[i]&0x1F) << 6;
                     ch |=  (wchar_t)(string[++i]&0x3F);
              }
              buff[j] = ch;
       }
       buff[j] = 0;
}

Member Data Documentation

Definition at line 35 of file font.h.

FTFont* pp::Font::mp_font [private]

Definition at line 34 of file font.h.

std::map< std::string, pp::Font * > pp::Font::sm_bindings [static, private]

stores the font bindings

Definition at line 72 of file font.h.


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