2009-03-18 11:32:28 -04:00
|
|
|
///////////////////////////////////////////////////////////////////////////////
|
|
|
|
// Name: tests/font/fonttest.cpp
|
|
|
|
// Purpose: wxFont unit test
|
|
|
|
// Author: Francesco Montorsi
|
|
|
|
// Created: 16.3.09
|
|
|
|
// Copyright: (c) 2009 Francesco Montorsi
|
|
|
|
// Licence: wxWindows licence
|
|
|
|
///////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
|
|
|
// ----------------------------------------------------------------------------
|
|
|
|
// headers
|
|
|
|
// ----------------------------------------------------------------------------
|
|
|
|
|
|
|
|
#include "testprec.h"
|
|
|
|
|
|
|
|
#ifdef __BORLANDC__
|
|
|
|
#pragma hdrstop
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifndef WX_PRECOMP
|
|
|
|
#include "wx/wx.h"
|
|
|
|
#endif // WX_PRECOMP
|
|
|
|
|
|
|
|
#include "wx/font.h"
|
|
|
|
|
2012-09-15 19:17:12 -04:00
|
|
|
#include "asserthelper.h"
|
|
|
|
|
2009-03-18 11:32:28 -04:00
|
|
|
// ----------------------------------------------------------------------------
|
2018-09-05 17:05:10 -04:00
|
|
|
// local helpers
|
2009-03-18 11:32:28 -04:00
|
|
|
// ----------------------------------------------------------------------------
|
|
|
|
|
2018-09-05 17:05:10 -04:00
|
|
|
// Returns a point to an array of fonts and fills the output parameter with the
|
|
|
|
// number of elements in this array.
|
|
|
|
static const wxFont *GetTestFonts(unsigned& numFonts)
|
2009-03-18 11:32:28 -04:00
|
|
|
{
|
2018-09-05 17:05:10 -04:00
|
|
|
static const wxFont testfonts[] =
|
2009-05-17 07:51:09 -04:00
|
|
|
{
|
2018-09-05 17:05:10 -04:00
|
|
|
*wxNORMAL_FONT,
|
|
|
|
*wxSMALL_FONT,
|
|
|
|
*wxITALIC_FONT,
|
|
|
|
*wxSWISS_FONT,
|
|
|
|
wxFont(5, wxFONTFAMILY_TELETYPE, wxFONTSTYLE_NORMAL, wxFONTWEIGHT_NORMAL)
|
|
|
|
};
|
2009-03-18 11:32:28 -04:00
|
|
|
|
2018-09-05 17:05:10 -04:00
|
|
|
numFonts = WXSIZEOF(testfonts);
|
2009-03-18 11:32:28 -04:00
|
|
|
|
2018-09-05 17:05:10 -04:00
|
|
|
return testfonts;
|
|
|
|
}
|
2009-03-18 11:32:28 -04:00
|
|
|
|
2009-04-14 14:55:41 -04:00
|
|
|
wxString DumpFont(const wxFont *font)
|
|
|
|
{
|
|
|
|
// dumps the internal properties of a wxFont in the same order they
|
|
|
|
// are checked by wxFontBase::operator==()
|
2009-05-17 07:51:09 -04:00
|
|
|
|
2009-04-14 14:55:41 -04:00
|
|
|
wxASSERT(font->IsOk());
|
2009-05-17 07:51:09 -04:00
|
|
|
|
2009-04-14 14:55:41 -04:00
|
|
|
wxString s;
|
|
|
|
s.Printf(wxS("%d-%d;%d-%d-%d-%d-%d-%s-%d"),
|
|
|
|
font->GetPointSize(),
|
|
|
|
font->GetPixelSize().x,
|
|
|
|
font->GetPixelSize().y,
|
|
|
|
font->GetFamily(),
|
|
|
|
font->GetStyle(),
|
|
|
|
font->GetWeight(),
|
|
|
|
font->GetUnderlined() ? 1 : 0,
|
|
|
|
font->GetFaceName(),
|
|
|
|
font->GetEncoding());
|
|
|
|
|
|
|
|
return s;
|
|
|
|
}
|
2009-03-18 11:32:28 -04:00
|
|
|
|
2018-09-05 17:05:10 -04:00
|
|
|
// ----------------------------------------------------------------------------
|
|
|
|
// the tests
|
|
|
|
// ----------------------------------------------------------------------------
|
|
|
|
|
|
|
|
TEST_CASE("wxFont::Construct", "[font][ctor]")
|
2012-01-23 09:42:56 -05:00
|
|
|
{
|
|
|
|
// The main purpose of this test is to verify that the font ctors below
|
|
|
|
// compile because it's easy to introduce ambiguities due to the number of
|
|
|
|
// overloaded wxFont ctors.
|
|
|
|
|
2018-09-05 17:05:10 -04:00
|
|
|
CHECK( wxFont(10, wxFONTFAMILY_DEFAULT,
|
|
|
|
wxFONTSTYLE_NORMAL,
|
|
|
|
wxFONTWEIGHT_NORMAL).IsOk() );
|
2012-01-23 09:42:56 -05:00
|
|
|
|
2014-01-04 15:07:33 -05:00
|
|
|
#if WXWIN_COMPATIBILITY_3_0
|
2014-08-03 08:47:32 -04:00
|
|
|
// Disable the warning about deprecated wxNORMAL as we use it here
|
|
|
|
// intentionally.
|
|
|
|
#ifdef __VISUALC__
|
|
|
|
#pragma warning(push)
|
|
|
|
#pragma warning(disable:4996)
|
|
|
|
#endif
|
|
|
|
|
2016-02-26 08:36:01 -05:00
|
|
|
wxGCC_WARNING_SUPPRESS(deprecated-declarations)
|
|
|
|
|
2012-01-23 09:42:56 -05:00
|
|
|
// Tests relying on the soon-to-be-deprecated ctor taking ints and not
|
|
|
|
// wxFontXXX enum elements.
|
2018-09-05 17:05:10 -04:00
|
|
|
CHECK( wxFont(10, wxDEFAULT, wxNORMAL, wxNORMAL).IsOk() );
|
2014-08-03 08:47:32 -04:00
|
|
|
|
2016-04-14 22:34:18 -04:00
|
|
|
wxGCC_WARNING_RESTORE(deprecated-declarations)
|
2016-02-26 08:36:01 -05:00
|
|
|
|
2014-08-03 08:47:32 -04:00
|
|
|
#ifdef __VISUALC__
|
|
|
|
#pragma warning(pop)
|
|
|
|
#endif
|
2014-01-04 15:07:33 -05:00
|
|
|
#endif // WXWIN_COMPATIBILITY_3_0
|
2012-01-23 09:42:56 -05:00
|
|
|
}
|
|
|
|
|
2018-09-05 17:08:34 -04:00
|
|
|
TEST_CASE("wxFont::Size", "[font][size]")
|
|
|
|
{
|
|
|
|
const struct Sizes
|
|
|
|
{
|
|
|
|
int specified; // Size in points specified in the ctor.
|
|
|
|
int expected; // Expected GetPointSize() return value,
|
|
|
|
// -1 here means "same as wxNORMAL_FONT".
|
|
|
|
} sizes[] =
|
|
|
|
{
|
|
|
|
{ 9, 9 },
|
|
|
|
{ 10, 10 },
|
|
|
|
{ 11, 11 },
|
|
|
|
{ -1, -1 },
|
|
|
|
{ 70, -1 }, // 70 == wxDEFAULT, should be handled specially
|
|
|
|
{ 90, 90 }, // 90 == wxNORMAL, should not be handled specially
|
|
|
|
};
|
|
|
|
|
|
|
|
const int sizeDefault = wxFont(wxFontInfo()).GetPointSize();
|
|
|
|
|
|
|
|
for ( size_t n = 0; n < WXSIZEOF(sizes); n++ )
|
|
|
|
{
|
|
|
|
const Sizes& size = sizes[n];
|
|
|
|
|
|
|
|
// Note: use the old-style wxFont ctor as wxFontInfo doesn't implement
|
|
|
|
// any compatibility hacks.
|
|
|
|
const wxFont font(size.specified,
|
|
|
|
wxFONTFAMILY_DEFAULT,
|
|
|
|
wxFONTSTYLE_NORMAL,
|
|
|
|
wxFONTWEIGHT_NORMAL);
|
|
|
|
|
|
|
|
int expected = size.expected;
|
|
|
|
if ( expected == -1 )
|
|
|
|
expected = sizeDefault;
|
|
|
|
|
|
|
|
INFO("specified = " << size.specified <<
|
|
|
|
", expected = " << size.expected);
|
|
|
|
CHECK( font.GetPointSize() == expected );
|
|
|
|
}
|
2018-09-05 20:32:53 -04:00
|
|
|
|
|
|
|
// Note that the compatibility hacks only apply to the old ctors, the newer
|
|
|
|
// one, taking wxFontInfo, doesn't support them.
|
|
|
|
CHECK( wxFont(wxFontInfo(70)).GetPointSize() == 70 );
|
|
|
|
CHECK( wxFont(wxFontInfo(90)).GetPointSize() == 90 );
|
2018-09-17 09:20:48 -04:00
|
|
|
|
|
|
|
// Check fractional point sizes as well.
|
|
|
|
wxFont font(wxFontInfo(12.25));
|
|
|
|
CHECK( font.GetFractionalPointSize() == 12.25 );
|
|
|
|
CHECK( font.GetPointSize() == 12 );
|
|
|
|
|
|
|
|
font = *wxNORMAL_FONT;
|
|
|
|
font.SetFractionalPointSize(9.5);
|
|
|
|
CHECK( font.GetFractionalPointSize() == 9.5 );
|
|
|
|
CHECK( font.GetPointSize() == 10 );
|
2018-09-05 17:08:34 -04:00
|
|
|
}
|
|
|
|
|
2018-09-05 19:34:25 -04:00
|
|
|
TEST_CASE("wxFont::Style", "[font][style]")
|
|
|
|
{
|
|
|
|
#if WXWIN_COMPATIBILITY_3_0
|
|
|
|
// Disable the warning about deprecated wxNORMAL as we use it here
|
|
|
|
// intentionally.
|
|
|
|
#ifdef __VISUALC__
|
|
|
|
#pragma warning(push)
|
|
|
|
#pragma warning(disable:4996)
|
|
|
|
#endif
|
|
|
|
|
|
|
|
wxGCC_WARNING_SUPPRESS(deprecated-declarations)
|
|
|
|
|
|
|
|
wxFont fontNormal(10, wxDEFAULT, wxNORMAL, wxNORMAL);
|
|
|
|
CHECK( fontNormal.GetStyle() == wxFONTSTYLE_NORMAL );
|
|
|
|
|
|
|
|
wxFont fontItalic(10, wxDEFAULT, wxITALIC, wxNORMAL);
|
|
|
|
CHECK( fontItalic.GetStyle() == wxFONTSTYLE_ITALIC );
|
|
|
|
|
|
|
|
wxFont fontSlant(10, wxDEFAULT, wxSLANT, wxNORMAL);
|
|
|
|
#ifdef __WXMSW__
|
|
|
|
CHECK( fontSlant.GetStyle() == wxFONTSTYLE_ITALIC );
|
|
|
|
#else
|
|
|
|
CHECK( fontSlant.GetStyle() == wxFONTSTYLE_SLANT );
|
|
|
|
#endif
|
|
|
|
|
|
|
|
wxGCC_WARNING_RESTORE(deprecated-declarations)
|
|
|
|
|
|
|
|
#ifdef __VISUALC__
|
|
|
|
#pragma warning(pop)
|
|
|
|
#endif
|
|
|
|
#endif // WXWIN_COMPATIBILITY_3_0
|
|
|
|
}
|
|
|
|
|
2018-09-05 19:34:25 -04:00
|
|
|
TEST_CASE("wxFont::Weight", "[font][weight]")
|
|
|
|
{
|
2018-09-17 09:20:48 -04:00
|
|
|
wxFont font;
|
|
|
|
font.SetNumericWeight(123);
|
2019-01-09 06:17:23 -05:00
|
|
|
|
|
|
|
// 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
|
2018-09-17 09:20:48 -04:00
|
|
|
CHECK( font.GetNumericWeight() == 123 );
|
2019-01-09 06:17:23 -05:00
|
|
|
#endif
|
|
|
|
|
2018-09-17 09:20:48 -04:00
|
|
|
CHECK( font.GetWeight() == wxFONTWEIGHT_THIN );
|
|
|
|
|
|
|
|
font.SetNumericWeight(wxFONTWEIGHT_SEMIBOLD);
|
|
|
|
CHECK( font.GetNumericWeight() == wxFONTWEIGHT_SEMIBOLD );
|
|
|
|
CHECK( font.GetWeight() == wxFONTWEIGHT_SEMIBOLD );
|
|
|
|
|
2018-09-05 19:34:25 -04:00
|
|
|
#if WXWIN_COMPATIBILITY_3_0
|
|
|
|
// Disable the warning about deprecated wxNORMAL as we use it here
|
|
|
|
// intentionally.
|
|
|
|
#ifdef __VISUALC__
|
|
|
|
#pragma warning(push)
|
|
|
|
#pragma warning(disable:4996)
|
|
|
|
#endif
|
|
|
|
|
|
|
|
wxGCC_WARNING_SUPPRESS(deprecated-declarations)
|
|
|
|
|
|
|
|
wxFont fontNormal(10, wxDEFAULT, wxNORMAL, wxNORMAL);
|
|
|
|
CHECK( fontNormal.GetWeight() == wxFONTWEIGHT_NORMAL );
|
|
|
|
|
|
|
|
wxFont fontBold(10, wxDEFAULT, wxNORMAL, wxBOLD);
|
|
|
|
CHECK( fontBold.GetWeight() == wxFONTWEIGHT_BOLD );
|
|
|
|
|
|
|
|
wxFont fontLight(10, wxDEFAULT, wxNORMAL, wxLIGHT);
|
|
|
|
CHECK( fontLight.GetWeight() == wxFONTWEIGHT_LIGHT );
|
|
|
|
|
|
|
|
wxGCC_WARNING_RESTORE(deprecated-declarations)
|
|
|
|
|
|
|
|
#ifdef __VISUALC__
|
|
|
|
#pragma warning(pop)
|
|
|
|
#endif
|
|
|
|
#endif // WXWIN_COMPATIBILITY_3_0
|
|
|
|
}
|
|
|
|
|
2018-09-05 17:05:10 -04:00
|
|
|
TEST_CASE("wxFont::GetSet", "[font][getters]")
|
2009-03-18 11:32:28 -04:00
|
|
|
{
|
2009-05-17 07:51:09 -04:00
|
|
|
unsigned numFonts;
|
|
|
|
const wxFont *pf = GetTestFonts(numFonts);
|
2010-04-18 18:15:53 -04:00
|
|
|
for ( unsigned n = 0; n < numFonts; n++ )
|
2009-03-18 11:32:28 -04:00
|
|
|
{
|
2009-05-17 07:51:09 -04:00
|
|
|
wxFont test(*pf++);
|
2009-03-18 11:32:28 -04:00
|
|
|
|
|
|
|
// remember: getters can only be called when wxFont::IsOk() == true
|
2018-09-05 17:05:10 -04:00
|
|
|
CHECK( test.IsOk() );
|
2009-03-18 11:32:28 -04:00
|
|
|
|
|
|
|
|
|
|
|
// test Get/SetFaceName()
|
2019-01-09 06:17:23 -05:00
|
|
|
#ifndef __WXQT__
|
2018-09-05 17:05:10 -04:00
|
|
|
CHECK( !test.SetFaceName("a dummy face name") );
|
|
|
|
CHECK( !test.IsOk() );
|
2019-01-09 06:17:23 -05:00
|
|
|
#endif
|
2009-03-18 11:32:28 -04:00
|
|
|
|
2009-05-17 10:01:38 -04:00
|
|
|
// if the call to SetFaceName() below fails on your system/port,
|
|
|
|
// consider adding another branch to this #if
|
|
|
|
#if defined(__WXMSW__) || defined(__WXOSX__)
|
|
|
|
static const char *knownGoodFaceName = "Arial";
|
|
|
|
#else
|
2010-04-18 18:15:53 -04:00
|
|
|
static const char *knownGoodFaceName = "Monospace";
|
2009-05-17 10:01:38 -04:00
|
|
|
#endif
|
|
|
|
|
2010-04-18 18:15:53 -04:00
|
|
|
WX_ASSERT_MESSAGE
|
|
|
|
(
|
|
|
|
("failed to set face name \"%s\" for test font #%u\n"
|
|
|
|
"(this failure is harmless if this face name is not "
|
|
|
|
"available on this system)", knownGoodFaceName, n),
|
|
|
|
test.SetFaceName(knownGoodFaceName)
|
|
|
|
);
|
2018-09-05 17:05:10 -04:00
|
|
|
CHECK( test.IsOk() );
|
2009-03-18 11:32:28 -04:00
|
|
|
|
|
|
|
|
|
|
|
// test Get/SetFamily()
|
|
|
|
|
2009-04-12 18:53:26 -04:00
|
|
|
test.SetFamily( wxFONTFAMILY_ROMAN );
|
2018-09-05 17:05:10 -04:00
|
|
|
CHECK( test.IsOk() );
|
2010-11-21 08:00:13 -05:00
|
|
|
|
|
|
|
// note that there is always the possibility that GetFamily() returns
|
|
|
|
// wxFONTFAMILY_DEFAULT (meaning "unknown" in this case) so that we
|
|
|
|
// consider it as a valid return value
|
|
|
|
const wxFontFamily family = test.GetFamily();
|
|
|
|
if ( family != wxFONTFAMILY_DEFAULT )
|
2018-09-05 17:05:10 -04:00
|
|
|
CHECK( wxFONTFAMILY_ROMAN == family );
|
2009-04-12 18:53:26 -04:00
|
|
|
|
2009-03-18 11:32:28 -04:00
|
|
|
|
|
|
|
// test Get/SetEncoding()
|
|
|
|
|
|
|
|
//test.SetEncoding( wxFONTENCODING_KOI8 );
|
2018-09-05 17:05:10 -04:00
|
|
|
//CHECK( test.IsOk() );
|
|
|
|
//CHECK( wxFONTENCODING_KOI8 == test.GetEncoding() );
|
2009-03-18 11:32:28 -04:00
|
|
|
|
2009-05-17 07:51:09 -04:00
|
|
|
|
|
|
|
// test Get/SetPointSize()
|
|
|
|
|
|
|
|
test.SetPointSize(30);
|
2018-09-05 17:05:10 -04:00
|
|
|
CHECK( test.IsOk() );
|
|
|
|
CHECK( 30 == test.GetPointSize() );
|
2009-05-17 07:51:09 -04:00
|
|
|
|
|
|
|
|
|
|
|
// test Get/SetPixelSize()
|
|
|
|
|
|
|
|
test.SetPixelSize(wxSize(0,30));
|
2018-09-05 17:05:10 -04:00
|
|
|
CHECK( test.IsOk() );
|
|
|
|
CHECK( test.GetPixelSize().GetHeight() <= 30 );
|
2009-05-17 07:51:09 -04:00
|
|
|
// NOTE: the match found by SetPixelSize() may be not 100% precise; it
|
|
|
|
// only grants that a font smaller than the required height will
|
|
|
|
// be selected
|
|
|
|
|
|
|
|
|
|
|
|
// test Get/SetStyle()
|
|
|
|
|
|
|
|
test.SetStyle(wxFONTSTYLE_SLANT);
|
2018-09-05 17:05:10 -04:00
|
|
|
CHECK( test.IsOk() );
|
2009-05-17 07:51:09 -04:00
|
|
|
#ifdef __WXMSW__
|
Replace CppUnit with Catch for unit tests
Drop the legacy CppUnit testing framework used for the unit tests.
Replacing it with Catch has the advantage of not requiring CppUnit
libraries to be installed on the system in order to be able to run
tests (Catch is header-only and a copy of it is now included in the
main repository itself) and, in the future, of being able to write
the tests in a much more natural way.
For now, however, avoid changing the existing tests code as much as
[reasonably] possible to avoid introducing bugs in them and provide
the CppUnit compatibility macros in the new wx/catch_cppunit.h header
which allow to preserve the 99% of the existing code unchanged. Some
of the required changes are:
- Decompose asserts using "a && b" conditions into multiple asserts
checking "a" and "b" independently. This would have been better
even with CppUnit (to know which part of condition exactly failed)
and is required with Catch.
- Use extra parentheses around such conditions when they can't be
easily decomposed in the arrays test, due to the use of macros.
This is not ideal from the point of view of messages given when
the tests fail but will do for now.
- Rewrite asserts using "a || b" as a combination of condition
checks and assert macros. Again, this is better anyhow, and is
required with Catch. Incidentally, this allowed to fix a bug in
the "exec" unit test which didn't leave enough time for the new
process to be launched before trying to kill it.
- Remove multiple CPPUNIT_TEST_SUITE_NAMED_REGISTRATION() macros,
our emulation of this macro can be used only once.
- Provide string conversions using Catch-specific StringMaker for
a couple of types.
- Replace custom wxImage comparison with a Catch-specific matcher
class.
- Remove most of test running logic from test.cpp, in particular don't
parse command line ourselves any longer but use Catch built-in
command line parser. This is a source of a minor regression:
previously, both "Foo" and "FooTestCase" could be used as the name of
the test to run, but now only the latter is accepted.
2017-11-01 14:15:24 -04:00
|
|
|
// on wxMSW wxFONTSTYLE_SLANT==wxFONTSTYLE_ITALIC, so accept the latter
|
|
|
|
// as a valid value too.
|
|
|
|
if ( test.GetStyle() != wxFONTSTYLE_ITALIC )
|
2009-05-17 07:51:09 -04:00
|
|
|
#endif
|
2018-09-05 17:05:10 -04:00
|
|
|
CHECK( wxFONTSTYLE_SLANT == test.GetStyle() );
|
2009-05-17 07:51:09 -04:00
|
|
|
|
|
|
|
// test Get/SetUnderlined()
|
|
|
|
|
|
|
|
test.SetUnderlined(true);
|
2018-09-05 17:05:10 -04:00
|
|
|
CHECK( test.IsOk() );
|
|
|
|
CHECK( test.GetUnderlined() );
|
2009-05-17 07:51:09 -04:00
|
|
|
|
2014-03-11 16:48:20 -04:00
|
|
|
const wxFont fontBase = test.GetBaseFont();
|
2018-09-05 17:05:10 -04:00
|
|
|
CHECK( fontBase.IsOk() );
|
|
|
|
CHECK( !fontBase.GetUnderlined() );
|
|
|
|
CHECK( !fontBase.GetStrikethrough() );
|
|
|
|
CHECK( wxFONTWEIGHT_NORMAL == fontBase.GetWeight() );
|
|
|
|
CHECK( wxFONTSTYLE_NORMAL == fontBase.GetStyle() );
|
2014-03-11 16:48:20 -04:00
|
|
|
|
2012-09-15 19:17:12 -04:00
|
|
|
// test Get/SetStrikethrough()
|
|
|
|
|
|
|
|
test.SetStrikethrough(true);
|
2018-09-05 17:05:10 -04:00
|
|
|
CHECK( test.IsOk() );
|
|
|
|
CHECK( test.GetStrikethrough() );
|
2012-09-15 19:17:12 -04:00
|
|
|
|
2009-05-17 07:51:09 -04:00
|
|
|
|
|
|
|
// test Get/SetWeight()
|
|
|
|
|
|
|
|
test.SetWeight(wxFONTWEIGHT_BOLD);
|
2018-09-05 17:05:10 -04:00
|
|
|
CHECK( test.IsOk() );
|
|
|
|
CHECK( wxFONTWEIGHT_BOLD == test.GetWeight() );
|
2009-05-17 07:51:09 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-09-05 17:05:10 -04:00
|
|
|
TEST_CASE("wxFont::NativeFontInfo", "[font][fontinfo]")
|
2009-05-17 07:51:09 -04:00
|
|
|
{
|
|
|
|
unsigned numFonts;
|
|
|
|
const wxFont *pf = GetTestFonts(numFonts);
|
2017-11-22 15:03:18 -05:00
|
|
|
for ( unsigned n = 0; n < numFonts; n++ )
|
2009-05-17 07:51:09 -04:00
|
|
|
{
|
|
|
|
wxFont test(*pf++);
|
|
|
|
|
2009-03-18 11:32:28 -04:00
|
|
|
const wxString& nid = test.GetNativeFontInfoDesc();
|
2018-09-05 17:05:10 -04:00
|
|
|
CHECK( !nid.empty() );
|
2009-03-25 08:49:04 -04:00
|
|
|
// documented to be never empty
|
2009-05-17 07:51:09 -04:00
|
|
|
|
2009-03-18 11:32:28 -04:00
|
|
|
wxFont temp;
|
2018-09-05 17:05:10 -04:00
|
|
|
CHECK( temp.SetNativeFontInfo(nid) );
|
|
|
|
CHECK( temp.IsOk() );
|
2009-05-17 07:51:09 -04:00
|
|
|
WX_ASSERT_MESSAGE(
|
2017-11-22 15:03:18 -05:00
|
|
|
("Test #%u failed\ndump of test font: \"%s\"\ndump of temp font: \"%s\"", \
|
2009-04-14 14:55:41 -04:00
|
|
|
n, DumpFont(&test), DumpFont(&temp)),
|
2009-04-13 05:03:45 -04:00
|
|
|
temp == test );
|
2009-05-17 07:51:09 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
// test that clearly invalid font info strings do not work
|
|
|
|
wxFont font;
|
2018-09-05 17:05:10 -04:00
|
|
|
CHECK( !font.SetNativeFontInfo("") );
|
2009-05-17 10:12:28 -04:00
|
|
|
|
|
|
|
// pango_font_description_from_string() used by wxFont in wxGTK and wxX11
|
|
|
|
// 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?
|
2019-01-09 06:17:23 -05:00
|
|
|
#if !defined(__WXGTK__) && !defined(__WXX11__) && !defined(__WXQT__)
|
2018-09-05 17:05:10 -04:00
|
|
|
CHECK( !font.SetNativeFontInfo("bloordyblop") );
|
2009-05-17 10:12:28 -04:00
|
|
|
#endif
|
2012-09-15 19:17:12 -04:00
|
|
|
|
|
|
|
// Pango font description doesn't have 'underlined' and 'strikethrough'
|
|
|
|
// attributes, so wxNativeFontInfo implements these itself. Test if these
|
|
|
|
// are properly preserved by wxNativeFontInfo or its string description.
|
|
|
|
font.SetUnderlined(true);
|
|
|
|
font.SetStrikethrough(true);
|
2018-09-05 17:05:10 -04:00
|
|
|
CHECK(font == wxFont(font));
|
|
|
|
CHECK(font == wxFont(*font.GetNativeFontInfo()));
|
|
|
|
CHECK(font == wxFont(font.GetNativeFontInfoDesc()));
|
2012-09-15 19:17:12 -04:00
|
|
|
font.SetUnderlined(false);
|
2018-09-05 17:05:10 -04:00
|
|
|
CHECK(font == wxFont(font));
|
|
|
|
CHECK(font == wxFont(*font.GetNativeFontInfo()));
|
|
|
|
CHECK(font == wxFont(font.GetNativeFontInfoDesc()));
|
2012-09-15 19:17:12 -04:00
|
|
|
font.SetUnderlined(true);
|
|
|
|
font.SetStrikethrough(false);
|
2018-09-05 17:05:10 -04:00
|
|
|
CHECK(font == wxFont(font));
|
|
|
|
CHECK(font == wxFont(*font.GetNativeFontInfo()));
|
|
|
|
CHECK(font == wxFont(font.GetNativeFontInfoDesc()));
|
2012-09-15 19:17:12 -04:00
|
|
|
// note: the GetNativeFontInfoUserDesc() doesn't preserve all attributes
|
|
|
|
// according to docs, so it is not tested.
|
2009-05-17 07:51:09 -04:00
|
|
|
}
|
|
|
|
|
2018-09-05 17:05:10 -04:00
|
|
|
TEST_CASE("wxFont::NativeFontInfoUserDesc", "[font][fontinfo]")
|
2009-05-17 07:51:09 -04:00
|
|
|
{
|
|
|
|
unsigned numFonts;
|
|
|
|
const wxFont *pf = GetTestFonts(numFonts);
|
2017-11-22 15:03:18 -05:00
|
|
|
for ( unsigned n = 0; n < numFonts; n++ )
|
2009-05-17 07:51:09 -04:00
|
|
|
{
|
|
|
|
wxFont test(*pf++);
|
2009-03-25 08:49:04 -04:00
|
|
|
|
2009-03-18 11:32:28 -04:00
|
|
|
const wxString& niud = test.GetNativeFontInfoUserDesc();
|
2018-09-05 17:05:10 -04:00
|
|
|
CHECK( !niud.empty() );
|
2009-03-25 08:49:04 -04:00
|
|
|
// documented to be never empty
|
2009-05-17 07:51:09 -04:00
|
|
|
|
2009-03-18 11:32:28 -04:00
|
|
|
wxFont temp2;
|
2018-09-05 17:05:10 -04:00
|
|
|
CHECK( temp2.SetNativeFontInfoUserDesc(niud) );
|
|
|
|
CHECK( temp2.IsOk() );
|
2009-03-25 08:49:04 -04:00
|
|
|
|
|
|
|
#ifdef __WXGTK__
|
|
|
|
// Pango saves/restores all font info in the user-friendly string:
|
2009-05-17 07:51:09 -04:00
|
|
|
WX_ASSERT_MESSAGE(
|
2017-11-22 15:03:18 -05:00
|
|
|
("Test #%u failed; native info user desc was \"%s\" for test and \"%s\" for temp2", \
|
2009-04-13 14:34:27 -04:00
|
|
|
n, niud, temp2.GetNativeFontInfoUserDesc()),
|
2009-04-13 05:03:45 -04:00
|
|
|
temp2 == test );
|
2009-03-25 08:49:04 -04:00
|
|
|
#else
|
|
|
|
// NOTE: as documented GetNativeFontInfoUserDesc/SetNativeFontInfoUserDesc
|
|
|
|
// are not granted to save/restore all font info.
|
|
|
|
// In fact e.g. the font family is not saved at all; test only those
|
|
|
|
// info which GetNativeFontInfoUserDesc() does indeed save:
|
2018-09-05 17:05:10 -04:00
|
|
|
CHECK( test.GetWeight() == temp2.GetWeight() );
|
|
|
|
CHECK( test.GetStyle() == temp2.GetStyle() );
|
2009-03-25 08:49:04 -04:00
|
|
|
|
2009-05-17 07:51:09 -04:00
|
|
|
// if the original face name was empty, it means that any face name (in
|
|
|
|
// this family) can be used for the new font so we shouldn't be
|
|
|
|
// surprised to find that they differ in this case
|
|
|
|
const wxString facename = test.GetFaceName();
|
|
|
|
if ( !facename.empty() )
|
|
|
|
{
|
2018-09-05 17:05:10 -04:00
|
|
|
CHECK( facename.Upper() == temp2.GetFaceName().Upper() );
|
2009-05-17 07:51:09 -04:00
|
|
|
}
|
2009-03-25 08:49:04 -04:00
|
|
|
|
2018-09-05 17:05:10 -04:00
|
|
|
CHECK( test.GetPointSize() == temp2.GetPointSize() );
|
|
|
|
CHECK( test.GetEncoding() == temp2.GetEncoding() );
|
2009-03-25 08:49:04 -04:00
|
|
|
#endif
|
2009-03-18 11:32:28 -04:00
|
|
|
}
|
2020-01-15 18:07:06 -05:00
|
|
|
|
|
|
|
// Test for a bug with handling fractional font sizes in description
|
|
|
|
// strings (see #18590).
|
|
|
|
wxFont font(*wxNORMAL_FONT);
|
|
|
|
|
2020-04-21 12:00:04 -04:00
|
|
|
static const double sizes[] = { 12.0, 10.5, 13.8, 10.123, 11.1 };
|
2020-01-15 18:07:06 -05:00
|
|
|
for ( unsigned n = 0; n < WXSIZEOF(sizes); n++ )
|
|
|
|
{
|
|
|
|
font.SetFractionalPointSize(sizes[n]);
|
|
|
|
|
|
|
|
// Just setting the font can slightly change it because of rounding
|
|
|
|
// errors, so don't expect the actual size to be exactly equal to what
|
|
|
|
// we used -- but close enough.
|
2020-04-21 12:00:04 -04:00
|
|
|
const double sizeUsed = font.GetFractionalPointSize();
|
2020-01-15 18:07:06 -05:00
|
|
|
CHECK( sizeUsed == Approx(sizes[n]).epsilon(0.001) );
|
|
|
|
|
|
|
|
const wxString& desc = font.GetNativeFontInfoDesc();
|
|
|
|
INFO("Font description: " << desc);
|
|
|
|
CHECK( font.SetNativeFontInfo(desc) );
|
|
|
|
|
|
|
|
// Notice that here we use the exact comparison, there is no reason for
|
|
|
|
// a differently rounded size to be used.
|
|
|
|
CHECK( font.GetFractionalPointSize() == sizeUsed );
|
|
|
|
}
|
2009-03-18 11:32:28 -04:00
|
|
|
}
|