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:
Paul Cornett
2020-04-21 09:00:04 -07:00
parent d551c156c4
commit 896512c732
29 changed files with 129 additions and 168 deletions

View File

@@ -74,7 +74,7 @@ public:
bool Create(const wxNativeFontInfo& fontinfo);
// implement base class pure virtuals
virtual float GetFractionalPointSize() const;
virtual double GetFractionalPointSize() const;
virtual wxFontStyle GetStyle() const;
virtual int GetNumericWeight() const;
virtual wxString GetFaceName() const;
@@ -83,7 +83,7 @@ public:
virtual bool IsFixedWidth() const;
virtual const wxNativeFontInfo *GetNativeFontInfo() const;
virtual void SetFractionalPointSize(float pointSize);
virtual void SetFractionalPointSize(double pointSize);
virtual void SetFamily(wxFontFamily family);
virtual void SetStyle(wxFontStyle style);
virtual void SetNumericWeight(int weight);

View File

@@ -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;

View File

@@ -132,18 +132,18 @@ public:
// MSW-specific: get point size from LOGFONT height using specified DPI,
// or screen DPI when 0.
static float GetPointSizeAtPPI(int lfHeight, int ppi = 0);
static double GetPointSizeAtPPI(int lfHeight, int ppi = 0);
// MSW-specific: get the height value in pixels using LOGFONT convention
// (i.e. negative) corresponding to the given size in points and DPI.
static int GetLogFontHeightAtPPI(float size, int ppi);
static int GetLogFontHeightAtPPI(double size, int ppi);
LOGFONT lf;
// MSW only has limited support for fractional point sizes and we need to
// store the fractional point size separately if it was initially specified
// as we can't losslessly recover it from LOGFONT later.
float pointSize;
double pointSize;
#elif defined(__WXOSX__)
public:
wxNativeFontInfo(const wxNativeFontInfo& info) { Init(info); }
@@ -208,7 +208,7 @@ public :
//
#define wxNO_NATIVE_FONTINFO
float pointSize;
double pointSize;
wxFontFamily family;
wxFontStyle style;
int weight;
@@ -280,7 +280,7 @@ public:
// accessors and modifiers for the font elements
int GetPointSize() const;
float GetFractionalPointSize() const;
double GetFractionalPointSize() const;
wxSize GetPixelSize() const;
wxFontStyle GetStyle() const;
wxFontWeight GetWeight() const;
@@ -292,7 +292,7 @@ public:
wxFontEncoding GetEncoding() const;
void SetPointSize(int pointsize);
void SetFractionalPointSize(float pointsize);
void SetFractionalPointSize(double pointsize);
void SetPixelSize(const wxSize& pixelSize);
void SetStyle(wxFontStyle style);
void SetNumericWeight(int weight);
@@ -305,7 +305,7 @@ public:
// Helper used in many ports: use the normal font size if the input is
// negative, as we handle -1 as meaning this for compatibility.
void SetSizeOrDefault(float size)
void SetSizeOrDefault(double size)
{
SetFractionalPointSize
(

View File

@@ -64,7 +64,7 @@ public:
virtual ~wxFont();
// implement base class pure virtuals
virtual float GetFractionalPointSize() const wxOVERRIDE;
virtual double GetFractionalPointSize() const wxOVERRIDE;
virtual wxFontStyle GetStyle() const wxOVERRIDE;
virtual int GetNumericWeight() const wxOVERRIDE;
virtual wxString GetFaceName() const wxOVERRIDE;
@@ -74,7 +74,7 @@ public:
virtual const wxNativeFontInfo *GetNativeFontInfo() const wxOVERRIDE;
virtual bool IsFixedWidth() const wxOVERRIDE;
virtual void SetFractionalPointSize(float pointSize) wxOVERRIDE;
virtual void SetFractionalPointSize(double pointSize) wxOVERRIDE;
virtual void SetFamily(wxFontFamily family) wxOVERRIDE;
virtual void SetStyle(wxFontStyle style) wxOVERRIDE;
virtual void SetNumericWeight(int weight) wxOVERRIDE;

View File

@@ -90,7 +90,7 @@ public:
virtual ~wxFont();
// implement base class pure virtuals
virtual float GetFractionalPointSize() const;
virtual double GetFractionalPointSize() const;
virtual wxFontStyle GetStyle() const;
virtual int GetNumericWeight() const;
virtual wxString GetFaceName() const;
@@ -99,7 +99,7 @@ public:
virtual const wxNativeFontInfo *GetNativeFontInfo() const;
virtual bool IsFixedWidth() const;
virtual void SetFractionalPointSize(float pointSize);
virtual void SetFractionalPointSize(double pointSize);
virtual void SetFamily(wxFontFamily family);
virtual void SetStyle(wxFontStyle style);
virtual void SetNumericWeight(int weight);

View File

@@ -72,7 +72,7 @@ public:
virtual ~wxFont();
// implement base class pure virtuals
virtual float GetFractionalPointSize() const;
virtual double GetFractionalPointSize() const;
virtual wxFontStyle GetStyle() const;
virtual int GetNumericWeight() const;
virtual bool GetUnderlined() const;
@@ -80,7 +80,7 @@ public:
virtual wxFontEncoding GetEncoding() const;
virtual const wxNativeFontInfo *GetNativeFontInfo() const;
virtual void SetFractionalPointSize(float pointSize);
virtual void SetFractionalPointSize(double pointSize);
virtual void SetFamily(wxFontFamily family);
virtual void SetStyle(wxFontStyle style);
virtual void SetNumericWeight(int weight);

View File

@@ -95,7 +95,7 @@ public:
virtual ~wxFont();
// implement base class pure virtuals
virtual float GetFractionalPointSize() const wxOVERRIDE;
virtual double GetFractionalPointSize() const wxOVERRIDE;
virtual wxSize GetPixelSize() const wxOVERRIDE;
virtual bool IsUsingSizeInPixels() const wxOVERRIDE;
virtual wxFontStyle GetStyle() const wxOVERRIDE;
@@ -106,7 +106,7 @@ public:
virtual wxFontEncoding GetEncoding() const wxOVERRIDE;
virtual const wxNativeFontInfo *GetNativeFontInfo() const wxOVERRIDE;
virtual void SetFractionalPointSize(float pointSize) wxOVERRIDE;
virtual void SetFractionalPointSize(double pointSize) wxOVERRIDE;
virtual void SetPixelSize(const wxSize& pixelSize) wxOVERRIDE;
virtual void SetFamily(wxFontFamily family) wxOVERRIDE;
virtual void SetStyle(wxFontStyle style) wxOVERRIDE;

View File

@@ -88,7 +88,7 @@ public:
virtual ~wxFont();
// implement base class pure virtuals
virtual float GetFractionalPointSize() const wxOVERRIDE;
virtual double GetFractionalPointSize() const wxOVERRIDE;
virtual wxSize GetPixelSize() const wxOVERRIDE;
virtual wxFontStyle GetStyle() const wxOVERRIDE;
virtual int GetNumericWeight() const wxOVERRIDE;
@@ -100,7 +100,7 @@ public:
virtual bool IsFixedWidth() const wxOVERRIDE;
virtual void SetFractionalPointSize(float pointSize) wxOVERRIDE;
virtual void SetFractionalPointSize(double pointSize) wxOVERRIDE;
virtual void SetFamily(wxFontFamily family) wxOVERRIDE;
virtual void SetStyle(wxFontStyle style) wxOVERRIDE;
virtual void SetNumericWeight(int weight) wxOVERRIDE;

View File

@@ -218,7 +218,7 @@ public:
const wxNativeFontInfo *GetNativeFontInfo() const { return &m_info; }
float GetFractionalPointSize() const { return m_info.pointSize; }
double GetFractionalPointSize() const { return m_info.pointSize; }
wxString GetFaceName() const { return m_info.faceName; }
wxFontFamily GetFamily() const { return m_info.family; }
wxFontStyle GetStyle() const { return m_info.style; }
@@ -226,7 +226,7 @@ public:
bool GetUnderlined() const { return m_info.underlined; }
wxFontEncoding GetEncoding() const { return m_info.encoding; }
void SetFractionalPointSize(float pointSize);
void SetFractionalPointSize(double pointSize);
void SetFamily(wxFontFamily family);
void SetStyle(wxFontStyle style);
void SetNumericWeight(int weight);

View File

@@ -51,7 +51,7 @@ public:
// accessors: get the font characteristics
virtual int GetPointSize() const wxOVERRIDE;
virtual float GetFractionalPointSize() const wxOVERRIDE;
virtual double GetFractionalPointSize() const wxOVERRIDE;
virtual wxSize GetPixelSize() const wxOVERRIDE;
virtual wxFontStyle GetStyle() const wxOVERRIDE;
virtual int GetNumericWeight() const wxOVERRIDE;
@@ -62,7 +62,7 @@ public:
virtual bool GetStrikethrough() const wxOVERRIDE;
// change the font characteristics
virtual void SetFractionalPointSize(float pointSize) wxOVERRIDE;
virtual void SetFractionalPointSize(double pointSize) wxOVERRIDE;
virtual void SetPixelSize(const wxSize& pixelSize) wxOVERRIDE;
virtual void SetFamily( wxFontFamily family ) wxOVERRIDE;
virtual void SetStyle( wxFontStyle style ) wxOVERRIDE;

View File

@@ -21,7 +21,7 @@
// returns the handle of the nearest available font or 0
extern wxNativeFont
wxLoadQueryNearestFont(float pointSize,
wxLoadQueryNearestFont(double pointSize,
wxFontFamily family,
wxFontStyle style,
int weight,

View File

@@ -81,7 +81,7 @@ public:
virtual ~wxFont();
// implement base class pure virtuals
virtual float GetFractionalPointSize() const;
virtual double GetFractionalPointSize() const;
virtual wxFontStyle GetStyle() const;
virtual int GetNumericWeight() const;
virtual bool GetUnderlined() const;
@@ -92,7 +92,7 @@ public:
virtual bool IsFixedWidth() const;
virtual void SetFractionalPointSize(float pointSize);
virtual void SetFractionalPointSize(double pointSize);
virtual void SetFamily(wxFontFamily family);
virtual void SetStyle(wxFontStyle style);
virtual void SetNumericWeight(int weight);