Change fractional point size from float to double
There doesn't seem to be any compelling reason to use float. Using double is simpler, and avoids otherwise unnecessary float<->double conversions.
This commit is contained in:
@@ -129,22 +129,28 @@ public:
|
||||
// Default ctor uses the default font size appropriate for the current
|
||||
// platform.
|
||||
wxFontInfo()
|
||||
{ InitPointSize(-1.0f); }
|
||||
: m_pointSize(-1.0)
|
||||
, m_pixelSize(wxDefaultSize)
|
||||
{
|
||||
Init();
|
||||
}
|
||||
|
||||
// These ctors specify the font size, either in points or in pixels.
|
||||
// Point size is a floating point number, however we also accept all
|
||||
// integer sizes using the simple template ctor below.
|
||||
explicit wxFontInfo(float pointSize)
|
||||
{ InitPointSize(pointSize); }
|
||||
explicit wxFontInfo(const wxSize& pixelSize) : m_pixelSize(pixelSize)
|
||||
{ Init(); }
|
||||
|
||||
// Need to define this one to avoid casting double to int too.
|
||||
explicit wxFontInfo(double pointSize)
|
||||
{ InitPointSize(static_cast<float>(pointSize)); }
|
||||
template <typename T>
|
||||
explicit wxFontInfo(T pointSize)
|
||||
{ InitPointSize(ToFloatPointSize(pointSize)); }
|
||||
: m_pointSize(pointSize >= 0.0 ? pointSize : -1.0)
|
||||
, m_pixelSize(wxDefaultSize)
|
||||
{
|
||||
Init();
|
||||
if (!wxIsSameDouble(m_pointSize, pointSize))
|
||||
wxFAIL_MSG("Invalid font point size");
|
||||
}
|
||||
explicit wxFontInfo(const wxSize& pixelSize)
|
||||
: m_pointSize(-1.0)
|
||||
, m_pixelSize(pixelSize)
|
||||
{
|
||||
Init();
|
||||
}
|
||||
// Default copy ctor, assignment operator and dtor are OK
|
||||
|
||||
// Setters for the various attributes. All of them return the object itself
|
||||
// so that the calls to them could be chained.
|
||||
@@ -185,7 +191,6 @@ public:
|
||||
wxFontInfo& Encoding(wxFontEncoding encoding)
|
||||
{ m_encoding = encoding; return *this; }
|
||||
|
||||
|
||||
// Set all flags at once.
|
||||
wxFontInfo& AllFlags(int flags)
|
||||
{
|
||||
@@ -200,13 +205,12 @@ public:
|
||||
return *this;
|
||||
}
|
||||
|
||||
|
||||
// Accessors are mostly meant to be used by wxFont itself to extract the
|
||||
// various pieces of the font description.
|
||||
|
||||
bool IsUsingSizeInPixels() const { return m_pixelSize != wxDefaultSize; }
|
||||
float GetFractionalPointSize() const { return m_pointSize; }
|
||||
int GetPointSize() const { return ToIntPointSize(m_pointSize); }
|
||||
double GetFractionalPointSize() const { return m_pointSize; }
|
||||
int GetPointSize() const { return wxRound(m_pointSize); }
|
||||
wxSize GetPixelSize() const { return m_pixelSize; }
|
||||
|
||||
// If face name is not empty, it has priority, otherwise use family.
|
||||
@@ -250,28 +254,6 @@ public:
|
||||
|
||||
wxFontEncoding GetEncoding() const { return m_encoding; }
|
||||
|
||||
|
||||
// Default copy ctor, assignment operator and dtor are OK.
|
||||
|
||||
|
||||
// Helper functions for converting between integer and fractional sizes.
|
||||
static int ToIntPointSize(float pointSize) { return wxRound(pointSize); }
|
||||
static float ToFloatPointSize(int pointSize)
|
||||
{
|
||||
wxCHECK_MSG( pointSize == -1 || pointSize >= 0,
|
||||
-1, "Invalid font point size" );
|
||||
|
||||
// Huge values are not exactly representable as floats, so don't accept
|
||||
// those neither as they can only be due to a mistake anyhow: nobody
|
||||
// could possibly need a font of size 16777217pt (which is the first
|
||||
// value for which this fails).
|
||||
const float f = static_cast<float>(pointSize);
|
||||
wxCHECK_MSG( static_cast<int>(f) == pointSize,
|
||||
-1, "Font point size out of range" );
|
||||
|
||||
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
|
||||
@@ -296,21 +278,12 @@ public:
|
||||
private:
|
||||
void Init()
|
||||
{
|
||||
m_pointSize = -1;
|
||||
m_family = wxFONTFAMILY_DEFAULT;
|
||||
m_flags = wxFONTFLAG_DEFAULT;
|
||||
m_weight = wxFONTWEIGHT_NORMAL;
|
||||
m_encoding = wxFONTENCODING_DEFAULT;
|
||||
}
|
||||
|
||||
void InitPointSize(float pointSize)
|
||||
{
|
||||
Init();
|
||||
|
||||
m_pointSize = pointSize;
|
||||
m_pixelSize = wxDefaultSize;
|
||||
}
|
||||
|
||||
// Turn on or off the given bit in m_flags depending on the value of the
|
||||
// boolean argument.
|
||||
void SetFlag(int flag, bool on)
|
||||
@@ -324,7 +297,7 @@ private:
|
||||
// The size information: if m_pixelSize is valid (!= wxDefaultSize), then
|
||||
// it is used. Otherwise m_pointSize is used, except if it is < 0, which
|
||||
// means that the platform dependent font size should be used instead.
|
||||
float m_pointSize;
|
||||
double m_pointSize;
|
||||
wxSize m_pixelSize;
|
||||
|
||||
wxFontFamily m_family;
|
||||
@@ -425,7 +398,7 @@ public:
|
||||
|
||||
// accessors: get the font characteristics
|
||||
virtual int GetPointSize() const;
|
||||
virtual float GetFractionalPointSize() const = 0;
|
||||
virtual double GetFractionalPointSize() const = 0;
|
||||
virtual wxSize GetPixelSize() const;
|
||||
virtual bool IsUsingSizeInPixels() const;
|
||||
wxFontFamily GetFamily() const;
|
||||
@@ -447,7 +420,7 @@ public:
|
||||
|
||||
// change the font characteristics
|
||||
virtual void SetPointSize( int pointSize );
|
||||
virtual void SetFractionalPointSize( float pointSize ) = 0;
|
||||
virtual void SetFractionalPointSize( double pointSize ) = 0;
|
||||
virtual void SetPixelSize( const wxSize& pixelSize );
|
||||
virtual void SetFamily( wxFontFamily family ) = 0;
|
||||
virtual void SetStyle( wxFontStyle style ) = 0;
|
||||
|
Reference in New Issue
Block a user