Add wxFontInfo ctor taking fractional font size in points
And implement support for it in the major ports. Also add wxFontInfo::GetFractionalPointSize().
This commit is contained in:
@@ -129,14 +129,23 @@ public:
|
||||
// Default ctor uses the default font size appropriate for the current
|
||||
// platform.
|
||||
wxFontInfo()
|
||||
{ InitPointSize(-1); }
|
||||
{ InitPointSize(-1.0f); }
|
||||
|
||||
// These ctors specify the font size, either in points or in pixels.
|
||||
explicit wxFontInfo(int pointSize)
|
||||
// Point size is a floating point number, however we also accept all
|
||||
// integer sizes using the simple template ctor below.
|
||||
explicit wxFontInfo(float pointSize)
|
||||
{ InitPointSize(pointSize); }
|
||||
explicit wxFontInfo(const wxSize& pixelSize) : m_pixelSize(pixelSize)
|
||||
{ Init(); }
|
||||
|
||||
// Need to define this one to avoid casting double to int too.
|
||||
explicit wxFontInfo(double pointSize)
|
||||
{ InitPointSize(pointSize); }
|
||||
template <typename T>
|
||||
explicit wxFontInfo(T pointSize)
|
||||
{ InitPointSize(ToFloatPointSize(pointSize)); }
|
||||
|
||||
// Setters for the various attributes. All of them return the object itself
|
||||
// so that the calls to them could be chained.
|
||||
wxFontInfo& Family(wxFontFamily family)
|
||||
@@ -174,7 +183,8 @@ public:
|
||||
// various pieces of the font description.
|
||||
|
||||
bool IsUsingSizeInPixels() const { return m_pixelSize != wxDefaultSize; }
|
||||
int GetPointSize() const { return m_pointSize; }
|
||||
float GetFractionalPointSize() const { return m_pointSize; }
|
||||
int GetPointSize() const { return ToIntPointSize(m_pointSize); }
|
||||
wxSize GetPixelSize() const { return m_pixelSize; }
|
||||
wxFontFamily GetFamily() const { return m_family; }
|
||||
const wxString& GetFaceName() const { return m_faceName; }
|
||||
@@ -245,7 +255,7 @@ private:
|
||||
m_encoding = wxFONTENCODING_DEFAULT;
|
||||
}
|
||||
|
||||
void InitPointSize(int pointSize)
|
||||
void InitPointSize(float pointSize)
|
||||
{
|
||||
Init();
|
||||
|
||||
@@ -264,10 +274,9 @@ private:
|
||||
}
|
||||
|
||||
// The size information: if m_pixelSize is valid (!= wxDefaultSize), then
|
||||
// it is used. Otherwise m_pointSize is used, taking into account that if
|
||||
// it is == -1, it means that the platform dependent font size should be
|
||||
// used.
|
||||
int m_pointSize;
|
||||
// it is used. Otherwise m_pointSize is used, except if it is < 0, which
|
||||
// means that the platform dependent font size should be used instead.
|
||||
float m_pointSize;
|
||||
wxSize m_pixelSize;
|
||||
|
||||
wxFontFamily m_family;
|
||||
|
@@ -38,7 +38,7 @@ public:
|
||||
|
||||
wxFont(const wxFontInfo& info)
|
||||
{
|
||||
Create(info.GetPointSize(),
|
||||
Create(info.GetFractionalPointSize(),
|
||||
info.GetFamily(),
|
||||
info.GetStyle(),
|
||||
info.GetWeight(),
|
||||
|
@@ -322,9 +322,16 @@ public:
|
||||
/**
|
||||
Constructor setting the font size in points to use.
|
||||
|
||||
The canonical type of @a pointSize argument is @c float, however any
|
||||
other integer type, as well as @c double, is also accepted for
|
||||
compatibility.
|
||||
|
||||
Notice that until wxWidgets 3.1.2, the type could only be @c int.
|
||||
|
||||
@see wxFont::SetPointSize()
|
||||
*/
|
||||
explicit wxFontInfo(int pointSize);
|
||||
template <typename T>
|
||||
explicit wxFontInfo(T pointSize);
|
||||
|
||||
/**
|
||||
Constructor setting the font size in pixels to use.
|
||||
|
@@ -47,7 +47,7 @@ class wxFontRefData : public wxGDIRefData
|
||||
{
|
||||
public:
|
||||
// from broken down font parameters, also default ctor
|
||||
wxFontRefData(int size = -1,
|
||||
wxFontRefData(float size = -1.0f,
|
||||
wxFontFamily family = wxFONTFAMILY_DEFAULT,
|
||||
wxFontStyle style = wxFONTSTYLE_NORMAL,
|
||||
wxFontWeight weight = wxFONTWEIGHT_NORMAL,
|
||||
@@ -80,7 +80,7 @@ public:
|
||||
|
||||
protected:
|
||||
// common part of all ctors
|
||||
void Init(int pointSize,
|
||||
void Init(float pointSize,
|
||||
wxFontFamily family,
|
||||
wxFontStyle style,
|
||||
wxFontWeight weight,
|
||||
@@ -106,7 +106,7 @@ private:
|
||||
// wxFontRefData
|
||||
// ----------------------------------------------------------------------------
|
||||
|
||||
void wxFontRefData::Init(int pointSize,
|
||||
void wxFontRefData::Init(float pointSize,
|
||||
wxFontFamily family,
|
||||
wxFontStyle style,
|
||||
wxFontWeight weight,
|
||||
@@ -133,8 +133,11 @@ void wxFontRefData::Init(int pointSize,
|
||||
}
|
||||
|
||||
SetStyle( style );
|
||||
m_nativeFontInfo.SetPointSize( pointSize == -1 ? wxDEFAULT_FONT_SIZE
|
||||
: pointSize );
|
||||
m_nativeFontInfo.SetFractionalPointSize
|
||||
(
|
||||
pointSize < 0 ? static_cast<float>(wxDEFAULT_FONT_SIZE)
|
||||
: pointSize
|
||||
);
|
||||
SetWeight( weight );
|
||||
SetUnderlined( underlined );
|
||||
SetStrikethrough( strikethrough );
|
||||
@@ -157,7 +160,7 @@ wxFontRefData::wxFontRefData( const wxFontRefData& data )
|
||||
{
|
||||
}
|
||||
|
||||
wxFontRefData::wxFontRefData(int size, wxFontFamily family, wxFontStyle style,
|
||||
wxFontRefData::wxFontRefData(float size, wxFontFamily family, wxFontStyle style,
|
||||
wxFontWeight weight, bool underlined, bool strikethrough,
|
||||
const wxString& faceName,
|
||||
wxFontEncoding encoding)
|
||||
@@ -282,7 +285,7 @@ wxFont::wxFont(const wxNativeFontInfo& info)
|
||||
|
||||
wxFont::wxFont(const wxFontInfo& info)
|
||||
{
|
||||
m_refData = new wxFontRefData(info.GetPointSize(),
|
||||
m_refData = new wxFontRefData(info.GetFractionalPointSize(),
|
||||
info.GetFamily(),
|
||||
info.GetStyle(),
|
||||
info.GetWeight(),
|
||||
@@ -308,7 +311,8 @@ bool wxFont::Create( int pointSize,
|
||||
|
||||
AccountForCompatValues(pointSize, style, weight);
|
||||
|
||||
m_refData = new wxFontRefData(pointSize, family, style, weight,
|
||||
m_refData = new wxFontRefData(wxFontInfo::ToFloatPointSize(pointSize),
|
||||
family, style, weight,
|
||||
underlined, false, face, encoding);
|
||||
|
||||
return true;
|
||||
|
@@ -60,12 +60,12 @@ public:
|
||||
// constructors
|
||||
wxFontRefData()
|
||||
{
|
||||
Init(-1, wxSize(0,0), false, wxFONTFAMILY_DEFAULT, wxFONTSTYLE_NORMAL,
|
||||
Init(-1.0f, wxSize(0,0), false, wxFONTFAMILY_DEFAULT, wxFONTSTYLE_NORMAL,
|
||||
wxFONTWEIGHT_NORMAL, false, false, wxEmptyString,
|
||||
wxFONTENCODING_DEFAULT);
|
||||
}
|
||||
|
||||
wxFontRefData(int size,
|
||||
wxFontRefData(float size,
|
||||
const wxSize& pixelSize,
|
||||
bool sizeUsingPixels,
|
||||
wxFontFamily family,
|
||||
@@ -267,7 +267,7 @@ public:
|
||||
|
||||
protected:
|
||||
// common part of all ctors
|
||||
void Init(int size,
|
||||
void Init(float size,
|
||||
const wxSize& pixelSize,
|
||||
bool sizeUsingPixels,
|
||||
wxFontFamily family,
|
||||
@@ -342,7 +342,7 @@ protected:
|
||||
// wxFontRefData
|
||||
// ----------------------------------------------------------------------------
|
||||
|
||||
void wxFontRefData::Init(int pointSize,
|
||||
void wxFontRefData::Init(float pointSize,
|
||||
const wxSize& pixelSize,
|
||||
bool sizeUsingPixels,
|
||||
wxFontFamily family,
|
||||
@@ -362,9 +362,12 @@ void wxFontRefData::Init(int pointSize,
|
||||
}
|
||||
else
|
||||
{
|
||||
m_nativeFontInfo.SetPointSize(pointSize == -1
|
||||
m_nativeFontInfo.SetFractionalPointSize
|
||||
(
|
||||
pointSize < 0
|
||||
? wxNORMAL_FONT->GetPointSize()
|
||||
: pointSize);
|
||||
: pointSize
|
||||
);
|
||||
}
|
||||
|
||||
SetStyle(style);
|
||||
@@ -793,7 +796,7 @@ wxFont::wxFont(const wxString& fontdesc)
|
||||
|
||||
wxFont::wxFont(const wxFontInfo& info)
|
||||
{
|
||||
m_refData = new wxFontRefData(info.GetPointSize(),
|
||||
m_refData = new wxFontRefData(info.GetFractionalPointSize(),
|
||||
info.GetPixelSize(),
|
||||
info.IsUsingSizeInPixels(),
|
||||
info.GetFamily(),
|
||||
@@ -828,7 +831,8 @@ bool wxFont::DoCreate(int pointSize,
|
||||
|
||||
AccountForCompatValues(pointSize, style, weight);
|
||||
|
||||
m_refData = new wxFontRefData(pointSize, pixelSize, sizeUsingPixels,
|
||||
m_refData = new wxFontRefData(wxFontInfo::ToFloatPointSize(pointSize),
|
||||
pixelSize, sizeUsingPixels,
|
||||
family, style, weight,
|
||||
underlined, false, faceName, encoding);
|
||||
|
||||
|
Reference in New Issue
Block a user