+void MyFrame::OnSetFamily(wxCommandEvent& WXUNUSED(event))
+{
+ wxFontFamily f = GetFamilyFromUser();
+
+ wxFont font = m_canvas->GetTextFont();
+ font.SetFamily(f);
+ DoChangeFont(font);
+}
+
+void MyFrame::OnSetFaceName(wxCommandEvent& WXUNUSED(event))
+{
+ wxString facename = GetCanvas()->GetTextFont().GetFaceName();
+ wxString newFaceName = wxGetTextFromUser(
+ wxT("Here you can edit current font face name."),
+ wxT("Input font facename"), facename,
+ this);
+ if (newFaceName.IsEmpty())
+ return; // user clicked "Cancel" - do nothing
+
+ wxFont font(GetCanvas()->GetTextFont());
+ if (font.SetFaceName(newFaceName)) // change facename only
+ {
+ wxASSERT_MSG(font.IsOk(), wxT("The font should now be valid"));
+ DoChangeFont(font);
+ }
+ else
+ {
+ wxASSERT_MSG(!font.IsOk(), wxT("The font should now be invalid"));
+ wxMessageBox(wxT("There is no font with such face name..."),
+ wxT("Invalid face name"), wxOK|wxICON_ERROR, this);
+ }
+}
+
+void MyFrame::OnSetEncoding(wxCommandEvent& WXUNUSED(event))
+{
+ wxFontEncoding enc = GetEncodingFromUser();
+ if ( enc == wxFONTENCODING_SYSTEM )
+ return;
+
+ wxFont font = m_canvas->GetTextFont();
+ font.SetEncoding(enc);
+ DoChangeFont(font);
+}
+
+wxFontEncoding MyFrame::GetEncodingFromUser()
+{
+ wxArrayString names;
+ wxArrayInt encodings;
+
+ const size_t count = wxFontMapper::GetSupportedEncodingsCount();
+ names.reserve(count);
+ encodings.reserve(count);
+
+ for ( size_t n = 0; n < count; n++ )
+ {
+ wxFontEncoding enc = wxFontMapper::GetEncoding(n);
+ encodings.push_back(enc);
+ names.push_back(wxFontMapper::GetEncodingName(enc));
+ }
+
+ int i = wxGetSingleChoiceIndex
+ (
+ wxT("Choose the encoding"),
+ SAMPLE_TITLE,
+ names,
+ this
+ );
+
+ return i == -1 ? wxFONTENCODING_SYSTEM : (wxFontEncoding)encodings[i];
+}
+
+wxFontFamily MyFrame::GetFamilyFromUser()
+{
+ wxArrayString names;
+ wxArrayInt families;
+
+ families.push_back(wxFONTFAMILY_DECORATIVE);
+ families.push_back(wxFONTFAMILY_ROMAN);
+ families.push_back(wxFONTFAMILY_SCRIPT);
+ families.push_back(wxFONTFAMILY_SWISS);
+ families.push_back(wxFONTFAMILY_MODERN);
+ families.push_back(wxFONTFAMILY_TELETYPE);
+
+ names.push_back("DECORATIVE");
+ names.push_back("ROMAN");
+ names.push_back("SCRIPT");
+ names.push_back("SWISS");
+ names.push_back("MODERN");
+ names.push_back("TELETYPE");
+
+ int i = wxGetSingleChoiceIndex
+ (
+ wxT("Choose the family"),
+ SAMPLE_TITLE,
+ names,
+ this
+ );
+
+ return i == -1 ? wxFONTFAMILY_DEFAULT : (wxFontFamily)families[i];
+}
+
+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::OnLight(wxCommandEvent& event)
+{
+ wxFont font = m_canvas->GetTextFont();
+
+ font.SetWeight(event.IsChecked() ? wxFONTWEIGHT_LIGHT : wxFONTWEIGHT_NORMAL);
+ DoChangeFont(font);
+}
+
+void MyFrame::OnItalic(wxCommandEvent& event)
+{
+ wxFont font = m_canvas->GetTextFont();
+
+ font.SetStyle(event.IsChecked() ? wxFONTSTYLE_ITALIC : wxFONTSTYLE_NORMAL);
+ DoChangeFont(font);
+}
+
+void MyFrame::OnSlant(wxCommandEvent& event)
+{
+ wxFont font = m_canvas->GetTextFont();
+
+ font.SetStyle(event.IsChecked() ? wxFONTSTYLE_SLANT : wxFONTSTYLE_NORMAL);
+ DoChangeFont(font);
+}
+
+void MyFrame::OnUnderline(wxCommandEvent& event)
+{
+ wxFont font = m_canvas->GetTextFont();
+
+ font.SetUnderlined(event.IsChecked());
+ DoChangeFont(font);
+}
+
+void MyFrame::OnStrikethrough(wxCommandEvent& event)