Game Development Reference
In-Depth Information
The
ReadFileData()
function loads the content of
File
. You are encouraged
to implement this function or to see the accompanying source, where it is done by
means of our Virtual Filesystem.
11. The static function
FreeType_Face_Requester()
caches the access to the font
face and allows us to reuse loaded fonts. It is deined in the FreeType library headers:
FT_Error FreeType_Face_Requester( FTC_FaceID FaceID,
FT_Library Library, FT_Pointer RequestData,
FT_Face* Face )
{
#ifdef _WIN64
long long int Idx = (long long int)FaceID;
int FaceIdx = (int)(Idx & 0xFF);
#else
int FaceIdx = reinterpret_cast< int >(FaceID);
#endif
if ( FaceIdx < 0 ) { return 1; }
TextRenderer* Renderer = ( TextRenderer* )RequestData;
std::string File = Renderer ->FFontFaces[FaceIdx];
FT_Error Result = Renderer ->LoadFontFile( File );
*Face = (Result == 0) ?
Renderer->FFontFaceHandles[File] : NULL;
return Result;
}
The FreeType library allows the
RequestData
parameter, where we pass an instance
of
TextRenderer
by pointer. The
#ifdef
in the code of
FreeType_Face_
Requester()
is necessary to run on 64-bit versions of Windows. The Android OS is
32-bit only, and the casting of
void*
to
int
is implicitly allowed.
12. The
GetSizedFace
function sets the font size for the loaded face:
FT_Face GetSizedFace( int FontID, int Height )
{
FTC_ScalerRec Scaler;
Scaler.face_id = IntToID(FontID);
Scaler.height = Height;
Scaler.width = 0;
Scaler.pixel = 1;
FT_Size SizedFont;
if ( !FTC_Manager_LookupSizePTR(FManager, &Scaler,
&SizedFont) ) return NULL;
if ( FT_Activate_SizePTR( SizedFont ) != 0 ) { return
NULL; }
return SizedFont->face;
}