From c1fb982a0723fd4221cebd6bc9bb58aac130fc06 Mon Sep 17 00:00:00 2001 From: Brian Date: Fri, 23 Dec 2022 22:40:36 -0700 Subject: [PATCH] String meter: Allow floating font sizes FontSize and InlineSetting=Size --- Common/Gfx/TextFormat.h | 2 +- Common/Gfx/TextFormatD2D.cpp | 4 ++-- Common/Gfx/TextFormatD2D.h | 2 +- Library/MeterString.cpp | 10 +++++----- Library/MeterString.h | 2 +- 5 files changed, 10 insertions(+), 10 deletions(-) diff --git a/Common/Gfx/TextFormat.h b/Common/Gfx/TextFormat.h index 830afd1b7..c43d334c5 100644 --- a/Common/Gfx/TextFormat.h +++ b/Common/Gfx/TextFormat.h @@ -43,7 +43,7 @@ class __declspec(novtable) TextFormat // Sets the logical properties of the font to use. If the font is not found in the system font // collection, the given |fontCollection| is also searched. |fontCollection| may be nullptr. virtual void SetProperties( - const WCHAR* fontFamily, int size, bool bold, bool italic, + const WCHAR* fontFamily, FLOAT size, bool bold, bool italic, const FontCollection* fontCollection) = 0; // Sets the font weight of the font used. |weight| should be between 1-999. diff --git a/Common/Gfx/TextFormatD2D.cpp b/Common/Gfx/TextFormatD2D.cpp index ef1ed0be2..d65f0d731 100644 --- a/Common/Gfx/TextFormatD2D.cpp +++ b/Common/Gfx/TextFormatD2D.cpp @@ -191,7 +191,7 @@ bool TextFormatD2D::CreateLayout(ID2D1DeviceContext* target, const std::wstring& } void TextFormatD2D::SetProperties( - const WCHAR* fontFamily, int size, bool bold, bool italic, + const WCHAR* fontFamily, FLOAT size, bool bold, bool italic, const FontCollection* fontCollection) { auto fontCollectionD2D = (FontCollectionD2D*)fontCollection; @@ -706,7 +706,7 @@ bool TextFormatD2D::CreateInlineOption(const size_t index, const std::wstring pa { if (optSize > 1) { - FLOAT size = (FLOAT)ConfigParser::ParseInt(options[1].c_str(), 0); + FLOAT size = (FLOAT)ConfigParser::ParseDouble(options[1].c_str(), 10.0); UpdateInlineSize(index, pattern, size); return true; } diff --git a/Common/Gfx/TextFormatD2D.h b/Common/Gfx/TextFormatD2D.h index 52db0a703..5e93aa507 100644 --- a/Common/Gfx/TextFormatD2D.h +++ b/Common/Gfx/TextFormatD2D.h @@ -32,7 +32,7 @@ class TextFormatD2D : public TextFormat virtual bool IsInitialized() const override { return m_TextFormat != nullptr; } virtual void SetProperties( - const WCHAR* fontFamily, int size, bool bold, bool italic, + const WCHAR* fontFamily, FLOAT size, bool bold, bool italic, const FontCollection* fontCollection) override; virtual void SetFontWeight(int weight) override; diff --git a/Library/MeterString.cpp b/Library/MeterString.cpp index cfbf8bf58..9425ee6e7 100644 --- a/Library/MeterString.cpp +++ b/Library/MeterString.cpp @@ -21,7 +21,7 @@ MeterString::MeterString(Skin* skin, const WCHAR* name) : Meter(skin, name), m_Style(NORMAL), m_Effect(EFFECT_NONE), m_Case(TEXTCASE_NONE), - m_FontSize(10), + m_FontSize(10.0f), m_Scale(1.0), m_NoDecimals(true), m_Percentual(true), @@ -117,7 +117,7 @@ void MeterString::ReadOptions(ConfigParser& parser, const WCHAR* section) { // Store the current font values so we know if the font needs to be updated std::wstring oldFontFace = m_FontFace; - int oldFontSize = m_FontSize; + FLOAT oldFontSize = m_FontSize; TEXTSTYLE oldStyle = m_Style; Gfx::HorizontalAlignment oldHAlign = m_TextFormat->GetHorizontalAlignment(); Gfx::VerticalAlignment oldVAlign = m_TextFormat->GetVerticalAlignment(); @@ -161,10 +161,10 @@ void MeterString::ReadOptions(ConfigParser& parser, const WCHAR* section) m_FontFace = L"Arial"; } - m_FontSize = parser.ReadInt(section, L"FontSize", 10); - if (m_FontSize < 0) + m_FontSize = (FLOAT)parser.ReadFloat(section, L"FontSize", 10.0); + if (m_FontSize < 0.0f) { - m_FontSize = 10; + m_FontSize = 10.0f; } m_NumOfDecimals = parser.ReadInt(section, L"NumOfDecimals", -1); diff --git a/Library/MeterString.h b/Library/MeterString.h index 86c11f745..6a90bcc20 100644 --- a/Library/MeterString.h +++ b/Library/MeterString.h @@ -82,7 +82,7 @@ class MeterString : public Meter TEXTSTYLE m_Style; TEXTEFFECT m_Effect; TEXTCASE m_Case; - int m_FontSize; + FLOAT m_FontSize; double m_Scale; bool m_NoDecimals; bool m_Percentual;