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.
This commit is contained in:
Vadim Zeitlin
2018-09-12 20:19:57 +02:00
parent 24c83625f6
commit f7a7fe6c4a
4 changed files with 14 additions and 12 deletions

View File

@@ -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().

View File

@@ -133,11 +133,7 @@ void wxFontRefData::Init(float pointSize,
}
SetStyle( style );
m_nativeFontInfo.SetFractionalPointSize
(
pointSize < 0 ? static_cast<float>(wxDEFAULT_FONT_SIZE)
: pointSize
);
m_nativeFontInfo.SetSizeOrDefault(pointSize);
SetNumericWeight( weight );
SetUnderlined( underlined );
SetStrikethrough( strikethrough );

View File

@@ -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);

View File

@@ -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);