Main Page | Class Hierarchy | Compound List | File List | Compound Members | File Members

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

Generated on Mon Aug 25 15:16:37 2003 for FTGL by doxygen 1.3.3