00001 #include "FTGlyphContainer.h" 00002 #include "FTGlyph.h" 00003 #include "FTFace.h" 00004 #include "FTCharmap.h" 00005 00006 00007 FTGlyphContainer::FTGlyphContainer( FTFace* f) 00008 : face(f), 00009 charMap(0), 00010 err(0) 00011 { 00012 glyphs.push_back( NULL); 00013 charMap = new FTCharmap( face); 00014 } 00015 00016 00017 FTGlyphContainer::~FTGlyphContainer() 00018 { 00019 GlyphVector::iterator glyphIterator; 00020 for( glyphIterator = glyphs.begin(); glyphIterator != glyphs.end(); ++glyphIterator) 00021 { 00022 delete *glyphIterator; 00023 } 00024 00025 glyphs.clear(); 00026 } 00027 00028 00029 bool FTGlyphContainer::CharMap( FT_Encoding encoding) 00030 { 00031 bool result = charMap->CharMap( encoding); 00032 err = charMap->Error(); 00033 return result; 00034 } 00035 00036 00037 unsigned int FTGlyphContainer::GlyphIndex( const unsigned int characterCode) const 00038 { 00039 return charMap->GlyphIndex( characterCode); 00040 } 00041 00042 00043 void FTGlyphContainer::Add( FTGlyph* tempGlyph, const unsigned int characterCode) 00044 { 00045 charMap->InsertIndex( characterCode, glyphs.size()); 00046 glyphs.push_back( tempGlyph); 00047 } 00048 00049 00050 const FTGlyph* const FTGlyphContainer::Glyph( const unsigned int characterCode) const 00051 { 00052 unsigned int index = charMap->CharIndex( characterCode); 00053 return glyphs[index]; 00054 } 00055 00056 00057 FTBBox FTGlyphContainer::BBox( const unsigned int characterCode) const 00058 { 00059 return glyphs[charMap->CharIndex( characterCode)]->BBox(); 00060 } 00061 00062 00063 float FTGlyphContainer::Advance( const unsigned int characterCode, const unsigned int nextCharacterCode) 00064 { 00065 unsigned int left = charMap->GlyphIndex( characterCode); 00066 unsigned int right = charMap->GlyphIndex( nextCharacterCode); 00067 00068 float width = face->KernAdvance( left, right).x; 00069 width += glyphs[charMap->CharIndex( characterCode)]->Advance(); 00070 00071 return width; 00072 } 00073 00074 00075 FTPoint FTGlyphContainer::Render( const unsigned int characterCode, const unsigned int nextCharacterCode, FTPoint penPosition) 00076 { 00077 FTPoint kernAdvance; 00078 float advance = 0; 00079 00080 unsigned int left = charMap->GlyphIndex( characterCode); 00081 unsigned int right = charMap->GlyphIndex( nextCharacterCode); 00082 00083 kernAdvance = face->KernAdvance( left, right); 00084 00085 if( !face->Error()) 00086 { 00087 advance = glyphs[charMap->CharIndex( characterCode)]->Render( penPosition); 00088 } 00089 00090 kernAdvance.x = advance + kernAdvance.x; 00091 // kernAdvance.y = advance.y + kernAdvance.y; 00092 return kernAdvance; 00093 }