+ if ( !facename.empty() )
+ {
+ wxFont font(wxFontInfo().FaceName(facename).Encoding(encoding));
+
+ DoChangeFont(font);
+ }
+
+ return true;
+ }
+ else if ( !silent )
+ {
+ wxLogWarning(wxT("No such fonts found."));
+ }
+
+ return false;
+}
+
+void MyFrame::OnEnumerateFamiliesForEncoding(wxCommandEvent& WXUNUSED(event))
+{
+ wxFontEncoding enc = GetEncodingFromUser();
+ if ( enc != wxFONTENCODING_SYSTEM )
+ {
+ DoEnumerateFamilies(false, enc);
+ }
+}
+
+void MyFrame::OnSetNativeDesc(wxCommandEvent& WXUNUSED(event))
+{
+ wxString fontInfo = wxGetTextFromUser
+ (
+ wxT("Enter native font string"),
+ wxT("Input font description"),
+ m_canvas->GetTextFont().GetNativeFontInfoDesc(),
+ this
+ );
+ if ( fontInfo.empty() )
+ return; // user clicked "Cancel" - do nothing
+
+ wxFont font;
+ font.SetNativeFontInfo(fontInfo);
+ if ( !font.IsOk() )
+ {
+ wxLogError(wxT("Font info string \"%s\" is invalid."),
+ fontInfo.c_str());
+ return;
+ }
+
+ DoChangeFont(font);
+}
+
+void MyFrame::OnSetNativeUserDesc(wxCommandEvent& WXUNUSED(event))
+{
+ wxString fontdesc = GetCanvas()->GetTextFont().GetNativeFontInfoUserDesc();
+ wxString fontUserInfo = wxGetTextFromUser(
+ wxT("Here you can edit current font description"),
+ wxT("Input font description"), fontdesc,
+ this);
+ if (fontUserInfo.IsEmpty())
+ return; // user clicked "Cancel" - do nothing
+
+ wxFont font;
+ if (font.SetNativeFontInfoUserDesc(fontUserInfo))
+ {
+ 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("Error trying to create a font with such description..."));
+ }
+}
+
+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();