+void FontTestCase::NativeFontInfo()
+{
+ unsigned numFonts;
+ const wxFont *pf = GetTestFonts(numFonts);
+ for ( size_t n = 0; n < numFonts; n++ )
+ {
+ wxFont test(*pf++);
+
+ const wxString& nid = test.GetNativeFontInfoDesc();
+ CPPUNIT_ASSERT( !nid.empty() );
+ // documented to be never empty
+
+ wxFont temp;
+ CPPUNIT_ASSERT( temp.SetNativeFontInfo(nid) );
+ CPPUNIT_ASSERT( temp.IsOk() );
+ WX_ASSERT_MESSAGE(
+ ("Test #%lu failed\ndump of test font: \"%s\"\ndump of temp font: \"%s\"", \
+ n, DumpFont(&test), DumpFont(&temp)),
+ temp == test );
+ }
+
+ // test that clearly invalid font info strings do not work
+ wxFont font;
+ CPPUNIT_ASSERT( !font.SetNativeFontInfo("") );
+
+ // 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?
+#if !defined(__WXGTK__) && !defined(__WXX11__)
+ CPPUNIT_ASSERT( !font.SetNativeFontInfo("bloordyblop") );
+#endif
+
+ // 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);
+ CPPUNIT_ASSERT_EQUAL(font, wxFont(font));
+ CPPUNIT_ASSERT_EQUAL(font, wxFont(*font.GetNativeFontInfo()));
+ CPPUNIT_ASSERT_EQUAL(font, wxFont(font.GetNativeFontInfoDesc()));
+ font.SetUnderlined(false);
+ CPPUNIT_ASSERT_EQUAL(font, wxFont(font));
+ CPPUNIT_ASSERT_EQUAL(font, wxFont(*font.GetNativeFontInfo()));
+ CPPUNIT_ASSERT_EQUAL(font, wxFont(font.GetNativeFontInfoDesc()));
+ font.SetUnderlined(true);
+ font.SetStrikethrough(false);
+ CPPUNIT_ASSERT_EQUAL(font, wxFont(font));
+ CPPUNIT_ASSERT_EQUAL(font, wxFont(*font.GetNativeFontInfo()));
+ CPPUNIT_ASSERT_EQUAL(font, wxFont(font.GetNativeFontInfoDesc()));
+ // note: the GetNativeFontInfoUserDesc() doesn't preserve all attributes
+ // according to docs, so it is not tested.
+}
+
+void FontTestCase::NativeFontInfoUserDesc()
+{
+ unsigned numFonts;
+ const wxFont *pf = GetTestFonts(numFonts);
+ for ( size_t n = 0; n < numFonts; n++ )
+ {
+ wxFont test(*pf++);
+
+ const wxString& niud = test.GetNativeFontInfoUserDesc();
+ CPPUNIT_ASSERT( !niud.empty() );
+ // documented to be never empty
+
+ wxFont temp2;
+ CPPUNIT_ASSERT( temp2.SetNativeFontInfoUserDesc(niud) );
+ CPPUNIT_ASSERT( temp2.IsOk() );
+
+#ifdef __WXGTK__
+ // Pango saves/restores all font info in the user-friendly string:
+ WX_ASSERT_MESSAGE(
+ ("Test #%lu failed; native info user desc was \"%s\" for test and \"%s\" for temp2", \
+ n, niud, temp2.GetNativeFontInfoUserDesc()),
+ temp2 == test );
+#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:
+ CPPUNIT_ASSERT_EQUAL( test.GetWeight(), temp2.GetWeight() );
+ CPPUNIT_ASSERT_EQUAL( test.GetStyle(), temp2.GetStyle() );
+
+ // 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() )
+ {
+ CPPUNIT_ASSERT_EQUAL( facename.Upper(), temp2.GetFaceName().Upper() );
+ }
+
+ CPPUNIT_ASSERT_EQUAL( test.GetPointSize(), temp2.GetPointSize() );
+ CPPUNIT_ASSERT_EQUAL( test.GetEncoding(), temp2.GetEncoding() );
+#endif
+ }
+}
+