Main Page | Namespace List | Class Hierarchy | Alphabetical List | Data Structures | File List | Namespace Members | Data Fields | Globals

Ars::FontEngine Class Reference

#include <arsfontengine.h>


Public Member Functions

 FontEngine (const std::string &sFontFileName, unsigned char FontSize)
virtual ~FontEngine (void)
 Standard destructor.

const int GetFontSize (void) const
std::string GetFontFilename (void) const
FT_BitmapGlyphRec * RenderGlyph (const char Char)
FT_Glyph_Metrics * GetMetrics (const char Char)

Protected Attributes

FT_Face m_FontFace
 The FreeType font face.

std::map< char, FT_BitmapGlyphRec > m_CachedGlyphMap
 A cached map of the rendered glyphs.

std::map< char, FT_Glyph_Metrics > m_CachedMetricsMap
 A cached map of the glyph metrics.


Static Protected Attributes

FT_Library m_FTLibrary
 The FreeType library.

bool m_bFTLibraryLoaded = false
 Indicates if the FreeType library has been loaded.


Private Attributes

unsigned int fontSize
std::string fontFilename


Detailed Description

The CFont class is wGui's interface to FreeType2 and is used to render strings This is used by the CRenderedString class, and shouldn't need to ever be called directly
See also:
CRenderedString

Definition at line 14 of file arsfontengine.h.


Constructor & Destructor Documentation

Ars::FontEngine::FontEngine const std::string &  sFontFileName,
unsigned char  FontSize
 

Construct a new CFont object, using the specified font For most cases, there is no need to directly instantiate a CFontEngine object. CApplication provides a GetFontEngine() method which should be used

Parameters:
sFontFileName The file that contains a file
FontSize The size of the font (in points)

Definition at line 10 of file arsfontengine.cpp.

References m_bFTLibraryLoaded, m_FontFace, m_FTLibrary, and tron.

00011 : fontSize( FontSize ) , fontFilename( sFontFileName )
00012 {
00013         if (!m_bFTLibraryLoaded)
00014         {
00015                 if (FT_Init_FreeType(&m_FTLibrary))
00016                         tron << "FontEngine::FontEngine : Unable to initialize FreeType library.\n";
00017                 m_bFTLibraryLoaded = true;
00018         }
00019         if (FT_New_Face(m_FTLibrary, sFontFileName.c_str(), 0, &m_FontFace))
00020                 tron << "FontEngine::FontEngine : Unable to create font face.";
00021         if (FT_Set_Char_Size(m_FontFace, 0, FontSize * 64, 0, 0))
00022                 tron << "FontEngine::FontEngine : Unable to set character size.\n";
00023 }

Ars::FontEngine::~FontEngine void   )  [virtual]
 

Standard destructor.

Definition at line 26 of file arsfontengine.cpp.

References m_FontFace.

00027 {
00028         FT_Done_Face(m_FontFace);
00029 }


Member Function Documentation

std::string Ars::FontEngine::GetFontFilename void   )  const [inline]
 

Definition at line 32 of file arsfontengine.h.

References fontFilename.

Referenced by Ars::Painter::Init().

00032 {       return fontFilename;    }

const int Ars::FontEngine::GetFontSize void   )  const [inline]
 

Definition at line 31 of file arsfontengine.h.

References fontSize.

Referenced by Ars::HPaint::GetFontSize(), and Ars::HPaint::GetTextSize().

00031 {       return fontSize;        }

FT_Glyph_Metrics * Ars::FontEngine::GetMetrics const char  Char  ) 
 

Returns the metrics for a specified character

Parameters:
Char The character to render
Returns:
A pointer to a FreeType metrics structure

Definition at line 49 of file arsfontengine.cpp.

References m_CachedMetricsMap, and m_FontFace.

Referenced by Ars::HPaint::GetMaxFontHeight(), and Ars::HPaint::GetMetrics().

00050 {
00051         std::map<char, FT_Glyph_Metrics>::iterator glyphIter = m_CachedMetricsMap.find(Char);
00052         if (glyphIter == m_CachedMetricsMap.end())
00053         {
00054                 if(FT_Load_Char(m_FontFace, Char, FT_LOAD_DEFAULT) == 0 )
00055                 {
00056                         glyphIter = m_CachedMetricsMap.insert(std::make_pair(Char, m_FontFace->glyph->metrics)).first;
00057                         return &(glyphIter->second);
00058                 }
00059         }
00060         return &(glyphIter->second);
00061 }

FT_BitmapGlyphRec * Ars::FontEngine::RenderGlyph const char  Char  ) 
 

Renders the specified character

Parameters:
Char The character to render
Returns:
A pointer to a FreeType glyph

Definition at line 31 of file arsfontengine.cpp.

References m_CachedGlyphMap, and m_FontFace.

Referenced by Ars::HPaint::_TextOut().

00032 {
00033         std::map<char, FT_BitmapGlyphRec>::iterator glyphIter = m_CachedGlyphMap.find(Char);
00034         if (glyphIter == m_CachedGlyphMap.end())
00035         {
00036                 if( FT_Load_Char(m_FontFace, Char, FT_LOAD_DEFAULT) == 0 )
00037                 {
00038                         FT_Glyph glyph;
00039                         if( FT_Get_Glyph(m_FontFace->glyph, &glyph) == 0 && FT_Glyph_To_Bitmap(&glyph, ft_render_mode_normal, 0, 1) == 0 )
00040                         {
00041                                 glyphIter = m_CachedGlyphMap.insert(std::make_pair(Char, *reinterpret_cast<FT_BitmapGlyph>(glyph))).first;
00042                                 return &(glyphIter->second);
00043                         }
00044                 }
00045         }
00046         return &(glyphIter->second);
00047 }


Field Documentation

std::string Ars::FontEngine::fontFilename [private]
 

Definition at line 18 of file arsfontengine.h.

Referenced by GetFontFilename().

unsigned int Ars::FontEngine::fontSize [private]
 

Definition at line 17 of file arsfontengine.h.

Referenced by GetFontSize().

bool Ars::FontEngine::m_bFTLibraryLoaded = false [static, protected]
 

Indicates if the FreeType library has been loaded.

Definition at line 7 of file arsfontengine.cpp.

Referenced by FontEngine().

std::map<char, FT_BitmapGlyphRec> Ars::FontEngine::m_CachedGlyphMap [protected]
 

A cached map of the rendered glyphs.

Definition at line 48 of file arsfontengine.h.

Referenced by RenderGlyph().

std::map<char, FT_Glyph_Metrics> Ars::FontEngine::m_CachedMetricsMap [protected]
 

A cached map of the glyph metrics.

Definition at line 49 of file arsfontengine.h.

Referenced by GetMetrics().

FT_Face Ars::FontEngine::m_FontFace [protected]
 

The FreeType font face.

Definition at line 47 of file arsfontengine.h.

Referenced by FontEngine(), GetMetrics(), RenderGlyph(), and ~FontEngine().

FT_Library Ars::FontEngine::m_FTLibrary [static, protected]
 

The FreeType library.

Definition at line 6 of file arsfontengine.cpp.

Referenced by FontEngine().


The documentation for this class was generated from the following files:
Generated on Fri Dec 5 04:06:43 2003 for Borqueror by doxygen 1.3.3