Switch to using float for point size in wxNativeFontInfo
Use float as the fundamental type for the font size and implement wxNativeFontInfo::{Set,Get}PointSize() as wrappers around the new {Set,Get}FractionalPointSize(). Update wxNativeFontInfo for all platforms and replace the use of its SetPointSize() method with SetFractionalPointSize() in wxFont for the platforms already supporting fractional point sizes (don't change the others just yet). Note that wxNativeFontInfo::{Get,Set}PointSize() are preserved for backwards compatibility but shouldn't be used in any code inside the library itself any more (again, this is not the case yet, but will be soon).
This commit is contained in:
@@ -185,7 +185,7 @@ public :
|
|||||||
//
|
//
|
||||||
#define wxNO_NATIVE_FONTINFO
|
#define wxNO_NATIVE_FONTINFO
|
||||||
|
|
||||||
int pointSize;
|
float pointSize;
|
||||||
wxFontFamily family;
|
wxFontFamily family;
|
||||||
wxFontStyle style;
|
wxFontStyle style;
|
||||||
wxFontWeight weight;
|
wxFontWeight weight;
|
||||||
@@ -236,9 +236,9 @@ public:
|
|||||||
if ( font.IsUsingSizeInPixels() )
|
if ( font.IsUsingSizeInPixels() )
|
||||||
SetPixelSize(font.GetPixelSize());
|
SetPixelSize(font.GetPixelSize());
|
||||||
else
|
else
|
||||||
SetPointSize(font.GetPointSize());
|
SetFractionalPointSize(font.GetFractionalPointSize());
|
||||||
#else
|
#else
|
||||||
SetPointSize(font.GetPointSize());
|
SetFractionalPointSize(font.GetFractionalPointSize());
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
// set the family/facename
|
// set the family/facename
|
||||||
@@ -268,7 +268,8 @@ public:
|
|||||||
wxFontFamily GetFamily() const;
|
wxFontFamily GetFamily() const;
|
||||||
wxFontEncoding GetEncoding() const;
|
wxFontEncoding GetEncoding() const;
|
||||||
|
|
||||||
void SetPointSize(float pointsize);
|
void SetPointSize(int pointsize);
|
||||||
|
void SetFractionalPointSize(float pointsize);
|
||||||
void SetPixelSize(const wxSize& pixelSize);
|
void SetPixelSize(const wxSize& pixelSize);
|
||||||
void SetStyle(wxFontStyle style);
|
void SetStyle(wxFontStyle style);
|
||||||
void SetNumericWeight(int weight);
|
void SetNumericWeight(int weight);
|
||||||
|
@@ -41,7 +41,8 @@ public:
|
|||||||
wxFontFamily GetFamily() const;
|
wxFontFamily GetFamily() const;
|
||||||
wxFontEncoding GetEncoding() const;
|
wxFontEncoding GetEncoding() const;
|
||||||
|
|
||||||
void SetPointSize(float pointsize);
|
void SetPointSize(int pointsize);
|
||||||
|
void SetFractionalPointSize(float pointsize);
|
||||||
void SetPixelSize(const wxSize& pixelSize);
|
void SetPixelSize(const wxSize& pixelSize);
|
||||||
void SetStyle(wxFontStyle style);
|
void SetStyle(wxFontStyle style);
|
||||||
void SetNumericWeight(int weight);
|
void SetNumericWeight(int weight);
|
||||||
|
@@ -377,7 +377,7 @@ void wxFontBase::SetWeight(wxFontWeight weight)
|
|||||||
void wxFontBase::DoSetNativeFontInfo(const wxNativeFontInfo& info)
|
void wxFontBase::DoSetNativeFontInfo(const wxNativeFontInfo& info)
|
||||||
{
|
{
|
||||||
#ifdef wxNO_NATIVE_FONTINFO
|
#ifdef wxNO_NATIVE_FONTINFO
|
||||||
SetPointSize(info.pointSize);
|
SetFractionalPointSize(info.pointSize);
|
||||||
SetFamily(info.family);
|
SetFamily(info.family);
|
||||||
SetStyle(info.style);
|
SetStyle(info.style);
|
||||||
SetWeight(info.weight);
|
SetWeight(info.weight);
|
||||||
@@ -700,6 +700,15 @@ void wxNativeFontInfo::SetFaceName(const wxArrayString& facenames)
|
|||||||
#endif // wxUSE_FONTENUM/!wxUSE_FONTENUM
|
#endif // wxUSE_FONTENUM/!wxUSE_FONTENUM
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int wxNativeFontInfo::GetPointSize() const
|
||||||
|
{
|
||||||
|
return wxRound(GetFractionalPointSize());
|
||||||
|
}
|
||||||
|
|
||||||
|
void wxNativeFontInfo::SetPointSize(int pointsize)
|
||||||
|
{
|
||||||
|
SetFractionalPointSize(static_cast<float>(pointsize));
|
||||||
|
}
|
||||||
|
|
||||||
#ifdef wxNO_NATIVE_FONTINFO
|
#ifdef wxNO_NATIVE_FONTINFO
|
||||||
|
|
||||||
@@ -776,7 +785,7 @@ wxString wxNativeFontInfo::ToString() const
|
|||||||
|
|
||||||
s.Printf(wxT("%d;%d;%d;%d;%d;%d;%d;%s;%d"),
|
s.Printf(wxT("%d;%d;%d;%d;%d;%d;%d;%s;%d"),
|
||||||
1, // version
|
1, // version
|
||||||
pointSize,
|
GetPointSize(),
|
||||||
family,
|
family,
|
||||||
(int)style,
|
(int)style,
|
||||||
(int)weight,
|
(int)weight,
|
||||||
@@ -790,7 +799,7 @@ wxString wxNativeFontInfo::ToString() const
|
|||||||
|
|
||||||
void wxNativeFontInfo::Init()
|
void wxNativeFontInfo::Init()
|
||||||
{
|
{
|
||||||
pointSize = 0;
|
pointSize = 0.0f;
|
||||||
family = wxFONTFAMILY_DEFAULT;
|
family = wxFONTFAMILY_DEFAULT;
|
||||||
style = wxFONTSTYLE_NORMAL;
|
style = wxFONTSTYLE_NORMAL;
|
||||||
weight = wxFONTWEIGHT_NORMAL;
|
weight = wxFONTWEIGHT_NORMAL;
|
||||||
@@ -800,7 +809,7 @@ void wxNativeFontInfo::Init()
|
|||||||
encoding = wxFONTENCODING_DEFAULT;
|
encoding = wxFONTENCODING_DEFAULT;
|
||||||
}
|
}
|
||||||
|
|
||||||
int wxNativeFontInfo::GetPointSize() const
|
float wxNativeFontInfo::GetFractionalPointSize()
|
||||||
{
|
{
|
||||||
return pointSize;
|
return pointSize;
|
||||||
}
|
}
|
||||||
@@ -840,7 +849,7 @@ wxFontEncoding wxNativeFontInfo::GetEncoding() const
|
|||||||
return encoding;
|
return encoding;
|
||||||
}
|
}
|
||||||
|
|
||||||
void wxNativeFontInfo::SetPointSize(int pointsize)
|
void wxNativeFontInfo::SetFractionalPointSize(float pointsize)
|
||||||
{
|
{
|
||||||
pointSize = pointsize;
|
pointSize = pointsize;
|
||||||
}
|
}
|
||||||
|
@@ -181,7 +181,7 @@ wxFontRefData::~wxFontRefData()
|
|||||||
|
|
||||||
void wxFontRefData::SetPointSize(float pointSize)
|
void wxFontRefData::SetPointSize(float pointSize)
|
||||||
{
|
{
|
||||||
m_nativeFontInfo.SetPointSize(pointSize);
|
m_nativeFontInfo.SetFractionalPointSize(pointSize);
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
@@ -100,7 +100,7 @@ public:
|
|||||||
// all wxFont accessors
|
// all wxFont accessors
|
||||||
float GetFractionalPointSize() const
|
float GetFractionalPointSize() const
|
||||||
{
|
{
|
||||||
return m_nativeFontInfo.GetPointSize();
|
return m_nativeFontInfo.GetFractionalPointSize();
|
||||||
}
|
}
|
||||||
|
|
||||||
wxSize GetPixelSize() const
|
wxSize GetPixelSize() const
|
||||||
@@ -180,7 +180,7 @@ public:
|
|||||||
{
|
{
|
||||||
Free();
|
Free();
|
||||||
|
|
||||||
m_nativeFontInfo.SetPointSize(pointSize);
|
m_nativeFontInfo.SetFractionalPointSize(pointSize);
|
||||||
m_sizeUsingPixels = false;
|
m_sizeUsingPixels = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -436,19 +436,13 @@ void wxNativeFontInfo::Init()
|
|||||||
: PROOF_QUALITY;
|
: PROOF_QUALITY;
|
||||||
}
|
}
|
||||||
|
|
||||||
int wxNativeFontInfo::GetPointSize() const
|
|
||||||
{
|
|
||||||
return wxRound(GetFractionalPointSize());
|
|
||||||
}
|
|
||||||
|
|
||||||
float wxNativeFontInfo::GetFractionalPointSize() const
|
float wxNativeFontInfo::GetFractionalPointSize() const
|
||||||
{
|
{
|
||||||
// FIXME: using the screen here results in incorrect font size calculation
|
// FIXME: using the screen here results in incorrect font size calculation
|
||||||
// for printing!
|
// for printing!
|
||||||
const int ppInch = ::GetDeviceCaps(ScreenHDC(), LOGPIXELSY);
|
const int ppInch = ::GetDeviceCaps(ScreenHDC(), LOGPIXELSY);
|
||||||
|
|
||||||
// BC++ 2007 doesn't provide abs(long) overload, hence the cast
|
return (72.0*abs(lf.lfHeight)) / (double) ppInch;
|
||||||
return (int) (((72.0*abs((int)lf.lfHeight)) / (double) ppInch) + 0.5);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
wxSize wxNativeFontInfo::GetPixelSize() const
|
wxSize wxNativeFontInfo::GetPixelSize() const
|
||||||
@@ -529,13 +523,13 @@ wxFontEncoding wxNativeFontInfo::GetEncoding() const
|
|||||||
return wxGetFontEncFromCharSet(lf.lfCharSet);
|
return wxGetFontEncFromCharSet(lf.lfCharSet);
|
||||||
}
|
}
|
||||||
|
|
||||||
void wxNativeFontInfo::SetPointSize(float pointsize)
|
void wxNativeFontInfo::SetFractionalPointSize(float pointsize)
|
||||||
{
|
{
|
||||||
// FIXME: using the screen here results in incorrect font size calculation
|
// FIXME: using the screen here results in incorrect font size calculation
|
||||||
// for printing!
|
// for printing!
|
||||||
const int ppInch = ::GetDeviceCaps(ScreenHDC(), LOGPIXELSY);
|
const int ppInch = ::GetDeviceCaps(ScreenHDC(), LOGPIXELSY);
|
||||||
|
|
||||||
lf.lfHeight = -(int)((pointsize*((double)ppInch)/72.0) + 0.5);
|
lf.lfHeight = -wxRound(pointsize*((double)ppInch)/72.0);
|
||||||
}
|
}
|
||||||
|
|
||||||
void wxNativeFontInfo::SetPixelSize(const wxSize& pixelSize)
|
void wxNativeFontInfo::SetPixelSize(const wxSize& pixelSize)
|
||||||
|
@@ -96,7 +96,7 @@ public:
|
|||||||
{
|
{
|
||||||
if (GetFractionalPointSize() != size)
|
if (GetFractionalPointSize() != size)
|
||||||
{
|
{
|
||||||
m_info.SetPointSize(size);
|
m_info.SetFractionalPointSize(size);
|
||||||
Free();
|
Free();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -1028,11 +1028,6 @@ wxString wxNativeFontInfo::ToString() const
|
|||||||
return s;
|
return s;
|
||||||
}
|
}
|
||||||
|
|
||||||
int wxNativeFontInfo::GetPointSize() const
|
|
||||||
{
|
|
||||||
return wxRound(GetFractionalPointSize());
|
|
||||||
}
|
|
||||||
|
|
||||||
float wxNativeFontInfo::GetFractionalPointSize() const
|
float wxNativeFontInfo::GetFractionalPointSize() const
|
||||||
{
|
{
|
||||||
return m_ctSize;
|
return m_ctSize;
|
||||||
@@ -1113,9 +1108,9 @@ bool wxNativeFontInfo::GetStrikethrough() const
|
|||||||
|
|
||||||
// changing the font descriptor
|
// changing the font descriptor
|
||||||
|
|
||||||
void wxNativeFontInfo::SetPointSize(float pointsize)
|
void wxNativeFontInfo::SetFractionalPointSize(float pointsize)
|
||||||
{
|
{
|
||||||
if (GetPointSize() != pointsize)
|
if (GetFractionalPointSize() != pointsize)
|
||||||
{
|
{
|
||||||
m_ctSize = pointsize;
|
m_ctSize = pointsize;
|
||||||
|
|
||||||
|
@@ -315,9 +315,9 @@ void wxNativeFontInfo::Init()
|
|||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
int wxNativeFontInfo::GetPointSize() const
|
float wxNativeFontInfo::GetFractionalPointSize() const
|
||||||
{
|
{
|
||||||
return m_qtFont.pointSize();
|
return m_qtFont.pointSizeF();
|
||||||
}
|
}
|
||||||
|
|
||||||
wxFontStyle wxNativeFontInfo::GetStyle() const
|
wxFontStyle wxNativeFontInfo::GetStyle() const
|
||||||
@@ -412,9 +412,9 @@ wxFontEncoding wxNativeFontInfo::GetEncoding() const
|
|||||||
return wxFONTENCODING_MAX;
|
return wxFONTENCODING_MAX;
|
||||||
}
|
}
|
||||||
|
|
||||||
void wxNativeFontInfo::SetPointSize(int pointsize)
|
void wxNativeFontInfo::SetFractionalPointSize(float pointsize)
|
||||||
{
|
{
|
||||||
m_qtFont.setPointSize(pointsize);
|
m_qtFont.setPointSizeF(pointsize);
|
||||||
}
|
}
|
||||||
|
|
||||||
void wxNativeFontInfo::SetStyle(wxFontStyle style)
|
void wxNativeFontInfo::SetStyle(wxFontStyle style)
|
||||||
|
@@ -35,6 +35,7 @@
|
|||||||
|
|
||||||
#include "wx/encinfo.h"
|
#include "wx/encinfo.h"
|
||||||
#include "wx/fontmap.h"
|
#include "wx/fontmap.h"
|
||||||
|
#include "wx/math.h"
|
||||||
#include "wx/tokenzr.h"
|
#include "wx/tokenzr.h"
|
||||||
#include "wx/fontenum.h"
|
#include "wx/fontenum.h"
|
||||||
|
|
||||||
@@ -90,11 +91,6 @@ void wxNativeFontInfo::Free()
|
|||||||
pango_font_description_free(description);
|
pango_font_description_free(description);
|
||||||
}
|
}
|
||||||
|
|
||||||
int wxNativeFontInfo::GetPointSize() const
|
|
||||||
{
|
|
||||||
return wxRound(GetFractionalPointSize());
|
|
||||||
}
|
|
||||||
|
|
||||||
float wxNativeFontInfo::GetFractionalPointSize() const
|
float wxNativeFontInfo::GetFractionalPointSize() const
|
||||||
{
|
{
|
||||||
return ((float) pango_font_description_get_size( description )) / PANGO_SCALE;
|
return ((float) pango_font_description_get_size( description )) / PANGO_SCALE;
|
||||||
@@ -219,9 +215,9 @@ wxFontEncoding wxNativeFontInfo::GetEncoding() const
|
|||||||
return wxFONTENCODING_SYSTEM;
|
return wxFONTENCODING_SYSTEM;
|
||||||
}
|
}
|
||||||
|
|
||||||
void wxNativeFontInfo::SetPointSize(float pointsize)
|
void wxNativeFontInfo::SetFractionalPointSize(float pointsize)
|
||||||
{
|
{
|
||||||
pango_font_description_set_size( description, pointsize * PANGO_SCALE );
|
pango_font_description_set_size( description, wxRound(pointsize * PANGO_SCALE) );
|
||||||
}
|
}
|
||||||
|
|
||||||
void wxNativeFontInfo::SetStyle(wxFontStyle style)
|
void wxNativeFontInfo::SetStyle(wxFontStyle style)
|
||||||
@@ -705,11 +701,6 @@ void wxNativeFontInfo::SetXFontName(const wxString& xFontName_)
|
|||||||
m_isDefault = false;
|
m_isDefault = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
int wxNativeFontInfo::GetPointSize() const
|
|
||||||
{
|
|
||||||
return wxRound(GetFractionalPointSize());
|
|
||||||
}
|
|
||||||
|
|
||||||
float wxNativeFontInfo::GetFractionalPointSize() const
|
float wxNativeFontInfo::GetFractionalPointSize() const
|
||||||
{
|
{
|
||||||
const wxString s = GetXFontComponent(wxXLFD_POINTSIZE);
|
const wxString s = GetXFontComponent(wxXLFD_POINTSIZE);
|
||||||
@@ -802,9 +793,10 @@ wxFontEncoding wxNativeFontInfo::GetEncoding() const
|
|||||||
return wxFONTENCODING_MAX;
|
return wxFONTENCODING_MAX;
|
||||||
}
|
}
|
||||||
|
|
||||||
void wxNativeFontInfo::SetPointSize(float pointsize)
|
void wxNativeFontInfo::SetFractionalPointSize(float pointsize)
|
||||||
{
|
{
|
||||||
SetXFontComponent(wxXLFD_POINTSIZE, wxString::Format(wxT("%d"), pointsize));
|
SetXFontComponent(wxXLFD_POINTSIZE,
|
||||||
|
wxString::Format("%d", wxRound(pointsize)));
|
||||||
}
|
}
|
||||||
|
|
||||||
void wxNativeFontInfo::SetStyle(wxFontStyle style)
|
void wxNativeFontInfo::SetStyle(wxFontStyle style)
|
||||||
|
Reference in New Issue
Block a user