added convenient wxFont::Make{Bold,Italic,Smaller,Larger} and Scale() methods

git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@61033 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
Vadim Zeitlin
2009-06-12 20:11:21 +00:00
parent 6541fd4b27
commit f76c075805
15 changed files with 141 additions and 62 deletions

View File

@@ -346,6 +346,7 @@ All (GUI):
- Added wxMouseEventsManager.
- Building OpenGL library is now enabled by default.
- Improve wxTreeCtrl::ScrollTo() in generic version (Raanan Barzel).
- Added wxFont::Make{Bold,Italic,Smaller,Larger} and Scale() methods.
- Added wxDC::CopyAttributes() and use it in wxBufferedDC.
- Added wxTextWrapper helper class useful for wrapping lines of text.

View File

@@ -119,7 +119,7 @@ public:
virtual void SetUnderlined(bool underlined);
virtual void SetEncoding(wxFontEncoding encoding);
WXDECLARE_COMPAT_SETTERS
wxDECLARE_COMMON_FONT_METHODS();
// implementation only from now on
// -------------------------------

View File

@@ -88,7 +88,7 @@ public:
virtual void SetUnderlined(bool underlined);
virtual void SetEncoding(wxFontEncoding encoding);
WXDECLARE_COMPAT_SETTERS
wxDECLARE_COMMON_FONT_METHODS();
// Unofficial API, don't use
virtual void SetNoAntiAliasing(bool no = true);

View File

@@ -276,7 +276,7 @@ WXDLLIMPEXP_CORE bool wxFromString(const wxString& str, wxFontBase* font);
#if FUTURE_WXWIN_COMPATIBILITY_3_0
#define WXDECLARE_COMPAT_SETTERS \
#define wxDECLARE_FONT_COMPAT_SETTER \
wxDEPRECATED_FUTURE( void SetFamily(int family) ) \
{ SetFamily((wxFontFamily)family); } \
wxDEPRECATED_FUTURE( void SetStyle(int style) ) \
@@ -290,9 +290,20 @@ WXDLLIMPEXP_CORE bool wxFromString(const wxString& str, wxFontBase* font);
wxDEPRECATED_FUTURE( void SetWeight(wxDeprecatedGUIConstants weight) ) \
{ SetWeight((wxFontWeight)weight); }
#else
#define WXDECLARE_COMPAT_SETTERS /*empty*/
#define wxDECLARE_FONT_COMPAT_SETTER /*empty*/
#endif
// this macro must be used in all derived wxFont classes declarations
#define wxDECLARE_COMMON_FONT_METHODS() \
wxDECLARE_FONT_COMPAT_SETTER \
\
/* functions for creating fonts based on this one */ \
wxFont MakeBold() const; \
wxFont MakeItalic() const; \
wxFont MakeLarger() const { return Scale(1.2f); } \
wxFont MakeSmaller() const { return Scale(1/1.2f); } \
wxFont Scale(float x) const
// include the real class declaration
#if defined(__WXPALMOS__)
#include "wx/palmos/font.h"

View File

@@ -95,7 +95,7 @@ public:
virtual void SetUnderlined( bool underlined );
virtual void SetEncoding(wxFontEncoding encoding);
WXDECLARE_COMPAT_SETTERS
wxDECLARE_COMMON_FONT_METHODS();
virtual void SetNoAntiAliasing( bool no = true );
virtual bool GetNoAntiAliasing() const ;

View File

@@ -109,7 +109,7 @@ public:
virtual void SetUnderlined( bool underlined );
virtual void SetEncoding(wxFontEncoding encoding);
WXDECLARE_COMPAT_SETTERS
wxDECLARE_COMMON_FONT_METHODS();
virtual void SetNoAntiAliasing( bool no = true );
virtual bool GetNoAntiAliasing() const ;

View File

@@ -104,7 +104,7 @@ public:
virtual void SetUnderlined(bool underlined);
virtual void SetEncoding(wxFontEncoding encoding);
WXDECLARE_COMPAT_SETTERS
wxDECLARE_COMMON_FONT_METHODS();
// Unofficial API, don't use
virtual void SetNoAntiAliasing(bool no = true);

View File

@@ -99,7 +99,7 @@ public:
virtual void SetUnderlined(bool underlined);
virtual void SetEncoding(wxFontEncoding encoding);
WXDECLARE_COMPAT_SETTERS
wxDECLARE_COMMON_FONT_METHODS();
// Implementation

View File

@@ -135,7 +135,7 @@ public:
virtual void SetUnderlined(bool underlined);
virtual void SetEncoding(wxFontEncoding encoding);
WXDECLARE_COMPAT_SETTERS
wxDECLARE_COMMON_FONT_METHODS();
virtual bool IsFixedWidth() const;

View File

@@ -109,7 +109,7 @@ public:
virtual void SetUnderlined(bool bUnderlined);
virtual void SetEncoding(wxFontEncoding vEncoding);
WXDECLARE_COMPAT_SETTERS
wxDECLARE_COMMON_FONT_METHODS();
//
// For internal use only!

View File

@@ -113,7 +113,7 @@ public:
virtual void SetUnderlined(bool underlined);
virtual void SetEncoding(wxFontEncoding encoding);
WXDECLARE_COMPAT_SETTERS
wxDECLARE_COMMON_FONT_METHODS();
// implementation only from now on
// -------------------------------

View File

@@ -116,7 +116,7 @@ public:
virtual void SetUnderlined(bool underlined);
virtual void SetEncoding(wxFontEncoding encoding);
WXDECLARE_COMPAT_SETTERS
wxDECLARE_COMMON_FONT_METHODS();
virtual bool IsFixedWidth() const;

View File

@@ -98,7 +98,7 @@ public:
virtual void SetUnderlined(bool underlined);
virtual void SetEncoding(wxFontEncoding encoding);
WXDECLARE_COMPAT_SETTERS
wxDECLARE_COMMON_FONT_METHODS();
virtual void SetNoAntiAliasing( bool no = TRUE );
virtual bool GetNoAntiAliasing() const ;

View File

@@ -523,6 +523,53 @@ public:
//@}
/**
@name Similar fonts creation
The functions in this section create a font similar to the given one
but with its weight, style or size changed.
*/
//@{
/**
Return a bold version of this font.
*/
wxFont MakeBold() const;
/**
Return an italic version of this font.
*/
wxFont MakeItalic() const;
/**
Return a larger version of this font.
The font size is multiplied by CSS specification inspired factor of @c
1.2.
@see MakeSmaller(), Scale()
*/
wxFont MakeLarger() const;
/**
Return a smaller version of this font.
The font size is divided by CSS specification inspired factor of @c
1.2.
@see MakeLarger(), Scale()
*/
wxFont MakeSmaller() const;
/**
Return a scaled version of this font.
The font size is multiplied by the given factor (which may be less than
1 to create a smaller version of the font).
*/
wxFont Scale(float x) const;
//@}
/**
@name Setters

View File

@@ -421,6 +421,26 @@ bool wxFontBase::SetFaceName(const wxString& facename)
return true;
}
wxFont wxFont::MakeBold() const
{
wxFont font(*this);
font.SetWeight(wxFONTWEIGHT_BOLD);
return font;
}
wxFont wxFont::MakeItalic() const
{
wxFont font(*this);
font.SetStyle(wxFONTSTYLE_ITALIC);
return font;
}
wxFont wxFont::Scale(float x) const
{
wxFont font(*this);
font.SetPointSize(int(x*GetPointSize() + 0.5));
return font;
}
// ----------------------------------------------------------------------------
// wxNativeFontInfo