Game Development Reference
In-Depth Information
37. Convert the value from the 26.6 ixed-point format:
Char.FAdvance = Char.FGlyph->advance.x >> 10;
FT_BBox bbox;
FT_Glyph_Get_CBoxPTR( Char.FGlyph,
FT_GLYPH_BBOX_GRIDFIT, &bbox );
Char.FWidth = bbox.xMax;
if ( Char.FWidth == 0 && Char.FAdvance != 0 )
{ Char.FWidth = Char.FAdvance; }
}
void Kern( sFTChar& Left, const sFTChar& Right )
{
if ( Left.FIndex == -1 || Right.FIndex == -1 )
{ return; }
FT_Vector Delta;
FT_Get_KerningPTR( FFace, Left.FIndex, Right.FIndex,
FT_KERNING_DEFAULT, &Delta );
Left.FAdvance += Delta.x;
}
38. Finally, once we have the positions of each character, we render the
individual glyphs to the bitmap:
void RenderLineOnBitmap( const std::string& S,
int FontID, int FontHeight, int StartX, int Y,
unsigned int C, bool LeftToRight, const clPtr<Bitmap>&
Out )
{
LoadStringWithFont( S, FontID, FontHeight );
int x = StartX << 6;
for ( size_t j = 0 ; j != FString.size(); j++ )
{
if ( FString[j].FGlyph != 0 )
{
auto Glyph = (FT_BitmapGlyph) FString[j].FGlyph;
int in_x = (x>>6);
in_x += (LeftToRight ? 1 : -1) * BmpGlyph->left;
if ( !LeftToRight )
{
in_x += BmpGlyph->bitmap.width;
in_x = StartX + ( StartX - in_x );
}
DrawGlyph( Out, &BmpGlyph->bitmap, in_x, Y -
BmpGlyph->top, Color );
}
x += FString[j].FAdvance;
}
}
 
Search WWH ::




Custom Search