- let the 3 relevant text functions handle UTF-8 strings

These functions are: DCanvas::DrawTextCommon, V_BreakLines and FFont::StringWidth.
This will allow strings from UTF-8 encoded assets to display properly, but also handle the OpenAL device name on international systems, as this will be returned as an UTF-8 string.

Due to backwards compatibility needs the decoding function is rather lax to allow both UTF-8 and ISO 8859-1 to pass through correctly - and this also implies that it will allow mixed encodings which may happen if strings from different sources get concatenated.
This commit is contained in:
Christoph Oelckers 2017-12-02 21:21:57 +01:00
commit cc54db6e6d
3 changed files with 81 additions and 7 deletions

View file

@ -890,9 +890,10 @@ int FFont::StringWidth(const uint8_t *string) const
while (*string)
{
if (*string == TEXTCOLOR_ESCAPE)
auto chr = GetCharFromString(string);
if (chr == TEXTCOLOR_ESCAPE)
{
++string;
// We do not need to check for UTF-8 in here.
if (*string == '[')
{
while (*string != '\0' && *string != ']')
@ -906,16 +907,15 @@ int FFont::StringWidth(const uint8_t *string) const
}
continue;
}
else if (*string == '\n')
else if (chr == '\n')
{
if (w > maxw)
maxw = w;
w = 0;
++string;
}
else
{
w += GetCharWidth(*string++) + GlobalKerning;
w += GetCharWidth(chr) + GlobalKerning;
}
}