- fixed text size calculations in the status bar.

To avoid errors, all spacing calculations have been added to FFont::StringWidth which already performs proper escape filtering.
This commit is contained in:
Christoph Oelckers 2020-04-13 12:11:14 +02:00
parent 17df95d69e
commit 9a3b663e04
3 changed files with 13 additions and 12 deletions

View file

@ -1093,7 +1093,7 @@ bool FFont::CanPrint(const uint8_t *string) const
// //
//========================================================================== //==========================================================================
int FFont::StringWidth(const uint8_t *string) const int FFont::StringWidth(const uint8_t *string, int spacing) const
{ {
int w = 0; int w = 0;
int maxw = 0; int maxw = 0;
@ -1123,13 +1123,17 @@ int FFont::StringWidth(const uint8_t *string) const
maxw = w; maxw = w;
w = 0; w = 0;
} }
else if (spacing >= 0)
{
w += GetCharWidth(chr) + GlobalKerning + spacing;
}
else else
{ {
w += GetCharWidth(chr) + GlobalKerning; w -= spacing;
} }
} }
return MAX(maxw, w); return std::max(maxw, w);
} }
//========================================================================== //==========================================================================

View file

@ -113,9 +113,9 @@ public:
static FFont *FindFont(FName fontname); static FFont *FindFont(FName fontname);
// Return width of string in pixels (unscaled) // Return width of string in pixels (unscaled)
int StringWidth (const uint8_t *str) const; int StringWidth (const uint8_t *str, int spacing = 0) const;
inline int StringWidth (const char *str) const { return StringWidth ((const uint8_t *)str); } inline int StringWidth (const char *str, int spacing = 0) const { return StringWidth ((const uint8_t *)str, spacing); }
inline int StringWidth (const FString &str) const { return StringWidth ((const uint8_t *)str.GetChars()); } inline int StringWidth (const FString &str, int spacing = 0) const { return StringWidth ((const uint8_t *)str.GetChars(), spacing); }
// Checks if the font contains all characters to print this text. // Checks if the font contains all characters to print this text.
bool CanPrint(const uint8_t *str) const; bool CanPrint(const uint8_t *str) const;

View file

@ -1670,20 +1670,17 @@ void DBaseStatusBar::DrawString(FFont *font, const FString &cstring, double x, d
{ {
bool monospaced = monospacing != EMonospacing::Off; bool monospaced = monospacing != EMonospacing::Off;
double dx = 0; double dx = 0;
int spacingparm = monospaced ? -spacing : spacing;
switch (flags & DI_TEXT_ALIGN) switch (flags & DI_TEXT_ALIGN)
{ {
default: default:
break; break;
case DI_TEXT_ALIGN_RIGHT: case DI_TEXT_ALIGN_RIGHT:
dx = monospaced dx = font->StringWidth(cstring, spacingparm);
? static_cast<int> ((spacing)*cstring.CharacterCount()) //monospaced, so just multiply the character size
: static_cast<int> (font->StringWidth(cstring) + (spacing * cstring.CharacterCount()));
break; break;
case DI_TEXT_ALIGN_CENTER: case DI_TEXT_ALIGN_CENTER:
dx = monospaced dx = font->StringWidth(cstring, spacingparm) / 2;
? static_cast<int> ((spacing)*cstring.CharacterCount()) / 2 //monospaced, so just multiply the character size
: static_cast<int> (font->StringWidth(cstring) + (spacing * cstring.CharacterCount())) / 2;
break; break;
} }