diff --git a/include/wx/fontutil.h b/include/wx/fontutil.h index df9c8262cc..f829c31e76 100644 --- a/include/wx/fontutil.h +++ b/include/wx/fontutil.h @@ -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); diff --git a/interface/wx/fontutil.h b/interface/wx/fontutil.h index 81dfcd3310..5109babd57 100644 --- a/interface/wx/fontutil.h +++ b/interface/wx/fontutil.h @@ -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); diff --git a/src/common/fontcmn.cpp b/src/common/fontcmn.cpp index a18b9f6f07..66db8ebb47 100644 --- a/src/common/fontcmn.cpp +++ b/src/common/fontcmn.cpp @@ -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(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; } diff --git a/src/gtk/font.cpp b/src/gtk/font.cpp index 5883d46815..b4fe2a4d6e 100644 --- a/src/gtk/font.cpp +++ b/src/gtk/font.cpp @@ -181,7 +181,7 @@ wxFontRefData::~wxFontRefData() void wxFontRefData::SetPointSize(float pointSize) { - m_nativeFontInfo.SetPointSize(pointSize); + m_nativeFontInfo.SetFractionalPointSize(pointSize); } /* diff --git a/src/msw/font.cpp b/src/msw/font.cpp index efedb1d0d7..6702f97851 100644 --- a/src/msw/font.cpp +++ b/src/msw/font.cpp @@ -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) diff --git a/src/osx/carbon/font.cpp b/src/osx/carbon/font.cpp index 5ebef216cf..d813e57335 100644 --- a/src/osx/carbon/font.cpp +++ b/src/osx/carbon/font.cpp @@ -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; diff --git a/src/qt/font.cpp b/src/qt/font.cpp index dc467ea0b7..48c29de81c 100644 --- a/src/qt/font.cpp +++ b/src/qt/font.cpp @@ -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) diff --git a/src/unix/fontutil.cpp b/src/unix/fontutil.cpp index 89baf77bef..7f0ca5edae 100644 --- a/src/unix/fontutil.cpp +++ b/src/unix/fontutil.cpp @@ -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)