]> git.saurik.com Git - wxWidgets.git/commitdiff
added demo of wxEncodingConverter
authorVáclav Slavík <vslavik@fastmail.fm>
Sat, 22 Jan 2000 11:55:33 +0000 (11:55 +0000)
committerVáclav Slavík <vslavik@fastmail.fm>
Sat, 22 Jan 2000 11:55:33 +0000 (11:55 +0000)
git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@5589 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775

samples/font/font.cpp

index 56e5a565b671e32aa2e731f68a7daf832723ae11..0ed46b1aa5b115da4a063971b11e0cda8203e754 100644 (file)
@@ -28,6 +28,7 @@
 #include <wx/fontdlg.h>
 #include <wx/fontenum.h>
 #include <wx/fontmap.h>
+#include <wx/encconv.h>
 #include <wx/textfile.h>
 
 // ----------------------------------------------------------------------------
@@ -489,6 +490,32 @@ void MyFrame::OnViewMsg(wxCommandEvent& WXUNUSED(event))
         return;
     }
 
+    m_textctrl->LoadFile(filename);
+
+    if (!wxTheFontMapper->IsEncodingAvailable(fontenc))
+    {
+        // try to find some similar encoding:
+        wxFontEncoding enc2;
+        if (wxTheFontMapper->GetAltForEncoding(fontenc, &enc2, 
+                                       wxEmptyString /*facename*/, FALSE /*interactive*/))
+        {
+            wxEncodingConverter conv;
+            
+            if (conv.Init(fontenc, enc2))
+            {
+                fontenc = enc2;
+                m_textctrl -> SetValue(conv.Convert(m_textctrl -> GetValue()));
+            }
+            else
+                wxLogWarning("Cannot convert from '%s' to '%s'.",
+                             wxFontMapper::GetEncodingDescription(fontenc).c_str(),
+                             wxFontMapper::GetEncodingDescription(enc2).c_str());
+        }
+        else
+            wxLogWarning("No fonts for encoding '%s' on this system.",
+                         wxFontMapper::GetEncodingDescription(fontenc).c_str());
+    }
+
     // and now create the correct font
     if ( !DoEnumerateFamilies(FALSE, fontenc, TRUE /* silent */) )
     {
@@ -505,8 +532,6 @@ void MyFrame::OnViewMsg(wxCommandEvent& WXUNUSED(event))
                          wxFontMapper::GetEncodingDescription(fontenc).c_str());
         }
     }
-
-    m_textctrl->LoadFile(filename);
 }
 
 void MyFrame::OnAbout(wxCommandEvent& WXUNUSED(event))