Add wxFont::SetFractionalPointSize()
Changing SetPointSize() argument type from int to float wasn't 100% backwards-compatible as it notably started resulting in warnings (from at least MSVC) about conversions from int to float in the existing code. To avoid these warnings and for symmetry with GetFractionalPointSize(), add SetFractionalPointSize() taking float argument and preserve the argument of type int in SetPointSize() for compatibility. SetPointSize() is now just a wrapper forwarding to the more general SetFractionalPointSize(). Notice that the other ports still remain broken, this commit only updates the currently working wxGTK, wxMac and wxMSW.
This commit is contained in:
@@ -368,7 +368,8 @@ public:
|
||||
wxString GetNativeFontInfoUserDesc() const;
|
||||
|
||||
// change the font characteristics
|
||||
virtual void SetPointSize( float pointSize ) = 0;
|
||||
virtual void SetPointSize( int pointSize );
|
||||
virtual void SetFractionalPointSize( float pointSize ) = 0;
|
||||
virtual void SetPixelSize( const wxSize& pixelSize );
|
||||
virtual void SetFamily( wxFontFamily family ) = 0;
|
||||
virtual void SetStyle( wxFontStyle style ) = 0;
|
||||
|
@@ -74,7 +74,7 @@ public:
|
||||
virtual const wxNativeFontInfo *GetNativeFontInfo() const wxOVERRIDE;
|
||||
virtual bool IsFixedWidth() const wxOVERRIDE;
|
||||
|
||||
virtual void SetPointSize(float pointSize) wxOVERRIDE;
|
||||
virtual void SetFractionalPointSize(float pointSize) wxOVERRIDE;
|
||||
virtual void SetFamily(wxFontFamily family) wxOVERRIDE;
|
||||
virtual void SetStyle(wxFontStyle style) wxOVERRIDE;
|
||||
virtual void SetNumericWeight(int weight) wxOVERRIDE;
|
||||
|
@@ -96,7 +96,7 @@ public:
|
||||
virtual wxFontEncoding GetEncoding() const wxOVERRIDE;
|
||||
virtual const wxNativeFontInfo *GetNativeFontInfo() const wxOVERRIDE;
|
||||
|
||||
virtual void SetPointSize(float pointSize) wxOVERRIDE;
|
||||
virtual void SetFractionalPointSize(float pointSize) wxOVERRIDE;
|
||||
virtual void SetPixelSize(const wxSize& pixelSize) wxOVERRIDE;
|
||||
virtual void SetFamily(wxFontFamily family) wxOVERRIDE;
|
||||
virtual void SetStyle(wxFontStyle style) wxOVERRIDE;
|
||||
|
@@ -131,7 +131,7 @@ public:
|
||||
|
||||
virtual bool IsFixedWidth() const wxOVERRIDE;
|
||||
|
||||
virtual void SetPointSize(float pointSize) wxOVERRIDE;
|
||||
virtual void SetFractionalPointSize(float pointSize) wxOVERRIDE;
|
||||
virtual void SetFamily(wxFontFamily family) wxOVERRIDE;
|
||||
virtual void SetStyle(wxFontStyle style) wxOVERRIDE;
|
||||
virtual void SetNumericWeight(int weight) wxOVERRIDE;
|
||||
|
@@ -1062,19 +1062,29 @@ public:
|
||||
void SetNativeFontInfo(const wxNativeFontInfo& info);
|
||||
|
||||
/**
|
||||
Sets the point size.
|
||||
Sets the font size in points to an integer value.
|
||||
|
||||
This is a legacy version of the function only supporting integer point
|
||||
sizes. It can still be used, but to avoid unnecessarily restricting the
|
||||
font size in points to integer values, consider using the new (added in
|
||||
wxWidgets 3.1.2) SetFractionalPointSize() function instead.
|
||||
*/
|
||||
virtual void SetPointSize(int pointSize);
|
||||
|
||||
/**
|
||||
Sets the font size in points.
|
||||
|
||||
The <em>point size</em> is defined as 1/72 of the Anglo-Saxon inch
|
||||
(25.4 mm): it is approximately 0.0139 inch or 352.8 um.
|
||||
|
||||
@param pointSize
|
||||
Size in points. This can also be a fractional point size like 11.5.
|
||||
Note that until wxWidgets 3.1.2, the size had to be an integer number
|
||||
(and the type of this parameter was @c int).
|
||||
|
||||
@see GetPointSize()
|
||||
@see GetFractionalPointSize(), SetPointSize()
|
||||
|
||||
@since 3.1.2
|
||||
*/
|
||||
virtual void SetPointSize(float pointSize);
|
||||
virtual void SetFractionalPointSize(float pointSize);
|
||||
|
||||
/**
|
||||
Sets the pixel size.
|
||||
|
@@ -45,6 +45,8 @@
|
||||
|
||||
#include "wx/tokenzr.h"
|
||||
|
||||
#include <float.h> // for FLT_MAX
|
||||
|
||||
// debugger helper: this function can be called from a debugger to show what
|
||||
// the date really is
|
||||
extern const char *wxDumpFont(const wxFont *font)
|
||||
@@ -306,6 +308,14 @@ bool wxFontBase::IsUsingSizeInPixels() const
|
||||
return false;
|
||||
}
|
||||
|
||||
void wxFontBase::SetPointSize(int pointSize)
|
||||
{
|
||||
wxCHECK_RET( pointSize >= 0 && static_cast<float>(pointSize) < FLT_MAX,
|
||||
"Invalid font point size" );
|
||||
|
||||
SetFractionalPointSize(static_cast<float>(pointSize));
|
||||
}
|
||||
|
||||
void wxFontBase::SetPixelSize( const wxSize& pixelSize )
|
||||
{
|
||||
wxCHECK_RET( pixelSize.GetWidth() >= 0 && pixelSize.GetHeight() > 0,
|
||||
|
@@ -65,7 +65,7 @@ public:
|
||||
|
||||
// setters: all of them also take care to modify m_nativeFontInfo if we
|
||||
// have it so as to not lose the information not carried by our fields
|
||||
void SetPointSize(float pointSize);
|
||||
void SetFractionalPointSize(float pointSize);
|
||||
void SetFamily(wxFontFamily family);
|
||||
void SetStyle(wxFontStyle style);
|
||||
void SetWeight(wxFontWeight weight);
|
||||
@@ -133,7 +133,8 @@ void wxFontRefData::Init(int pointSize,
|
||||
}
|
||||
|
||||
SetStyle( style );
|
||||
SetPointSize( pointSize == -1 ? wxDEFAULT_FONT_SIZE : pointSize );
|
||||
m_nativeFontInfo.SetPointSize( pointSize == -1 ? wxDEFAULT_FONT_SIZE
|
||||
: pointSize );
|
||||
SetWeight( weight );
|
||||
SetUnderlined( underlined );
|
||||
SetStrikethrough( strikethrough );
|
||||
@@ -179,7 +180,7 @@ wxFontRefData::~wxFontRefData()
|
||||
// wxFontRefData SetXXX()
|
||||
// ----------------------------------------------------------------------------
|
||||
|
||||
void wxFontRefData::SetPointSize(float pointSize)
|
||||
void wxFontRefData::SetFractionalPointSize(float pointSize)
|
||||
{
|
||||
m_nativeFontInfo.SetFractionalPointSize(pointSize);
|
||||
}
|
||||
@@ -409,11 +410,11 @@ bool wxFont::IsFixedWidth() const
|
||||
// change font attributes
|
||||
// ----------------------------------------------------------------------------
|
||||
|
||||
void wxFont::SetPointSize(float pointSize)
|
||||
void wxFont::SetFractionalPointSize(float pointSize)
|
||||
{
|
||||
AllocExclusive();
|
||||
|
||||
M_FONTDATA->SetPointSize(pointSize);
|
||||
M_FONTDATA->SetFractionalPointSize(pointSize);
|
||||
}
|
||||
|
||||
void wxFont::SetFamily(wxFontFamily family)
|
||||
|
@@ -176,7 +176,7 @@ public:
|
||||
// ... and setters: notice that all of them invalidate the currently
|
||||
// allocated HFONT, if any, so that the next call to GetHFONT() recreates a
|
||||
// new one
|
||||
void SetPointSize(float pointSize)
|
||||
void SetFractionalPointSize(float pointSize)
|
||||
{
|
||||
Free();
|
||||
|
||||
@@ -357,9 +357,15 @@ void wxFontRefData::Init(int pointSize,
|
||||
|
||||
m_sizeUsingPixels = sizeUsingPixels;
|
||||
if ( m_sizeUsingPixels )
|
||||
SetPixelSize(pixelSize);
|
||||
{
|
||||
m_nativeFontInfo.SetPixelSize(pixelSize);
|
||||
}
|
||||
else
|
||||
SetPointSize(pointSize == -1 ? wxNORMAL_FONT->GetPointSize() : pointSize);
|
||||
{
|
||||
m_nativeFontInfo.SetPointSize(pointSize == -1
|
||||
? wxNORMAL_FONT->GetPointSize()
|
||||
: pointSize);
|
||||
}
|
||||
|
||||
SetStyle(style);
|
||||
m_nativeFontInfo.SetWeight(weight);
|
||||
@@ -877,12 +883,12 @@ bool wxFont::IsFree() const
|
||||
// change font attribute: we recreate font when doing it
|
||||
// ----------------------------------------------------------------------------
|
||||
|
||||
void wxFont::SetPointSize(float pointSize)
|
||||
void wxFont::SetFractionalPointSize(float pointSize)
|
||||
{
|
||||
AllocExclusive();
|
||||
|
||||
M_FONTDATA->Free();
|
||||
M_FONTDATA->SetPointSize(pointSize);
|
||||
M_FONTDATA->SetFractionalPointSize(pointSize);
|
||||
}
|
||||
|
||||
void wxFont::SetPixelSize(const wxSize& pixelSize)
|
||||
|
@@ -92,7 +92,7 @@ public:
|
||||
|
||||
const wxNativeFontInfo& GetNativeFontInfo() const;
|
||||
|
||||
void SetPointSize(float size)
|
||||
void SetFractionalPointSize(float size)
|
||||
{
|
||||
if (GetFractionalPointSize() != size)
|
||||
{
|
||||
@@ -300,7 +300,8 @@ void wxFontRefData::Init(float size,
|
||||
SetFaceName(faceName);
|
||||
else
|
||||
SetFamily(family);
|
||||
SetPointSize(size < 0 ? wxNORMAL_FONT->GetFractionalPointSize() : size);
|
||||
|
||||
SetFractionalPointSize(size < 0 ? wxNORMAL_FONT->GetFractionalPointSize() : size);
|
||||
SetNumericWeight(weight);
|
||||
SetStyle(style);
|
||||
SetUnderlined(underlined);
|
||||
@@ -613,14 +614,11 @@ wxGDIRefData* wxFont::CloneGDIRefData(const wxGDIRefData* data) const
|
||||
return new wxFontRefData(*static_cast<const wxFontRefData*>(data));
|
||||
}
|
||||
|
||||
void wxFont::SetPointSize(float pointSize)
|
||||
void wxFont::SetFractionalPointSize(float pointSize)
|
||||
{
|
||||
if (IsOk() && M_FONTDATA->GetFractionalPointSize() == pointSize)
|
||||
return;
|
||||
|
||||
AllocExclusive();
|
||||
|
||||
M_FONTDATA->SetPointSize(pointSize);
|
||||
M_FONTDATA->SetFractionalPointSize(pointSize);
|
||||
}
|
||||
|
||||
void wxFont::SetFamily(wxFontFamily family)
|
||||
|
Reference in New Issue
Block a user