Move GetWeightClosestToNumericValue() to wxFontInfo too
This is similar to a recent commit which moved float to int point size conversions to wxFontInfo and is done for the same reasons: wxFont and wxNativeFontInfo can depend on wxFontInfo, but the converse is not true. No real changes.
This commit is contained in:
@@ -246,6 +246,27 @@ public:
|
|||||||
return f;
|
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<wxFontWeight>(weight);
|
||||||
|
}
|
||||||
|
|
||||||
private:
|
private:
|
||||||
void Init()
|
void Init()
|
||||||
{
|
{
|
||||||
@@ -444,7 +465,6 @@ public:
|
|||||||
|
|
||||||
// Convert between symbolic and numeric font weights.
|
// Convert between symbolic and numeric font weights.
|
||||||
static int GetNumericWeightOf(wxFontWeight weight);
|
static int GetNumericWeightOf(wxFontWeight weight);
|
||||||
static wxFontWeight GetWeightClosestToNumericValue(int numWeight);
|
|
||||||
|
|
||||||
// this doesn't do anything and is kept for compatibility only
|
// this doesn't do anything and is kept for compatibility only
|
||||||
#if WXWIN_COMPATIBILITY_2_8
|
#if WXWIN_COMPATIBILITY_2_8
|
||||||
|
@@ -428,6 +428,18 @@ public:
|
|||||||
See ::wxFontFlag for the various flags that can be used.
|
See ::wxFontFlag for the various flags that can be used.
|
||||||
*/
|
*/
|
||||||
wxFontInfo& AllFlags(int flags);
|
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);
|
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
|
This function takes the same parameters as the relative
|
||||||
|
@@ -258,26 +258,6 @@ int wxFontBase::GetNumericWeightOf(wxFontWeight weight)
|
|||||||
return 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<wxFontWeight>(weight);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
int wxFontBase::GetPointSize() const
|
int wxFontBase::GetPointSize() const
|
||||||
{
|
{
|
||||||
return wxFontInfo::ToIntPointSize(GetFractionalPointSize());
|
return wxFontInfo::ToIntPointSize(GetFractionalPointSize());
|
||||||
@@ -295,7 +275,7 @@ wxFontWeight wxFontBase::GetWeight() const
|
|||||||
{
|
{
|
||||||
wxCHECK_MSG( IsOk(), wxFONTWEIGHT_MAX, "invalid font" );
|
wxCHECK_MSG( IsOk(), wxFONTWEIGHT_MAX, "invalid font" );
|
||||||
|
|
||||||
return GetWeightClosestToNumericValue(GetNumericWeight());
|
return wxFontInfo::GetWeightClosestToNumericValue(GetNumericWeight());
|
||||||
}
|
}
|
||||||
|
|
||||||
bool wxFontBase::IsUsingSizeInPixels() const
|
bool wxFontBase::IsUsingSizeInPixels() const
|
||||||
@@ -1324,7 +1304,7 @@ bool wxNativeFontInfo::FromUserString(const wxString& s)
|
|||||||
|
|
||||||
wxFontWeight wxNativeFontInfo::GetWeight() const
|
wxFontWeight wxNativeFontInfo::GetWeight() const
|
||||||
{
|
{
|
||||||
return wxFontBase::GetWeightClosestToNumericValue(GetNumericWeight());
|
return wxFontInfo::GetWeightClosestToNumericValue(GetNumericWeight());
|
||||||
}
|
}
|
||||||
|
|
||||||
void wxNativeFontInfo::SetWeight(wxFontWeight weight)
|
void wxNativeFontInfo::SetWeight(wxFontWeight weight)
|
||||||
|
@@ -826,7 +826,7 @@ void wxNativeFontInfo::SetStyle(wxFontStyle style)
|
|||||||
void wxNativeFontInfo::SetNumericWeight(int weight)
|
void wxNativeFontInfo::SetNumericWeight(int weight)
|
||||||
{
|
{
|
||||||
wxString s;
|
wxString s;
|
||||||
switch ( wxFont::GetWeightClosestToNumericValue(weight) )
|
switch ( wxFontInfo::GetWeightClosestToNumericValue(weight) )
|
||||||
{
|
{
|
||||||
case wxFONTWEIGHT_THIN:
|
case wxFONTWEIGHT_THIN:
|
||||||
s = "thin";
|
s = "thin";
|
||||||
|
Reference in New Issue
Block a user