Game Development Reference
In-Depth Information
24. Another variable stores the horizontal size of the string:
int SizeX = 0;
25. We iterate over the FString array and use the sFTChar::FGlyph ield to
retrieve the vertical character size. We also add the FAdvance ield to SizeX ,
to account for the kerning and horizontal character size:
for ( size_t i = 0 ; i != FString.size(); i++ )
{
if ( FString[i].FGlyph == NULL ) { continue; }
auto Glyph = ( FT_BitmapGlyph )FString[i].FGlyph;
SizeX += FString[i].FAdvance;
int Y = Glyph->top;
int H = Glyph->bitmap.rows;
if ( Y > StrMinY ) { StrMinY = Y; }
if ( H - Y > StrMaxY ) { StrMaxY = H - Y; }
}
if ( Width ) { *Width = ( SizeX >> 6 ); }
if ( BaseLine ) { *BaseLine = StrMaxY; }
if ( MinY ) { *MinY = StrMinY; }
if ( MaxY ) { *MaxY = StrMaxY; }
}
26. We use the preceding code to render a UTF-8 string into a newly allocated bitmap:
clPtr<Bitmap> RenderTextWithFont( const std::string& Str,
int FontID, int FontHeight,
unsigned int Color, bool LeftToRight )
{
27. Decode the UTF-8 input string and calculate individual character positions:
if ( !LoadTextStringWithFont(Str, FontID, FontHeight) )
{ return NULL; }
28. Calculate the horizontal and vertical string dimensions and allocate the
output bitmap:
int W, Y, MinY, MaxY;
CalculateLineParameters( &W, &MinY, &MaxY, &Y );
clPtr<Bitmap> Result = new Bitmap( W, MaxY + MinY);
29. Render all the glyphs to the bitmap. Start on the other side of the bitmap, if
the text is right-to-left:
RenderLineOnBitmap( TextString, FontID, FontHeight,
LeftToRight ? 0 : W - 1,
MinY, Color, LeftToRight,
Result );
return Result;
}
 
Search WWH ::




Custom Search