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

arsfontengine.cpp

Go to the documentation of this file.
00001 #include "SdlArs.h"
00002 
00003 namespace Ars
00004 {
00005 // Static members
00006 FT_Library FontEngine::m_FTLibrary;
00007 bool FontEngine::m_bFTLibraryLoaded = false;
00008 
00009 
00010 FontEngine::FontEngine(const std::string& sFontFileName, unsigned char FontSize)
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 }
00024 
00025 
00026 FontEngine::~FontEngine(void)
00027 {
00028         FT_Done_Face(m_FontFace);
00029 }
00030 
00031 FT_BitmapGlyphRec* FontEngine::RenderGlyph( const char Char )
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 }
00048 
00049 FT_Glyph_Metrics* FontEngine::GetMetrics( const char Char )
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 }
00062 
00063 }

Generated on Fri Dec 5 04:05:58 2003 for Borqueror by doxygen 1.3.3