diff --git a/include/wx/fontutil.h b/include/wx/fontutil.h index 33e9313755..aee4cf4fd5 100644 --- a/include/wx/fontutil.h +++ b/include/wx/fontutil.h @@ -285,6 +285,17 @@ public: void SetFamily(wxFontFamily family); void SetEncoding(wxFontEncoding encoding); + // Helper used in many ports: use the normal font size if the input is + // negative, as we handle -1 as meaning this for compatibility. + void SetSizeOrDefault(float size) + { + SetFractionalPointSize + ( + size < 0 ? wxNORMAL_FONT->GetFractionalPointSize() + : size + ); + } + // sets the first facename in the given array which is found // to be valid. If no valid facename is given, sets the // first valid facename returned by wxFontEnumerator::GetFacenames(). diff --git a/src/gtk/font.cpp b/src/gtk/font.cpp index 7ad3e9ec11..e8bf634526 100644 --- a/src/gtk/font.cpp +++ b/src/gtk/font.cpp @@ -133,11 +133,7 @@ void wxFontRefData::Init(float pointSize, } SetStyle( style ); - m_nativeFontInfo.SetFractionalPointSize - ( - pointSize < 0 ? static_cast(wxDEFAULT_FONT_SIZE) - : pointSize - ); + m_nativeFontInfo.SetSizeOrDefault(pointSize); SetNumericWeight( weight ); SetUnderlined( underlined ); SetStrikethrough( strikethrough ); diff --git a/src/msw/font.cpp b/src/msw/font.cpp index a2111bcdc9..668873fc14 100644 --- a/src/msw/font.cpp +++ b/src/msw/font.cpp @@ -362,12 +362,7 @@ void wxFontRefData::Init(float pointSize, } else { - m_nativeFontInfo.SetFractionalPointSize - ( - pointSize < 0 - ? wxNORMAL_FONT->GetPointSize() - : pointSize - ); + m_nativeFontInfo.SetSizeOrDefault(pointSize); } SetStyle(style); diff --git a/src/osx/carbon/font.cpp b/src/osx/carbon/font.cpp index 106ab44902..07d5968aef 100644 --- a/src/osx/carbon/font.cpp +++ b/src/osx/carbon/font.cpp @@ -301,7 +301,7 @@ void wxFontRefData::Init(float size, else SetFamily(family); - SetFractionalPointSize(size < 0 ? wxNORMAL_FONT->GetFractionalPointSize() : size); + m_info.SetSizeOrDefault(size); SetNumericWeight(weight); SetStyle(style); SetUnderlined(underlined);