From 4ada99945f34422e69efd59ca91d136517f50cba Mon Sep 17 00:00:00 2001 From: Vadim Zeitlin Date: Sat, 15 Sep 2018 13:07:17 +0200 Subject: [PATCH] Extract ConvertFromLegacyWeightIfNecessary() function Make it possible to reuse just this part of GetNumericWeightOf() in the upcoming commit. --- include/wx/font.h | 9 ++++++++- src/common/fontcmn.cpp | 24 ++++++++++++------------ 2 files changed, 20 insertions(+), 13 deletions(-) diff --git a/include/wx/font.h b/include/wx/font.h index 2e2281c530..ef9bf45c71 100644 --- a/include/wx/font.h +++ b/include/wx/font.h @@ -491,7 +491,14 @@ public: static wxFontEncoding GetDefaultEncoding() { return ms_encodingDefault; } static void SetDefaultEncoding(wxFontEncoding encoding); - // Convert between symbolic and numeric font weights. + // Account for legacy font weight values: if the argument is one of + // wxNORMAL, wxLIGHT or wxBOLD, return the corresponding wxFONTWEIGHT_XXX + // enum value. Otherwise just return it unchanged. + static int ConvertFromLegacyWeightIfNecessary(int weight); + + // Convert between symbolic and numeric font weights. This function uses + // ConvertFromLegacyWeightIfNecessary(), so takes legacy values into + // account as well. static int GetNumericWeightOf(wxFontWeight weight); // this doesn't do anything and is kept for compatibility only diff --git a/src/common/fontcmn.cpp b/src/common/fontcmn.cpp index dc865ceb86..cef604180a 100644 --- a/src/common/fontcmn.cpp +++ b/src/common/fontcmn.cpp @@ -226,22 +226,22 @@ bool wxFontBase::IsFixedWidth() const // Convert to/from wxFontWeight enum elements and numeric weight values. -// This function interprets wxNORMAL, wxLIGHT and wxBOLD values in addition to -// the actual wxFontWeight enum element values for compatibility. It does check -// that it gets either the one or the other. /* static */ -int wxFontBase::GetNumericWeightOf(wxFontWeight weight) +int wxFontBase::ConvertFromLegacyWeightIfNecessary(int weight) { - // deal with compatibility constants - if (weight >= 90 && weight <= 92) + switch ( weight ) { - if (weight == 90 /* wxNORMAL */) - weight = wxFONTWEIGHT_NORMAL; - else if (weight == 91 /* wxLIGHT */) - weight = wxFONTWEIGHT_LIGHT; - else if (weight == 92 /* wxBOLD */) - weight = wxFONTWEIGHT_BOLD; + case 90: return wxFONTWEIGHT_NORMAL; + case 91: return wxFONTWEIGHT_LIGHT; + case 92: return wxFONTWEIGHT_BOLD; + default: return weight; } +} + +/* static */ +int wxFontBase::GetNumericWeightOf(wxFontWeight weight_) +{ + const int weight = ConvertFromLegacyWeightIfNecessary(weight_); wxASSERT(weight > wxFONTWEIGHT_INVALID); wxASSERT(weight <= wxFONTWEIGHT_MAX);