From 0634700a96fb1ad8f808317193f807e3b276b730 Mon Sep 17 00:00:00 2001 From: Vadim Zeitlin Date: Mon, 23 Jan 2012 11:28:21 +0000 Subject: [PATCH] Add wxFont ctor taking a single flags argument instead of style/weight/... Currently this ctor just does the same thing as the existing ctors in a different way but it will be extended to support wxFONTFLAG_STRIKETHROUGH in the next commits. See #9907. git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@70445 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775 --- include/wx/cocoa/font.h | 13 +++++++++++++ include/wx/dfb/font.h | 13 +++++++++++++ include/wx/font.h | 27 +++++++++++++++++++++++++++ include/wx/gtk/font.h | 6 ++++++ include/wx/gtk1/font.h | 13 +++++++++++++ include/wx/motif/font.h | 13 +++++++++++++ include/wx/msw/font.h | 6 ++++++ include/wx/os2/font.h | 13 +++++++++++++ include/wx/osx/font.h | 13 +++++++++++++ include/wx/x11/font.h | 13 +++++++++++++ interface/wx/font.h | 20 ++++++++++++++++++-- src/common/fontcmn.cpp | 41 ++++++++++------------------------------- src/gtk/font.cpp | 13 +++++++++++++ src/msw/font.cpp | 14 ++++++++++++++ 14 files changed, 185 insertions(+), 33 deletions(-) diff --git a/include/wx/cocoa/font.h b/include/wx/cocoa/font.h index d54a07f6e1..a8989845db 100644 --- a/include/wx/cocoa/font.h +++ b/include/wx/cocoa/font.h @@ -75,6 +75,19 @@ public: SetPixelSize(pixelSize); } + wxFont(int pointSize, + wxFontFamily family, + int flags = wxFONTFLAG_DEFAULT, + const wxString& face = wxEmptyString, + wxFontEncoding encoding = wxFONTENCODING_DEFAULT) + { + Create(pointSize, family, + GetStyleFromFlags(flags), + GetWeightFromFlags(flags), + GetUnderlinedFromFlags(flags), + face, encoding); + } + /*! @abstract Construction with opaque wxNativeFontInfo */ wxFont(const wxNativeFontInfo& info) diff --git a/include/wx/dfb/font.h b/include/wx/dfb/font.h index ad0e586e1e..3ccdebb422 100644 --- a/include/wx/dfb/font.h +++ b/include/wx/dfb/font.h @@ -60,6 +60,19 @@ public: SetPixelSize(pixelSize); } + wxFont(int pointSize, + wxFontFamily family, + int flags = wxFONTFLAG_DEFAULT, + const wxString& face = wxEmptyString, + wxFontEncoding encoding = wxFONTENCODING_DEFAULT) + { + Create(pointSize, family, + GetStyleFromFlags(flags), + GetWeightFromFlags(flags), + GetUnderlinedFromFlags(flags), + face, encoding); + } + bool Create(int size, wxFontFamily family, wxFontStyle style, diff --git a/include/wx/font.h b/include/wx/font.h index 0d70d3f41a..0a7623ee49 100644 --- a/include/wx/font.h +++ b/include/wx/font.h @@ -290,6 +290,33 @@ protected: // wxFONTFAMILY_UNKNOWN unlike the public method (see comment there). virtual wxFontFamily DoGetFamily() const = 0; + + // Helper functions to recover wxFONTSTYLE/wxFONTWEIGHT and underlined flg + // values from flags containing a combination of wxFONTFLAG_XXX. + static wxFontStyle GetStyleFromFlags(int flags) + { + return flags & wxFONTFLAG_ITALIC + ? wxFONTSTYLE_ITALIC + : flags & wxFONTFLAG_SLANT + ? wxFONTSTYLE_SLANT + : wxFONTSTYLE_NORMAL; + } + + static wxFontWeight GetWeightFromFlags(int flags) + { + return flags & wxFONTFLAG_LIGHT + ? wxFONTWEIGHT_LIGHT + : flags & wxFONTFLAG_BOLD + ? wxFONTWEIGHT_BOLD + : wxFONTWEIGHT_NORMAL; + } + + static bool GetUnderlinedFromFlags(int flags) + { + return (flags & wxFONTFLAG_UNDERLINED) != 0; + } + + private: // the currently default encoding: by default, it's the default system // encoding, but may be changed by the application using diff --git a/include/wx/gtk/font.h b/include/wx/gtk/font.h index da9c9a474f..a73e9669cb 100644 --- a/include/wx/gtk/font.h +++ b/include/wx/gtk/font.h @@ -63,6 +63,12 @@ public: SetPixelSize(pixelSize); } + wxFont(int pointSize, + wxFontFamily family, + int flags = wxFONTFLAG_DEFAULT, + const wxString& face = wxEmptyString, + wxFontEncoding encoding = wxFONTENCODING_DEFAULT); + bool Create(int size, wxFontFamily family, wxFontStyle style, diff --git a/include/wx/gtk1/font.h b/include/wx/gtk1/font.h index b5e7e4ea20..87d21b1f11 100644 --- a/include/wx/gtk1/font.h +++ b/include/wx/gtk1/font.h @@ -76,6 +76,19 @@ public: SetPixelSize(pixelSize); } + wxFont(int pointSize, + wxFontFamily family, + int flags = wxFONTFLAG_DEFAULT, + const wxString& face = wxEmptyString, + wxFontEncoding encoding = wxFONTENCODING_DEFAULT) + { + Create(pointSize, family, + GetStyleFromFlags(flags), + GetWeightFromFlags(flags), + GetUnderlinedFromFlags(flags), + face, encoding); + } + bool Create(int size, wxFontFamily family, wxFontStyle style, diff --git a/include/wx/motif/font.h b/include/wx/motif/font.h index e00eb848d3..935581f2e4 100644 --- a/include/wx/motif/font.h +++ b/include/wx/motif/font.h @@ -66,6 +66,19 @@ public: SetPixelSize(pixelSize); } + wxFont(int pointSize, + wxFontFamily family, + int flags = wxFONTFLAG_DEFAULT, + const wxString& face = wxEmptyString, + wxFontEncoding encoding = wxFONTENCODING_DEFAULT) + { + Create(pointSize, family, + GetStyleFromFlags(flags), + GetWeightFromFlags(flags), + GetUnderlinedFromFlags(flags), + face, encoding); + } + bool Create(int size, wxFontFamily family, wxFontStyle style, diff --git a/include/wx/msw/font.h b/include/wx/msw/font.h index 3f49e65e78..eb4ed5b17e 100644 --- a/include/wx/msw/font.h +++ b/include/wx/msw/font.h @@ -91,6 +91,12 @@ public: Create(info, hFont); } + wxFont(int pointSize, + wxFontFamily family, + int flags = wxFONTFLAG_DEFAULT, + const wxString& face = wxEmptyString, + wxFontEncoding encoding = wxFONTENCODING_DEFAULT); + wxFont(const wxString& fontDesc); diff --git a/include/wx/os2/font.h b/include/wx/os2/font.h index 7060847d66..39be035dfc 100644 --- a/include/wx/os2/font.h +++ b/include/wx/os2/font.h @@ -63,6 +63,19 @@ public: SetPixelSize(pixelSize); } + wxFont(int pointSize, + wxFontFamily family, + int flags = wxFONTFLAG_DEFAULT, + const wxString& face = wxEmptyString, + wxFontEncoding encoding = wxFONTENCODING_DEFAULT) + { + Create(pointSize, family, + GetStyleFromFlags(flags), + GetWeightFromFlags(flags), + GetUnderlinedFromFlags(flags), + face, encoding); + } + bool Create(int size, wxFontFamily family, wxFontStyle style, diff --git a/include/wx/osx/font.h b/include/wx/osx/font.h index 7eb86a6809..fb7fea783a 100644 --- a/include/wx/osx/font.h +++ b/include/wx/osx/font.h @@ -79,6 +79,19 @@ public: SetPixelSize(pixelSize); } + wxFont(int pointSize, + wxFontFamily family, + int flags = wxFONTFLAG_DEFAULT, + const wxString& face = wxEmptyString, + wxFontEncoding encoding = wxFONTENCODING_DEFAULT) + { + Create(pointSize, family, + GetStyleFromFlags(flags), + GetWeightFromFlags(flags), + GetUnderlinedFromFlags(flags), + face, encoding); + } + bool Create(int size, wxFontFamily family, wxFontStyle style, diff --git a/include/wx/x11/font.h b/include/wx/x11/font.h index b2c8718392..a7cabdeb9f 100644 --- a/include/wx/x11/font.h +++ b/include/wx/x11/font.h @@ -57,6 +57,19 @@ public: SetPixelSize(pixelSize); } + wxFont(int pointSize, + wxFontFamily family, + int flags = wxFONTFLAG_DEFAULT, + const wxString& face = wxEmptyString, + wxFontEncoding encoding = wxFONTENCODING_DEFAULT) + { + Create(pointSize, family, + GetStyleFromFlags(flags), + GetWeightFromFlags(flags), + GetUnderlinedFromFlags(flags), + face, encoding); + } + bool Create(int size, wxFontFamily family, wxFontStyle style, diff --git a/interface/wx/font.h b/interface/wx/font.h index c8de700f48..cde804883b 100644 --- a/interface/wx/font.h +++ b/interface/wx/font.h @@ -303,7 +303,7 @@ public: wxFont(const wxFont& font); /** - Creates a font object with the specified attributes. + Creates a font object with the specified attributes and size in points. @param pointSize Size in points. See SetPointSize() for more info. @@ -349,7 +349,7 @@ public: wxFontEncoding encoding = wxFONTENCODING_DEFAULT); /** - Creates a font object with the specified attributes. + Creates a font object with the specified attributes and size in pixels. @param pixelSize Size in pixels. See SetPixelSize() for more info. @@ -394,6 +394,22 @@ public: const wxString& faceName = wxEmptyString, wxFontEncoding encoding = wxFONTENCODING_DEFAULT); + /** + Creates a font object using font flags. + + This constructor is similar to the constructors above except it + specifies the font styles such as underlined, italic, bold, ... in a + single @a flags argument instead of using separate arguments for them. + This parameter can be a combination of ::wxFontFlag enum elements. + The meaning of the remaining arguments is the same as in the other + constructors, please see their documentation for details. + + @since 2.9.4 + */ + wxFont(int pointSize, wxFontFamily family, int flags, + const wxString& faceName = wxEmptyString, + wxFontEncoding encoding = wxFONTENCODING_DEFAULT); + /** Constructor from font description string. diff --git a/src/common/fontcmn.cpp b/src/common/fontcmn.cpp index d54521c449..de35aa96d1 100644 --- a/src/common/fontcmn.cpp +++ b/src/common/fontcmn.cpp @@ -128,33 +128,6 @@ wxEMPTY_HANDLERS_TABLE(wxFont) // implementation // ============================================================================ -// ---------------------------------------------------------------------------- -// helper functions -// ---------------------------------------------------------------------------- - -static inline int flags2Style(int flags) -{ - return flags & wxFONTFLAG_ITALIC - ? wxFONTSTYLE_ITALIC - : flags & wxFONTFLAG_SLANT - ? wxFONTSTYLE_SLANT - : wxFONTSTYLE_NORMAL; -} - -static inline int flags2Weight(int flags) -{ - return flags & wxFONTFLAG_LIGHT - ? wxFONTWEIGHT_LIGHT - : flags & wxFONTFLAG_BOLD - ? wxFONTWEIGHT_BOLD - : wxFONTWEIGHT_NORMAL; -} - -static inline bool flags2Underlined(int flags) -{ - return (flags & wxFONTFLAG_UNDERLINED) != 0; -} - // ---------------------------------------------------------------------------- // wxFontBase // ---------------------------------------------------------------------------- @@ -209,8 +182,11 @@ wxFont *wxFontBase::New(int pointSize, const wxString& face, wxFontEncoding encoding) { - return New(pointSize, family, flags2Style(flags), flags2Weight(flags), - flags2Underlined(flags), face, encoding); + return New(pointSize, family, + GetStyleFromFlags(flags), + GetWeightFromFlags(flags), + GetUnderlinedFromFlags(flags), + face, encoding); } /* static */ @@ -220,8 +196,11 @@ wxFont *wxFontBase::New(const wxSize& pixelSize, const wxString& face, wxFontEncoding encoding) { - return New(pixelSize, family, flags2Style(flags), flags2Weight(flags), - flags2Underlined(flags), face, encoding); + return New(pixelSize, family, + GetStyleFromFlags(flags), + GetWeightFromFlags(flags), + GetUnderlinedFromFlags(flags), + face, encoding); } /* static */ diff --git a/src/gtk/font.cpp b/src/gtk/font.cpp index 3ac8f4590a..5ca1b2b600 100644 --- a/src/gtk/font.cpp +++ b/src/gtk/font.cpp @@ -277,6 +277,19 @@ wxFont::wxFont(const wxNativeFontInfo& info) info.GetEncoding() ); } +wxFont::wxFont(int pointSize, + wxFontFamily family, + int flags, + const wxString& face, + wxFontEncoding encoding) +{ + m_refData = new wxFontRefData(pointSize, family, + GetStyleFromFlags(flags), + GetWeightFromFlags(flags), + GetUnderlinedFromFlags(flags), + face, encoding); +} + bool wxFont::Create( int pointSize, wxFontFamily family, wxFontStyle style, diff --git a/src/msw/font.cpp b/src/msw/font.cpp index 376b8b3b87..72294a58b1 100644 --- a/src/msw/font.cpp +++ b/src/msw/font.cpp @@ -778,6 +778,20 @@ wxFont::wxFont(const wxString& fontdesc) (void)Create(info); } +wxFont::wxFont(int pointSize, + wxFontFamily family, + int flags, + const wxString& face, + wxFontEncoding encoding) +{ + m_refData = new wxFontRefData(pointSize, wxDefaultSize, false, + family, + GetStyleFromFlags(flags), + GetWeightFromFlags(flags), + GetUnderlinedFromFlags(flags), + face, encoding); +} + bool wxFont::Create(const wxNativeFontInfo& info, WXHFONT hFont) { UnRef(); -- 2.45.2