Main Page | File List | 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 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(), filename, 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 } 00025 } 00026 00027 00028 FTFace::FTFace( const unsigned char *pBufferBytes, size_t bufferSizeInBytes) 00029 : numGlyphs(0), 00030 err(0) 00031 { 00032 const FT_Long DEFAULT_FACE_INDEX = 0; 00033 ftFace = new FT_Face; 00034 00035 err = FT_New_Memory_Face( *FTLibrary::Instance().GetLibrary(), (FT_Byte *)pBufferBytes, bufferSizeInBytes, DEFAULT_FACE_INDEX, ftFace); 00036 00037 if( err) 00038 { 00039 delete ftFace; 00040 ftFace = 0; 00041 } 00042 else 00043 { 00044 numGlyphs = (*ftFace)->num_glyphs; 00045 } 00046 } 00047 00048 00049 FTFace::~FTFace() 00050 { 00051 Close(); 00052 } 00053 00054 00055 bool FTFace::Attach( const char* filename) 00056 { 00057 err = FT_Attach_File( *ftFace, filename); 00058 return !err; 00059 } 00060 00061 00062 bool FTFace::Attach( const unsigned char *pBufferBytes, size_t bufferSizeInBytes) 00063 { 00064 FT_Open_Args open; 00065 00066 open.flags = FT_OPEN_MEMORY; 00067 open.memory_base = (FT_Byte *)pBufferBytes; 00068 open.memory_size = bufferSizeInBytes; 00069 00070 err = FT_Attach_Stream( *ftFace, &open); 00071 return !err; 00072 } 00073 00074 00075 void FTFace::Close() 00076 { 00077 if( ftFace) 00078 { 00079 FT_Done_Face( *ftFace); 00080 delete ftFace; 00081 ftFace = 0; 00082 } 00083 } 00084 00085 00086 const FTSize& FTFace::Size( const unsigned int size, const unsigned int res) 00087 { 00088 charSize.CharSize( ftFace, size, res, res); 00089 err = charSize.Error(); 00090 00091 return charSize; 00092 } 00093 00094 00095 unsigned int FTFace::CharMapCount() 00096 { 00097 return (*ftFace)->num_charmaps; 00098 } 00099 00100 00101 FT_Encoding* FTFace::CharMapList() 00102 { 00103 if( 0 == fontEncodingList) 00104 { 00105 fontEncodingList = new FT_Encoding[CharMapCount()]; 00106 for( size_t encodingIndex = 0; encodingIndex < CharMapCount(); ++encodingIndex) 00107 { 00108 fontEncodingList[encodingIndex] = (*ftFace)->charmaps[encodingIndex]->encoding; 00109 } 00110 } 00111 00112 return fontEncodingList; 00113 } 00114 00115 00116 unsigned int FTFace::UnitsPerEM() const 00117 { 00118 return (*ftFace)->units_per_EM; 00119 } 00120 00121 00122 FTPoint FTFace::KernAdvance( unsigned int index1, unsigned int index2) 00123 { 00124 float x, y; 00125 x = y = 0.0f; 00126 00127 if( FT_HAS_KERNING((*ftFace)) && index1 && index2) 00128 { 00129 FT_Vector kernAdvance; 00130 kernAdvance.x = kernAdvance.y = 0; 00131 00132 err = FT_Get_Kerning( *ftFace, index1, index2, ft_kerning_unfitted, &kernAdvance); 00133 if( !err) 00134 { 00135 x = static_cast<float>( kernAdvance.x) / 64.0f; 00136 y = static_cast<float>( kernAdvance.y) / 64.0f; 00137 } 00138 } 00139 00140 return FTPoint( x, y, 0.0); 00141 } 00142 00143 00144 FT_GlyphSlot FTFace::Glyph( unsigned int index, FT_Int load_flags) 00145 { 00146 err = FT_Load_Glyph( *ftFace, index, load_flags); 00147 if( err) 00148 { 00149 return NULL; 00150 } 00151 00152 return (*ftFace)->glyph; 00153 } 00154

Generated on Tue Jul 27 22:31:15 2004 for FTGL by doxygen 1.3.7