Refactor float to int point size conversions once again

They will be also needed in wxFontInfo soon, so move them there and use
these functions from both wxFont and wxNativeFontInfo, as they can
depend on wxFontInfo but not the other way round.

No real changes.
This commit is contained in:
Vadim Zeitlin
2018-09-12 14:46:00 +02:00
parent 7500a999bd
commit 5a6b7681d8
3 changed files with 26 additions and 11 deletions

View File

@@ -19,6 +19,7 @@
#include "wx/fontenc.h" // the font encoding constants
#include "wx/gdiobj.h" // the base class
#include "wx/gdicmn.h" // for wxGDIObjListBase
#include "wx/math.h" // for wxRound()
// ----------------------------------------------------------------------------
// forward declarations
@@ -216,6 +217,25 @@ public:
// 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;
}
private:
void Init()
{