X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/189e08b45ac97195a4f975fe8507439a8739e5fa..8f974c520a8733158591891458fda10fae4c3950:/samples/font/font.cpp?ds=sidebyside diff --git a/samples/font/font.cpp b/samples/font/font.cpp index 4736134731..d919ea6a59 100644 --- a/samples/font/font.cpp +++ b/samples/font/font.cpp @@ -262,10 +262,10 @@ MyFrame::MyFrame(const wxString& title, const wxPoint& pos, const wxSize& size) class MyEncodingEnumerator : public wxFontEnumerator { public: - MyEncodingEnumerator() + MyEncodingEnumerator() { m_n = 0; } - const wxString& GetText() const + const wxString& GetText() const { return m_text; } protected: @@ -299,10 +299,10 @@ void MyFrame::OnEnumerateEncodings(wxCommandEvent& WXUNUSED(event)) class MyFontEnumerator : public wxFontEnumerator { public: - bool GotAny() const + bool GotAny() const { return !m_facenames.IsEmpty(); } - const wxArrayString& GetFacenames() const + const wxArrayString& GetFacenames() const { return m_facenames; } protected: @@ -391,15 +391,15 @@ void MyFrame::OnEnumerateFamiliesForEncoding(wxCommandEvent& WXUNUSED(event)) static const wxString encodingNames[] = { - "West European (Latin 1)", - "Central European (Latin 2)", - "Cyrillic (Latin 5)", - "Greek (Latin 7)", - "West European new (Latin 0)", + "Western European (ISO-8859-1)", + "Central European (ISO-8859-2)", + "Cyrillic (ISO-8859-5)", + "Greek (ISO-8859-7)", + "Western European with Euro (ISO-8859-15)", "KOI8-R", - "Windows Latin 2", - "Windows Cyrillic", - "Windows Latin 1", + "Windows Central European (CP 1250)", + "Windows Cyrillic (CP 1251)", + "Windows Western European (CP 1252)", }; int n = wxGetSingleChoiceIndex("Choose an encoding", "Font demo", @@ -415,22 +415,20 @@ void MyFrame::OnEnumerateFamiliesForEncoding(wxCommandEvent& WXUNUSED(event)) void MyFrame::OnCheckNativeToFromString(wxCommandEvent& WXUNUSED(event)) { - wxString fontInfo = m_canvas->GetTextFont().GetNativeFontInfo().ToString(); + wxString fontInfo = m_canvas->GetTextFont().GetNativeFontInfoDesc(); - if(fontInfo.IsEmpty()) - wxMessageBox("Native font info string is empty!", "Font demo", - wxOK); + if ( fontInfo.IsEmpty() ) + { + wxLogError("Native font info string is empty!"); + } else { - wxNativeFontInfo info; - info.FromString(fontInfo); - wxFont font(info); - if(fontInfo == font.GetNativeFontInfo().ToString()) - wxMessageBox("wxNativeFontInfo ToString()/FromString() works!", - "Font demo", wxOK); + wxFont *font = wxFont::New(fontInfo); + if ( fontInfo != font->GetNativeFontInfoDesc() ) + wxLogError("wxNativeFontInfo ToString()/FromString() broken!"); else - wxMessageBox("wxNativeFontInfo ToString()/FromString() doesn't work!", - "Font demo", wxOK); + wxLogError("wxNativeFontInfo works: %s", fontInfo.c_str()); + delete font; } } @@ -453,7 +451,7 @@ void MyFrame::DoResizeFont(int diff) void MyFrame::DoChangeFont(const wxFont& font, const wxColour& col) { - Resize(GetSize(), font); + Resize(GetClientSize(), font); m_canvas->SetTextFont(font); if ( col.Ok() ) @@ -559,14 +557,15 @@ void MyFrame::OnViewMsg(wxCommandEvent& WXUNUSED(event)) m_textctrl->LoadFile(filename); - if (!wxTheFontMapper->IsEncodingAvailable(fontenc)) + if ( fontenc == wxFONTENCODING_UTF8 || + !wxTheFontMapper->IsEncodingAvailable(fontenc) ) { // try to find some similar encoding: wxFontEncoding encAlt; if ( wxTheFontMapper->GetAltForEncoding(fontenc, &encAlt) ) { wxEncodingConverter conv; - + if (conv.Init(fontenc, encAlt)) { fontenc = encAlt; @@ -612,9 +611,7 @@ void MyFrame::OnAbout(wxCommandEvent& WXUNUSED(event)) void MyFrame::OnSize(wxSizeEvent& event) { - wxSize size = event.GetSize(); - - Resize(size); + Resize(GetClientSize()); event.Skip(); } @@ -678,11 +675,12 @@ void MyCanvas::OnPaint( wxPaintEvent &WXUNUSED(event) ) dc.DrawText(fontInfo, 5, 5); - if(m_font.Ok()) + if ( m_font.Ok() ) { - dc.SetFont(wxFont(m_font.GetNativeFontInfo())); - fontInfo.Printf("Native font info: %s", m_font.GetNativeFontInfo().ToString().GetData()); - dc.DrawText(fontInfo, 5, 5 + dc.GetCharHeight()); + wxString fontDesc = m_font.GetNativeFontInfoDesc(); + dc.SetFont(m_font); + fontInfo.Printf("Native font info: %s", fontDesc.c_str()); + dc.DrawText(fontInfo, 5, 5 + dc.GetCharHeight()); } // prepare to draw the font