From f7a7fe6c4a2c45fb12a73dc934d5c95d0a09ed63 Mon Sep 17 00:00:00 2001 From: Vadim Zeitlin Date: Wed, 12 Sep 2018 20:19:57 +0200 Subject: [PATCH] Add wxNativeFontInfo::SetSizeOrDefault() and use it in all ports Reuse the same code for determining the default font size to use if it wasn't specified in all major ports. In particular, make wxGTK behaviour compatible with the rest and use the normal font size in this case instead of the hardcoded value of 12pt. --- include/wx/fontutil.h | 11 +++++++++++ src/gtk/font.cpp | 6 +----- src/msw/font.cpp | 7 +------ src/osx/carbon/font.cpp | 2 +- 4 files changed, 14 insertions(+), 12 deletions(-) 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);