Main Page | Class Hierarchy | Data Structures | File List | Data Fields | Globals

FTFace.cpp

Go to the documentation of this file.
00001 #include "FTFace.h"
00002 #include "FTLibrary.h"
00003 
00004 #include FT_TRUETYPE_TABLES_H
00005 
00006 FTFace::FTFace( const char* fontFilePath)
00007 :   numGlyphs(0),
00008     fontEncodingList(0),
00009     err(0)
00010 {
00011     const FT_Long DEFAULT_FACE_INDEX = 0;
00012     ftFace = new FT_Face;
00013 
00014     err = FT_New_Face( *FTLibrary::Instance().GetLibrary(), fontFilePath, DEFAULT_FACE_INDEX, ftFace);
00015 
00016     if( err)
00017     {
00018         delete ftFace;
00019         ftFace = 0;
00020     }
00021     else
00022     {
00023         numGlyphs = (*ftFace)->num_glyphs;
00024         hasKerningTable = FT_HAS_KERNING((*ftFace));
00025     }
00026 }
00027 
00028 
00029 FTFace::FTFace( const unsigned char *pBufferBytes, size_t bufferSizeInBytes)
00030 :   numGlyphs(0),
00031     err(0)
00032 {
00033     const FT_Long DEFAULT_FACE_INDEX = 0;
00034     ftFace = new FT_Face;
00035 
00036     err = FT_New_Memory_Face( *FTLibrary::Instance().GetLibrary(), (FT_Byte *)pBufferBytes, bufferSizeInBytes, DEFAULT_FACE_INDEX, ftFace);
00037 
00038     if( err)
00039     {
00040         delete ftFace;
00041         ftFace = 0;
00042     }
00043     else
00044     {
00045         numGlyphs = (*ftFace)->num_glyphs;
00046     }
00047 }
00048 
00049 
00050 FTFace::~FTFace()
00051 {
00052     if( ftFace)
00053     {
00054         FT_Done_Face( *ftFace);
00055         delete ftFace;
00056         ftFace = 0;
00057     }
00058 }
00059 
00060 
00061 bool FTFace::Attach( const char* fontFilePath)
00062 {
00063     err = FT_Attach_File( *ftFace, fontFilePath);
00064     return !err;
00065 }
00066 
00067 
00068 bool FTFace::Attach( const unsigned char *pBufferBytes, size_t bufferSizeInBytes)
00069 {
00070     FT_Open_Args open;
00071 
00072     open.flags = FT_OPEN_MEMORY;
00073     open.memory_base = (FT_Byte *)pBufferBytes;
00074     open.memory_size = bufferSizeInBytes;
00075 
00076     err = FT_Attach_Stream( *ftFace, &open);
00077     return !err;
00078 }
00079 
00080 
00081 const FTSize& FTFace::Size( const unsigned int size, const unsigned int res)
00082 {
00083     charSize.CharSize( ftFace, size, res, res);
00084     err = charSize.Error();
00085 
00086     return charSize;
00087 }
00088 
00089 
00090 unsigned int FTFace::CharMapCount()
00091 {
00092     return (*ftFace)->num_charmaps;
00093 }
00094 
00095 
00096 FT_Encoding* FTFace::CharMapList()
00097 {
00098     if( 0 == fontEncodingList)
00099     {
00100         fontEncodingList = new FT_Encoding[CharMapCount()];
00101         for( size_t encodingIndex = 0; encodingIndex < CharMapCount(); ++encodingIndex)
00102         {
00103             fontEncodingList[encodingIndex] = (*ftFace)->charmaps[encodingIndex]->encoding;
00104         }
00105     }
00106     
00107     return fontEncodingList;
00108 }
00109 
00110 
00111 FTPoint FTFace::KernAdvance( unsigned int index1, unsigned int index2)
00112 {
00113     float x, y;
00114     x = y = 0.0f;
00115 
00116     if( hasKerningTable && index1 && index2)
00117     {
00118         FT_Vector kernAdvance;
00119         kernAdvance.x = kernAdvance.y = 0;
00120 
00121         err = FT_Get_Kerning( *ftFace, index1, index2, ft_kerning_unfitted, &kernAdvance);
00122         if( !err)
00123         {   
00124             x = static_cast<float>( kernAdvance.x) / 64.0f;
00125             y = static_cast<float>( kernAdvance.y) / 64.0f;
00126         }
00127     }
00128     
00129     return FTPoint( x, y, 0.0);
00130 }
00131 
00132 
00133 FT_GlyphSlot FTFace::Glyph( unsigned int index, FT_Int load_flags)
00134 {
00135     err = FT_Load_Glyph( *ftFace, index, load_flags);
00136     if( err)
00137     {
00138         return NULL;
00139     }
00140 
00141     return (*ftFace)->glyph;
00142 }
00143 

Generated on Sun Dec 5 22:24:05 2004 for FTGL by doxygen 1.3.6