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:
@@ -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()
|
||||
{
|
||||
|
@@ -28,7 +28,6 @@
|
||||
#ifndef WX_PRECOMP
|
||||
#include "wx/dc.h"
|
||||
#include "wx/intl.h"
|
||||
#include "wx/math.h"
|
||||
#include "wx/dcscreen.h"
|
||||
#include "wx/log.h"
|
||||
#include "wx/gdicmn.h"
|
||||
@@ -45,8 +44,6 @@
|
||||
|
||||
#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)
|
||||
@@ -283,7 +280,7 @@ wxFontWeight wxFontBase::GetWeightClosestToNumericValue(int numWeight)
|
||||
|
||||
int wxFontBase::GetPointSize() const
|
||||
{
|
||||
return wxRound(GetFractionalPointSize());
|
||||
return wxFontInfo::ToIntPointSize(GetFractionalPointSize());
|
||||
}
|
||||
|
||||
|
||||
@@ -308,10 +305,7 @@ bool wxFontBase::IsUsingSizeInPixels() const
|
||||
|
||||
void wxFontBase::SetPointSize(int pointSize)
|
||||
{
|
||||
wxCHECK_RET( pointSize >= 0 && static_cast<float>(pointSize) < FLT_MAX,
|
||||
"Invalid font point size" );
|
||||
|
||||
SetFractionalPointSize(static_cast<float>(pointSize));
|
||||
SetFractionalPointSize(wxFontInfo::ToFloatPointSize(pointSize));
|
||||
}
|
||||
|
||||
void wxFontBase::SetPixelSize( const wxSize& pixelSize )
|
||||
@@ -710,12 +704,12 @@ void wxNativeFontInfo::SetFaceName(const wxArrayString& facenames)
|
||||
|
||||
int wxNativeFontInfo::GetPointSize() const
|
||||
{
|
||||
return wxRound(GetFractionalPointSize());
|
||||
return wxFontInfo::ToIntPointSize(GetFractionalPointSize());
|
||||
}
|
||||
|
||||
void wxNativeFontInfo::SetPointSize(int pointsize)
|
||||
{
|
||||
SetFractionalPointSize(static_cast<float>(pointsize));
|
||||
SetFractionalPointSize(wxFontInfo::ToFloatPointSize(pointsize));
|
||||
}
|
||||
|
||||
#ifdef wxNO_NATIVE_FONTINFO
|
||||
|
@@ -578,7 +578,8 @@ bool wxFont::Create(int pointSize,
|
||||
{
|
||||
AccountForCompatValues(pointSize, style, weight);
|
||||
|
||||
return Create((float)pointSize, family, style, weight, underlined, faceName, encoding);
|
||||
return Create(wxFontInfo::ToFloatPointSize(pointSize),
|
||||
family, style, weight, underlined, faceName, encoding);
|
||||
}
|
||||
|
||||
wxFont::~wxFont()
|
||||
|
Reference in New Issue
Block a user