Game Development Reference
In-Depth Information
16. The
NextUTF8()
and
ContUTF8()
inline functions are declared next to the
decoding buffers:
static const int UTF8_LINE_END = 0;
static const int UTF8_DECODE_ERROR = -1;
17. A buffer with the current string:
std::vector<sFTChar> FString;
18. The current character index and the source buffer length:
int FIndex, FLength;
19. Raw pointer to the source buffer and the current byte:
const char* FBuffer;
int FByte;
20. Get the next byte or
UTF8_LINE_END
if there are no bytes left:
inline int NextUTF8()
{
return ( FIndex >= FLength ) ?
UTF8_LINE_END : ( FBuffer[FIndex++] & 0xFF );
}
21. Get the low six bits of the next continuation byte and return
UTF8_DECODE_ERROR
if it is not a continuation byte:
inline int ContUTF8()
{
int c = NextUTF8();
return ( ( c & 0xC0 ) == 0x80 ) ?
( c & 0x3F ) : UTF8_DECODE_ERROR;
}
22. By now, we have the font loading functions and a UTF-8 decoder. Now it is time to
deal with the actual rendering. The irst thing we want to do is calculate the string size
in screen pixels, which is performed in the
CalculateLineParameters
function:
void CalculateLineParameters(
int* Width, int* MinY, int* MaxY, int* BaseLine ) const
{
23. We use two variables to look for the minimum and maximum vertical positions:
int StrMinY = -1000, StrMaxY = -1000;
if ( FString.empty() )
StrMinY = StrMaxY = 0;