Various wxFont fixes in wxQt

Implement point/pixel size accessors correctly.

Implement support for strike-through fonts.

Also implement DoSetNativeFontInfo() for wxQt.

Make wxFont unit test pass by accounting for Qt-specific aspects.

Closes https://github.com/wxWidgets/wxWidgets/pull/1113
This commit is contained in:
chris2oph 2019-01-09 11:17:23 +00:00 committed by Vadim Zeitlin
parent ebb50551c4
commit dd306cac77
4 changed files with 67 additions and 4 deletions

View File

@ -50,21 +50,26 @@ public:
wxFontEncoding encoding = wxFONTENCODING_DEFAULT);
// accessors: get the font characteristics
virtual int GetPointSize() const wxOVERRIDE;
virtual float GetFractionalPointSize() const wxOVERRIDE;
virtual wxSize GetPixelSize() const wxOVERRIDE;
virtual wxFontStyle GetStyle() const;
virtual int GetNumericWeight() const wxOVERRIDE;
virtual bool GetUnderlined() const;
virtual wxString GetFaceName() const;
virtual wxFontEncoding GetEncoding() const;
virtual const wxNativeFontInfo *GetNativeFontInfo() const;
virtual bool GetStrikethrough() const wxOVERRIDE;
// change the font characteristics
virtual void SetFractionalPointSize(float pointSize) wxOVERRIDE;
virtual void SetPixelSize(const wxSize& pixelSize) wxOVERRIDE;
virtual void SetFamily( wxFontFamily family );
virtual void SetStyle( wxFontStyle style );
virtual void SetNumericWeight(int weight) wxOVERRIDE;
virtual bool SetFaceName(const wxString& facename);
virtual void SetUnderlined( bool underlined );
virtual void SetStrikethrough(bool strikethrough) wxOVERRIDE;
virtual void SetEncoding(wxFontEncoding encoding);
wxDECLARE_COMMON_FONT_METHODS();
@ -75,6 +80,7 @@ protected:
virtual wxGDIRefData *CreateGDIRefData() const;
virtual wxGDIRefData *CloneGDIRefData(const wxGDIRefData *data) const;
virtual wxFontFamily DoGetFamily() const;
virtual void DoSetNativeFontInfo(const wxNativeFontInfo& info) wxOVERRIDE;
wxDECLARE_DYNAMIC_CLASS(wxFont);

View File

@ -439,8 +439,7 @@ bool wxFontBase::operator==(const wxFont& font) const
// in wxGTK1 GetPixelSize() calls GetInternalFont() which uses
// operator==() resulting in infinite recursion so we can't use it
// in that port
// in wxQT, GetPixelSize is too slow to be used here
#if (!defined(__WXGTK__) || defined(__WXGTK20__)) && !defined(__WXQT__)
#if (!defined(__WXGTK__) || defined(__WXGTK20__))
GetPixelSize() == font.GetPixelSize() &&
#endif
GetFamily() == font.GetFamily() &&

View File

@ -135,7 +135,7 @@ public:
if ( info.IsUsingSizeInPixels() )
m_nativeFontInfo.SetPixelSize(info.GetPixelSize());
else
m_nativeFontInfo.SetFractionalPointSize(info.GetFractionalPointSize());
m_nativeFontInfo.SetSizeOrDefault(info.GetFractionalPointSize());
m_nativeFontInfo.SetStyle(info.GetStyle());
m_nativeFontInfo.SetWeight(info.GetWeight());
@ -236,11 +236,21 @@ bool wxFont::Create(wxSize size, wxFontFamily family, wxFontStyle style,
return true;
}
int wxFont::GetPointSize() const
{
return M_FONTDATA.wxNativeFontInfo::GetPointSize();
}
float wxFont::GetFractionalPointSize() const
{
return M_FONTDATA.GetFractionalPointSize();
}
wxSize wxFont::GetPixelSize() const
{
return M_FONTDATA.GetPixelSize();
}
wxFontStyle wxFont::GetStyle() const
{
return M_FONTDATA.GetStyle();
@ -271,6 +281,12 @@ const wxNativeFontInfo *wxFont::GetNativeFontInfo() const
return &M_FONTDATA;
}
bool wxFont::GetStrikethrough() const
{
return M_FONTDATA.GetStrikethrough();
}
void wxFont::SetFractionalPointSize(float pointSize)
{
AllocExclusive();
@ -278,6 +294,13 @@ void wxFont::SetFractionalPointSize(float pointSize)
M_FONTDATA.SetFractionalPointSize(pointSize);
}
void wxFont::SetPixelSize(const wxSize& pixelSize)
{
AllocExclusive();
M_FONTDATA.SetPixelSize(pixelSize);
}
bool wxFont::SetFaceName(const wxString& facename)
{
AllocExclusive();
@ -313,6 +336,13 @@ void wxFont::SetUnderlined( bool underlined )
M_FONTDATA.SetUnderlined(underlined);
}
void wxFont::SetStrikethrough(bool strikethrough)
{
AllocExclusive();
M_FONTDATA.SetStrikethrough(strikethrough);
}
void wxFont::SetEncoding(wxFontEncoding encoding)
{
AllocExclusive();
@ -320,6 +350,18 @@ void wxFont::SetEncoding(wxFontEncoding encoding)
M_FONTDATA.SetEncoding(encoding);
}
void wxFont::DoSetNativeFontInfo(const wxNativeFontInfo& info)
{
SetFractionalPointSize(info.GetPointSize());
SetFamily(info.GetFamily());
SetStyle(info.GetStyle());
SetNumericWeight(info.GetWeight());
SetUnderlined(info.GetUnderlined());
SetStrikethrough(info.GetStrikethrough());
SetFaceName(info.GetFaceName());
SetEncoding(info.GetEncoding());
}
wxGDIRefData *wxFont::CreateGDIRefData() const
{
return new wxFontRefData;
@ -353,6 +395,11 @@ float wxNativeFontInfo::GetFractionalPointSize() const
return m_qtFont.pointSizeF();
}
wxSize wxNativeFontInfo::GetPixelSize() const
{
return wxSize(0, m_qtFont.pixelSize());
}
wxFontStyle wxNativeFontInfo::GetStyle() const
{
switch (m_qtFont.style())

View File

@ -197,7 +197,16 @@ TEST_CASE("wxFont::Weight", "[font][weight]")
{
wxFont font;
font.SetNumericWeight(123);
// WX to QT font weight conversions do not map directly which is why we
// check if the numeric weight is within a range rather than checking for
// an exact match.
#ifdef __WXQT__
CHECK( ( font.GetNumericWeight() > 113 && font.GetNumericWeight() < 133 ) );
#else
CHECK( font.GetNumericWeight() == 123 );
#endif
CHECK( font.GetWeight() == wxFONTWEIGHT_THIN );
font.SetNumericWeight(wxFONTWEIGHT_SEMIBOLD);
@ -244,8 +253,10 @@ TEST_CASE("wxFont::GetSet", "[font][getters]")
// test Get/SetFaceName()
#ifndef __WXQT__
CHECK( !test.SetFaceName("a dummy face name") );
CHECK( !test.IsOk() );
#endif
// if the call to SetFaceName() below fails on your system/port,
// consider adding another branch to this #if
@ -370,7 +381,7 @@ TEST_CASE("wxFont::NativeFontInfo", "[font][fontinfo]")
// never returns an error at all so this assertion fails there -- and as it
// doesn't seem to be possible to do anything about it maybe we should
// change wxMSW and other ports to also accept any strings?
#if !defined(__WXGTK__) && !defined(__WXX11__)
#if !defined(__WXGTK__) && !defined(__WXX11__) && !defined(__WXQT__)
CHECK( !font.SetNativeFontInfo("bloordyblop") );
#endif