diff --git a/src/common/fonts/font.cpp b/src/common/fonts/font.cpp index 6ba5046fc0..148631670f 100644 --- a/src/common/fonts/font.cpp +++ b/src/common/fonts/font.cpp @@ -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 maxw = 0; @@ -1123,13 +1123,17 @@ int FFont::StringWidth(const uint8_t *string) const maxw = w; w = 0; } + else if (spacing >= 0) + { + w += GetCharWidth(chr) + GlobalKerning + spacing; + } else { - w += GetCharWidth(chr) + GlobalKerning; + w -= spacing; } } - return MAX(maxw, w); + return std::max(maxw, w); } //========================================================================== diff --git a/src/common/fonts/v_font.h b/src/common/fonts/v_font.h index 41fabb0967..71ba99ed75 100644 --- a/src/common/fonts/v_font.h +++ b/src/common/fonts/v_font.h @@ -113,9 +113,9 @@ public: static FFont *FindFont(FName fontname); // Return width of string in pixels (unscaled) - int StringWidth (const uint8_t *str) const; - inline int StringWidth (const char *str) const { return StringWidth ((const uint8_t *)str); } - inline int StringWidth (const FString &str) const { return StringWidth ((const uint8_t *)str.GetChars()); } + int StringWidth (const uint8_t *str, int spacing = 0) const; + inline int StringWidth (const char *str, int spacing = 0) const { return StringWidth ((const uint8_t *)str, spacing); } + 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. bool CanPrint(const uint8_t *str) const; diff --git a/src/g_statusbar/shared_sbar.cpp b/src/g_statusbar/shared_sbar.cpp index e7108e512c..e9282b72aa 100644 --- a/src/g_statusbar/shared_sbar.cpp +++ b/src/g_statusbar/shared_sbar.cpp @@ -1670,20 +1670,17 @@ void DBaseStatusBar::DrawString(FFont *font, const FString &cstring, double x, d { bool monospaced = monospacing != EMonospacing::Off; double dx = 0; + int spacingparm = monospaced ? -spacing : spacing; switch (flags & DI_TEXT_ALIGN) { default: break; case DI_TEXT_ALIGN_RIGHT: - dx = monospaced - ? static_cast ((spacing)*cstring.CharacterCount()) //monospaced, so just multiply the character size - : static_cast (font->StringWidth(cstring) + (spacing * cstring.CharacterCount())); + dx = font->StringWidth(cstring, spacingparm); break; case DI_TEXT_ALIGN_CENTER: - dx = monospaced - ? static_cast ((spacing)*cstring.CharacterCount()) / 2 //monospaced, so just multiply the character size - : static_cast (font->StringWidth(cstring) + (spacing * cstring.CharacterCount())) / 2; + dx = font->StringWidth(cstring, spacingparm) / 2; break; }