diff --git a/include/wx/font.h b/include/wx/font.h index f0e4473fe0..a022aba730 100644 --- a/include/wx/font.h +++ b/include/wx/font.h @@ -246,6 +246,27 @@ public: return f; } + // Another helper for converting arbitrary numeric weight to the closest + // value of wxFontWeight enum. It should be avoided in the new code (also + // note that the function for the conversion in the other direction is + // trivial and so is not provided, we only have GetNumericWeightOf() which + // contains backwards compatibility hacks, but we don't need it here). + static wxFontWeight GetWeightClosestToNumericValue(int numWeight) + { + wxASSERT(numWeight > 0); + wxASSERT(numWeight <= 1000); + + // round to nearest hundredth = wxFONTWEIGHT_ constant + int weight = ((numWeight + 50) / 100) * 100; + + if (weight < wxFONTWEIGHT_THIN) + weight = wxFONTWEIGHT_THIN; + if (weight > wxFONTWEIGHT_MAX) + weight = wxFONTWEIGHT_MAX; + + return static_cast(weight); + } + private: void Init() { @@ -444,7 +465,6 @@ public: // Convert between symbolic and numeric font weights. static int GetNumericWeightOf(wxFontWeight weight); - static wxFontWeight GetWeightClosestToNumericValue(int numWeight); // this doesn't do anything and is kept for compatibility only #if WXWIN_COMPATIBILITY_2_8 diff --git a/interface/wx/font.h b/interface/wx/font.h index 13dcde5492..287c65f16e 100644 --- a/interface/wx/font.h +++ b/interface/wx/font.h @@ -428,6 +428,18 @@ public: See ::wxFontFlag for the various flags that can be used. */ wxFontInfo& AllFlags(int flags); + + /** + Get the symbolic weight closest to the given raw weight value. + + @param numWeight + A valid raw weight value, i.e. a value in the range 1 to 1000, + inclusive. + @return A valid element of wxFontWeight enum. + + @since 3.1.2 + */ + static wxFontWeight GetWeightClosestToNumericValue(int numWeight); }; /** @@ -1244,18 +1256,6 @@ public: */ static int GetNumericWeightOf(wxFontWeight weight); - /** - Get the symbolic weight closest to the given raw weight value. - - @param numWeight - A valid raw weight value, i.e. a value in the range 1 to 1000, - inclusive. - @return A valid element of wxFontWeight enum. - - @since 3.1.2 - */ - static wxFontWeight GetWeightClosestToNumericValue(int numWeight); - //@{ /** This function takes the same parameters as the relative diff --git a/src/common/fontcmn.cpp b/src/common/fontcmn.cpp index 998c3c1caa..bd279a46fb 100644 --- a/src/common/fontcmn.cpp +++ b/src/common/fontcmn.cpp @@ -258,26 +258,6 @@ int wxFontBase::GetNumericWeightOf(wxFontWeight weight) return weight; } -// As its name indicates, this function returns the closest wxFontWeight enum -// element, even if its value doesn't correspond to the given weight exactly. -/* static */ -wxFontWeight wxFontBase::GetWeightClosestToNumericValue(int numWeight) -{ - wxASSERT(numWeight > 0); - wxASSERT(numWeight <= 1000); - - // round to nearest hundredth = wxFONTWEIGHT_ constant - int weight = ((numWeight + 50) / 100) * 100; - - if (weight < wxFONTWEIGHT_THIN) - weight = wxFONTWEIGHT_THIN; - if (weight > wxFONTWEIGHT_MAX) - weight = wxFONTWEIGHT_MAX; - - return static_cast(weight); -} - - int wxFontBase::GetPointSize() const { return wxFontInfo::ToIntPointSize(GetFractionalPointSize()); @@ -295,7 +275,7 @@ wxFontWeight wxFontBase::GetWeight() const { wxCHECK_MSG( IsOk(), wxFONTWEIGHT_MAX, "invalid font" ); - return GetWeightClosestToNumericValue(GetNumericWeight()); + return wxFontInfo::GetWeightClosestToNumericValue(GetNumericWeight()); } bool wxFontBase::IsUsingSizeInPixels() const @@ -1324,7 +1304,7 @@ bool wxNativeFontInfo::FromUserString(const wxString& s) wxFontWeight wxNativeFontInfo::GetWeight() const { - return wxFontBase::GetWeightClosestToNumericValue(GetNumericWeight()); + return wxFontInfo::GetWeightClosestToNumericValue(GetNumericWeight()); } void wxNativeFontInfo::SetWeight(wxFontWeight weight) diff --git a/src/unix/fontutil.cpp b/src/unix/fontutil.cpp index 54df3a3a0c..ca365f5084 100644 --- a/src/unix/fontutil.cpp +++ b/src/unix/fontutil.cpp @@ -826,7 +826,7 @@ void wxNativeFontInfo::SetStyle(wxFontStyle style) void wxNativeFontInfo::SetNumericWeight(int weight) { wxString s; - switch ( wxFont::GetWeightClosestToNumericValue(weight) ) + switch ( wxFontInfo::GetWeightClosestToNumericValue(weight) ) { case wxFONTWEIGHT_THIN: s = "thin";