From 9ca1e43292eb5f13061da662f71e56b2bdc40750 Mon Sep 17 00:00:00 2001 From: Christoph Oelckers Date: Mon, 13 Apr 2020 12:11:14 +0200 Subject: [PATCH] - 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. # Conflicts: # src/common/fonts/font.cpp --- src/g_statusbar/shared_sbar.cpp | 9 +++------ src/v_font.cpp | 10 +++++++--- src/v_font.h | 6 +++--- 3 files changed, 13 insertions(+), 12 deletions(-) diff --git a/src/g_statusbar/shared_sbar.cpp b/src/g_statusbar/shared_sbar.cpp index b986aae5b..271bbe057 100644 --- a/src/g_statusbar/shared_sbar.cpp +++ b/src/g_statusbar/shared_sbar.cpp @@ -1556,20 +1556,17 @@ void DBaseStatusBar::DrawString(FFont *font, const FString &cstring, double x, d { bool monospaced = monospacing != EMonospacing::MOff; 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; } diff --git a/src/v_font.cpp b/src/v_font.cpp index edfaa0022..c65bc4bc4 100644 --- a/src/v_font.cpp +++ b/src/v_font.cpp @@ -1777,7 +1777,7 @@ double GetBottomAlignOffset(FFont *font, int c) // //========================================================================== -int FFont::StringWidth(const uint8_t *string) const +int FFont::StringWidth(const uint8_t *string, int spacing) const { int w = 0; int maxw = 0; @@ -1807,13 +1807,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/v_font.h b/src/v_font.h index 370119958..fa9365436 100644 --- a/src/v_font.h +++ b/src/v_font.h @@ -112,9 +112,9 @@ public: static void StaticPreloadFonts(); // 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); } inline bool CanPrint(const uint8_t *str) const { return true; } // hack hack