void OnSize(wxSizeEvent& event);
protected:
- void DoEnumerateFamilies(bool fixedWidthOnly,
- wxFontEncoding encoding = wxFONTENCODING_SYSTEM);
+ bool DoEnumerateFamilies(bool fixedWidthOnly,
+ wxFontEncoding encoding = wxFONTENCODING_SYSTEM,
+ bool silent = FALSE);
void DoChangeFont(const wxFont& font, const wxColour& col = wxNullColour);
fontEnumerator.GetText().c_str());
}
-void MyFrame::DoEnumerateFamilies(bool fixedWidthOnly, wxFontEncoding encoding)
+bool MyFrame::DoEnumerateFamilies(bool fixedWidthOnly,
+ wxFontEncoding encoding,
+ bool silent)
{
class MyFontEnumerator : public wxFontEnumerator
{
if ( fontEnumerator.GotAny() )
{
- int n, nFacenames = fontEnumerator.GetFacenames().GetCount();
- wxLogStatus(this, "Found %d %sfonts",
- nFacenames, fixedWidthOnly ? "fixed width " : "");
+ int nFacenames = fontEnumerator.GetFacenames().GetCount();
+ if ( !silent )
+ {
+ wxLogStatus(this, "Found %d %sfonts",
+ nFacenames, fixedWidthOnly ? "fixed width " : "");
+ }
+
+ 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("Choose a facename", "Font demo",
+ nFacenames, facenames, this);
- wxString *facenames = new wxString[nFacenames];
- for ( n = 0; n < nFacenames; n++ )
- facenames[n] = fontEnumerator.GetFacenames().Item(n);
+ if ( n != -1 )
+ facename = facenames[n];
- n = wxGetSingleChoiceIndex("Choose a facename", "Font demo",
- nFacenames, facenames, this);
- if ( n != -1 )
+ delete [] facenames;
+ }
+
+ if ( !facename.IsEmpty() )
{
- wxFont font(14, wxFONTFAMILY_DEFAULT, wxFONTSTYLE_NORMAL,
- wxFONTWEIGHT_NORMAL, FALSE, facenames[n], encoding);
+ wxFont font(12, wxFONTFAMILY_DEFAULT, wxFONTSTYLE_NORMAL,
+ wxFONTWEIGHT_NORMAL, FALSE, facename, encoding);
DoChangeFont(font);
}
- delete [] facenames;
+ return TRUE;
}
- else
+ else if ( !silent )
{
wxLogWarning("No such fonts found.");
}
+
+ return FALSE;
}
void MyFrame::OnEnumerateFamiliesForEncoding(wxCommandEvent& WXUNUSED(event))
}
// ok, now get the corresponding encoding
- wxFontMapper fontMapper;
- wxFontEncoding fontenc = fontMapper.CharsetToEncoding(charset);
+ wxFontEncoding fontenc = wxTheFontMapper->CharsetToEncoding(charset);
if ( fontenc == wxFONTENCODING_SYSTEM )
{
wxLogError("Charset '%s' is unsupported.", charset.c_str());
}
// and now create the correct font
- m_textctrl->LoadFile(filename);
+ if ( !DoEnumerateFamilies(FALSE, fontenc, TRUE /* silent */) )
+ {
+ wxFont font(12, wxFONTFAMILY_DEFAULT, wxFONTSTYLE_NORMAL,
+ wxFONTWEIGHT_NORMAL, FALSE /* !underlined */,
+ wxEmptyString /* facename */, fontenc);
+ if ( font.Ok() )
+ {
+ DoChangeFont(font);
+ }
+ else
+ {
+ wxLogWarning("No fonts for encoding '%s' on this system.",
+ wxFontMapper::GetEncodingDescription(fontenc).c_str());
+ }
+ }
- DoEnumerateFamilies(FALSE, fontenc);
+ m_textctrl->LoadFile(filename);
}
void MyFrame::OnAbout(wxCommandEvent& WXUNUSED(event))
END_EVENT_TABLE()
MyCanvas::MyCanvas( wxWindow *parent )
- : wxWindow( parent, -1 )
+ : wxWindow( parent, -1 ),
+ m_colour(*wxRED), m_font(*wxNORMAL_FONT)
{
- m_font = *wxNORMAL_FONT;
- m_colour = *wxRED;
}
MyCanvas::~MyCanvas()