Game Development Reference
In-Depth Information
30. The routine LoadStringWithFont() does the job of horizontal position
calculation for each character of the string S :
bool LoadStringWithFont(const std::string& S, int ID, int
Height )
{
if ( ID < 0 ) { return false; }
31. Get the required font face:
FFace = GetSizedFace( ID, Height );
if ( FFace == NULL ) { return false; }
bool UseKerning = FT_HAS_KERNING( Face );
32. Decode the input UTF-8 string and calculate character sizes, checking each
element in FString :
DecodeUTF8( S.c_str() );
for ( size_t i = 0, count = FString.size(); i != count;
i++ )
{
sFTChar& Char = FString[i];
FT_UInt ch = Char.FChar;
Char.FIndex = ( ch != '\r' && ch != '\n' ) ?
GetCharIndex(ID, ch) : -1;
33. Load a glyph corresponding to the character:
Char.FGlyph = ( Char.FIndex != -1 ) ?
GetGlyph( ID, Height, ch,
FT_LOAD_RENDER, &Char.FCacheNode ) : NULL;
if ( !Char.FGlyph || Char.FIndex == -1 ) continue;
34. Calculate the horizontal offset of this glyph:
SetAdvance( Char );
35. Calculate the kerning for each character, except the irst one:
if (i > 0 && UseKerning) Kern(FString[i - 1], Char);
}
return true;
}
36. The LoadStringWithFont() function uses auxiliary routines Kern() and
SetAdvance() to calculate the offset between two sequential characters:
void SetAdvance( sFTChar& Char )
{
Char.FAdvance = Char.FWidth = 0;
if ( !Char.FGlyph ) { return; }
 
Search WWH ::




Custom Search