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
|
||||
|
||||
int pointSize;
|
||||
float pointSize;
|
||||
wxFontFamily family;
|
||||
wxFontStyle style;
|
||||
wxFontWeight weight;
|
||||
@@ -236,9 +236,9 @@ public:
|
||||
if ( font.IsUsingSizeInPixels() )
|
||||
SetPixelSize(font.GetPixelSize());
|
||||
else
|
||||
SetPointSize(font.GetPointSize());
|
||||
SetFractionalPointSize(font.GetFractionalPointSize());
|
||||
#else
|
||||
SetPointSize(font.GetPointSize());
|
||||
SetFractionalPointSize(font.GetFractionalPointSize());
|
||||
#endif
|
||||
|
||||
// set the family/facename
|
||||
@@ -268,7 +268,8 @@ public:
|
||||
wxFontFamily GetFamily() const;
|
||||
wxFontEncoding GetEncoding() const;
|
||||
|
||||
void SetPointSize(float pointsize);
|
||||
void SetPointSize(int pointsize);
|
||||
void SetFractionalPointSize(float pointsize);
|
||||
void SetPixelSize(const wxSize& pixelSize);
|
||||
void SetStyle(wxFontStyle style);
|
||||
void SetNumericWeight(int weight);
|
||||
|
@@ -41,7 +41,8 @@ public:
|
||||
wxFontFamily GetFamily() const;
|
||||
wxFontEncoding GetEncoding() const;
|
||||
|
||||
void SetPointSize(float pointsize);
|
||||
void SetPointSize(int pointsize);
|
||||
void SetFractionalPointSize(float pointsize);
|
||||
void SetPixelSize(const wxSize& pixelSize);
|
||||
void SetStyle(wxFontStyle style);
|
||||
void SetNumericWeight(int weight);
|
||||
|
@@ -377,7 +377,7 @@ void wxFontBase::SetWeight(wxFontWeight weight)
|
||||
void wxFontBase::DoSetNativeFontInfo(const wxNativeFontInfo& info)
|
||||
{
|
||||
#ifdef wxNO_NATIVE_FONTINFO
|
||||
SetPointSize(info.pointSize);
|
||||
SetFractionalPointSize(info.pointSize);
|
||||
SetFamily(info.family);
|
||||
SetStyle(info.style);
|
||||
SetWeight(info.weight);
|
||||
@@ -700,6 +700,15 @@ void wxNativeFontInfo::SetFaceName(const wxArrayString& facenames)
|
||||
#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
|
||||
|
||||
@@ -776,7 +785,7 @@ wxString wxNativeFontInfo::ToString() const
|
||||
|
||||
s.Printf(wxT("%d;%d;%d;%d;%d;%d;%d;%s;%d"),
|
||||
1, // version
|
||||
pointSize,
|
||||
GetPointSize(),
|
||||
family,
|
||||
(int)style,
|
||||
(int)weight,
|
||||
@@ -790,7 +799,7 @@ wxString wxNativeFontInfo::ToString() const
|
||||
|
||||
void wxNativeFontInfo::Init()
|
||||
{
|
||||
pointSize = 0;
|
||||
pointSize = 0.0f;
|
||||
family = wxFONTFAMILY_DEFAULT;
|
||||
style = wxFONTSTYLE_NORMAL;
|
||||
weight = wxFONTWEIGHT_NORMAL;
|
||||
@@ -800,7 +809,7 @@ void wxNativeFontInfo::Init()
|
||||
encoding = wxFONTENCODING_DEFAULT;
|
||||
}
|
||||
|
||||
int wxNativeFontInfo::GetPointSize() const
|
||||
float wxNativeFontInfo::GetFractionalPointSize()
|
||||
{
|
||||
return pointSize;
|
||||
}
|
||||
@@ -840,7 +849,7 @@ wxFontEncoding wxNativeFontInfo::GetEncoding() const
|
||||
return encoding;
|
||||
}
|
||||
|
||||
void wxNativeFontInfo::SetPointSize(int pointsize)
|
||||
void wxNativeFontInfo::SetFractionalPointSize(float pointsize)
|
||||
{
|
||||
pointSize = pointsize;
|
||||
}
|
||||
|
@@ -181,7 +181,7 @@ wxFontRefData::~wxFontRefData()
|
||||
|
||||
void wxFontRefData::SetPointSize(float pointSize)
|
||||
{
|
||||
m_nativeFontInfo.SetPointSize(pointSize);
|
||||
m_nativeFontInfo.SetFractionalPointSize(pointSize);
|
||||
}
|
||||
|
||||
/*
|
||||
|
@@ -100,7 +100,7 @@ public:
|
||||
// all wxFont accessors
|
||||
float GetFractionalPointSize() const
|
||||
{
|
||||
return m_nativeFontInfo.GetPointSize();
|
||||
return m_nativeFontInfo.GetFractionalPointSize();
|
||||
}
|
||||
|
||||
wxSize GetPixelSize() const
|
||||
@@ -180,7 +180,7 @@ public:
|
||||
{
|
||||
Free();
|
||||
|
||||
m_nativeFontInfo.SetPointSize(pointSize);
|
||||
m_nativeFontInfo.SetFractionalPointSize(pointSize);
|
||||
m_sizeUsingPixels = false;
|
||||
}
|
||||
|
||||
@@ -436,19 +436,13 @@ void wxNativeFontInfo::Init()
|
||||
: PROOF_QUALITY;
|
||||
}
|
||||
|
||||
int wxNativeFontInfo::GetPointSize() const
|
||||
{
|
||||
return wxRound(GetFractionalPointSize());
|
||||
}
|
||||
|
||||
float wxNativeFontInfo::GetFractionalPointSize() const
|
||||
{
|
||||
// FIXME: using the screen here results in incorrect font size calculation
|
||||
// for printing!
|
||||
const int ppInch = ::GetDeviceCaps(ScreenHDC(), LOGPIXELSY);
|
||||
|
||||
// BC++ 2007 doesn't provide abs(long) overload, hence the cast
|
||||
return (int) (((72.0*abs((int)lf.lfHeight)) / (double) ppInch) + 0.5);
|
||||
return (72.0*abs(lf.lfHeight)) / (double) ppInch;
|
||||
}
|
||||
|
||||
wxSize wxNativeFontInfo::GetPixelSize() const
|
||||
@@ -529,13 +523,13 @@ wxFontEncoding wxNativeFontInfo::GetEncoding() const
|
||||
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
|
||||
// for printing!
|
||||
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)
|
||||
|
@@ -96,7 +96,7 @@ public:
|
||||
{
|
||||
if (GetFractionalPointSize() != size)
|
||||
{
|
||||
m_info.SetPointSize(size);
|
||||
m_info.SetFractionalPointSize(size);
|
||||
Free();
|
||||
}
|
||||
}
|
||||
@@ -1028,11 +1028,6 @@ wxString wxNativeFontInfo::ToString() const
|
||||
return s;
|
||||
}
|
||||
|
||||
int wxNativeFontInfo::GetPointSize() const
|
||||
{
|
||||
return wxRound(GetFractionalPointSize());
|
||||
}
|
||||
|
||||
float wxNativeFontInfo::GetFractionalPointSize() const
|
||||
{
|
||||
return m_ctSize;
|
||||
@@ -1113,9 +1108,9 @@ bool wxNativeFontInfo::GetStrikethrough() const
|
||||
|
||||
// changing the font descriptor
|
||||
|
||||
void wxNativeFontInfo::SetPointSize(float pointsize)
|
||||
void wxNativeFontInfo::SetFractionalPointSize(float pointsize)
|
||||
{
|
||||
if (GetPointSize() != pointsize)
|
||||
if (GetFractionalPointSize() != 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
|
||||
@@ -412,9 +412,9 @@ wxFontEncoding wxNativeFontInfo::GetEncoding() const
|
||||
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)
|
||||
|
@@ -35,6 +35,7 @@
|
||||
|
||||
#include "wx/encinfo.h"
|
||||
#include "wx/fontmap.h"
|
||||
#include "wx/math.h"
|
||||
#include "wx/tokenzr.h"
|
||||
#include "wx/fontenum.h"
|
||||
|
||||
@@ -90,11 +91,6 @@ void wxNativeFontInfo::Free()
|
||||
pango_font_description_free(description);
|
||||
}
|
||||
|
||||
int wxNativeFontInfo::GetPointSize() const
|
||||
{
|
||||
return wxRound(GetFractionalPointSize());
|
||||
}
|
||||
|
||||
float wxNativeFontInfo::GetFractionalPointSize() const
|
||||
{
|
||||
return ((float) pango_font_description_get_size( description )) / PANGO_SCALE;
|
||||
@@ -219,9 +215,9 @@ wxFontEncoding wxNativeFontInfo::GetEncoding() const
|
||||
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)
|
||||
@@ -705,11 +701,6 @@ void wxNativeFontInfo::SetXFontName(const wxString& xFontName_)
|
||||
m_isDefault = false;
|
||||
}
|
||||
|
||||
int wxNativeFontInfo::GetPointSize() const
|
||||
{
|
||||
return wxRound(GetFractionalPointSize());
|
||||
}
|
||||
|
||||
float wxNativeFontInfo::GetFractionalPointSize() const
|
||||
{
|
||||
const wxString s = GetXFontComponent(wxXLFD_POINTSIZE);
|
||||
@@ -802,9 +793,10 @@ wxFontEncoding wxNativeFontInfo::GetEncoding() const
|
||||
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)
|
||||
|
Reference in New Issue
Block a user