+ CreateStatusBar();
+ SetStatusText(wxT("Welcome to wxWidgets font demo!"));
+#endif // wxUSE_STATUSBAR
+}
+
+// --------------------------------------------------------
+
+class MyEncodingEnumerator : public wxFontEnumerator
+{
+public:
+ MyEncodingEnumerator()
+ { m_n = 0; }
+
+ const wxString& GetText() const
+ { return m_text; }
+
+protected:
+ virtual bool OnFontEncoding(const wxString& facename,
+ const wxString& encoding)
+ {
+ wxString text;
+ text.Printf(wxT("Encoding %u: %s (available in facename '%s')\n"),
+ (unsigned int) ++m_n, encoding.c_str(), facename.c_str());
+ m_text += text;
+ return true;
+ }
+
+private:
+ size_t m_n;
+ wxString m_text;
+};
+
+void MyFrame::OnEnumerateEncodings(wxCommandEvent& WXUNUSED(event))
+{
+ MyEncodingEnumerator fontEnumerator;
+
+ fontEnumerator.EnumerateEncodings();
+
+ wxLogMessage(wxT("Enumerating all available encodings:\n%s"),
+ fontEnumerator.GetText().c_str());
+}
+
+// -------------------------------------------------------------
+
+class MyFontEnumerator : public wxFontEnumerator
+{
+public:
+ bool GotAny() const
+ { return !m_facenames.IsEmpty(); }
+
+ const wxArrayString& GetFacenames() const
+ { return m_facenames; }
+
+protected:
+ virtual bool OnFacename(const wxString& facename)
+ {
+ m_facenames.Add(facename);
+ return true;
+ }
+
+ private:
+ wxArrayString m_facenames;
+} fontEnumerator;
+
+bool MyFrame::DoEnumerateFamilies(bool fixedWidthOnly,
+ wxFontEncoding encoding,
+ bool silent)
+{
+ MyFontEnumerator fontEnumerator;
+
+ fontEnumerator.EnumerateFacenames(encoding, fixedWidthOnly);
+
+ if ( fontEnumerator.GotAny() )
+ {
+ int nFacenames = fontEnumerator.GetFacenames().GetCount();
+ if ( !silent )
+ {
+ wxLogStatus(this, wxT("Found %d %sfonts"),
+ nFacenames, fixedWidthOnly ? wxT("fixed width ") : wxT(""));
+ }
+
+ wxString facename;
+
+ if ( silent )
+ {
+ // choose the first
+ facename = fontEnumerator.GetFacenames().Item(0);
+ }
+ else
+ {
+ // let the user choose
+ wxString *facenames = new wxString[nFacenames];
+ int n;
+ for ( n = 0; n < nFacenames; n++ )
+ facenames[n] = fontEnumerator.GetFacenames().Item(n);
+
+ n = wxGetSingleChoiceIndex(wxT("Choose a facename"), wxT("Font demo"),
+ nFacenames, facenames, this);
+
+ if ( n != -1 )
+ facename = facenames[n];
+
+ delete [] facenames;
+ }
+
+ if ( !facename.empty() )
+ {
+ wxFont font(12, wxFONTFAMILY_DEFAULT, wxFONTSTYLE_NORMAL,
+ wxFONTWEIGHT_NORMAL, false, facename, encoding);
+
+ DoChangeFont(font);
+ }
+
+ return true;
+ }
+ else if ( !silent )
+ {
+ wxLogWarning(wxT("No such fonts found."));
+ }
+
+ return false;
+}
+
+void MyFrame::OnEnumerateFamiliesForEncoding(wxCommandEvent& WXUNUSED(event))
+{
+ static wxFontEncoding encodings[] =
+ {
+ wxFONTENCODING_ISO8859_1,
+ wxFONTENCODING_ISO8859_2,
+ wxFONTENCODING_ISO8859_5,
+ wxFONTENCODING_ISO8859_7,
+ wxFONTENCODING_ISO8859_15,
+ wxFONTENCODING_KOI8,
+ wxFONTENCODING_KOI8_U,
+ wxFONTENCODING_CP1250,
+ wxFONTENCODING_CP1251,
+ wxFONTENCODING_CP1252,
+ };
+
+ static const wxString encodingNames[] =
+ {
+ wxT("Western European (ISO-8859-1)"),
+ wxT("Central European (ISO-8859-2)"),
+ wxT("Cyrillic (ISO-8859-5)"),
+ wxT("Greek (ISO-8859-7)"),
+ wxT("Western European with Euro (ISO-8859-15)"),
+ wxT("KOI8-R"),
+ wxT("KOI8-U"),
+ wxT("Windows Central European (CP 1250)"),
+ wxT("Windows Cyrillic (CP 1251)"),
+ wxT("Windows Western European (CP 1252)"),
+ };
+
+ int n = wxGetSingleChoiceIndex(wxT("Choose an encoding"), wxT("Font demo"),
+ WXSIZEOF(encodingNames),
+ encodingNames,
+ this);
+
+ if ( n != -1 )
+ {
+ DoEnumerateFamilies(false, encodings[n]);
+ }
+}
+
+void MyFrame::OnCheckNativeToFromString(wxCommandEvent& WXUNUSED(event))
+{
+ wxString fontInfo = m_canvas->GetTextFont().GetNativeFontInfoDesc();
+
+ if ( fontInfo.empty() )
+ {
+ wxLogError(wxT("Native font info string is empty!"));
+ }
+ else
+ {
+ wxFont *font = wxFont::New(fontInfo);
+ if ( fontInfo != font->GetNativeFontInfoDesc() )
+ wxLogError(wxT("wxNativeFontInfo ToString()/FromString() broken!"));
+ else
+ wxLogMessage(wxT("wxNativeFontInfo works: %s"), fontInfo.c_str());
+
+ delete font;
+ }
+}
+
+void MyFrame::DoResizeFont(int diff)
+{
+ wxFont font = m_canvas->GetTextFont();
+
+ font.SetPointSize(font.GetPointSize() + diff);
+ DoChangeFont(font);
+}
+
+void MyFrame::OnBold(wxCommandEvent& event)
+{
+ wxFont font = m_canvas->GetTextFont();
+
+ font.SetWeight(event.IsChecked() ? wxFONTWEIGHT_BOLD : wxFONTWEIGHT_NORMAL);
+ DoChangeFont(font);
+}
+
+void MyFrame::OnItalic(wxCommandEvent& event)
+{
+ wxFont font = m_canvas->GetTextFont();
+
+ font.SetStyle(event.IsChecked() ? wxFONTSTYLE_ITALIC : wxFONTSTYLE_NORMAL);
+ DoChangeFont(font);