]> git.saurik.com Git - wxWidgets.git/commitdiff
use the encoding of the font which is used to draw the text when convering it to...
authorVadim Zeitlin <vadim@wxwidgets.org>
Mon, 10 Apr 2006 22:22:13 +0000 (22:22 +0000)
committerVadim Zeitlin <vadim@wxwidgets.org>
Mon, 10 Apr 2006 22:22:13 +0000 (22:22 +0000)
git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@38661 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775

docs/changes.txt
include/wx/gtk/private.h
src/gtk/colour.cpp
src/gtk/font.cpp
src/gtk/menu.cpp
src/gtk/utilsgtk.cpp
src/unix/fontutil.cpp

index e24ae287c864fbc388f1b056c3f3db8496c329c0..5c760e6de003123198d16d7102bcbb673874336a 100644 (file)
@@ -163,6 +163,7 @@ wxMSW:
 
 wxGTK:
 
+- Fixed handling of font encoding in non-Unicode build
 - wxEVT_MENU_CLOSE and wxEVT_MENU_OPENED for popup menus are now generated.
 - Implemented wxCURSOR_BLANK support.
 - wxSlider generates all scroll events now and not only wxEVT_SCROLL_THUMBTRACK.
index 2ce2865725f3fbf12c5ee31d08941f272af4e66f..f3219f75a1b8c8436c618e7bdbfb40320191b27f 100644 (file)
 
 #if wxUSE_UNICODE
     #define wxGTK_CONV(s) wxConvUTF8.cWX2MB(s)
+    #define wxGTK_CONV_SYS(s, enc) wxGTK_CONV(s)
     #define wxGTK_CONV_BACK(s) wxConvUTF8.cMB2WX(s)
 #else
-    #define wxGTK_CONV(s) wxConvUTF8.cWC2MB( wxConvLocal.cWX2WC(s) )
-    #define wxGTK_CONV_BACK(s)  wxConvLocal.cWC2WX( (wxConvUTF8.cMB2WC( s ) ) )
+    // convert the text in given encoding to UTF-8 used by wxGTK
+    extern wxCharBuffer
+    wxConvertToGTK(const wxString& s,
+                   wxFontEncoding enc = wxFONTENCODING_SYSTEM);
+
+    // helper: use the encoding of the given font if it's valid
+    inline wxCharBuffer wxConvertToGTK(const wxString& s, const wxFont& font)
+    {
+        return wxConvertToGTK(s, font.Ok() ? font.GetEncoding()
+                                           : wxFONTENCODING_SYSTEM);
+    }
+
+    #define wxGTK_CONV(s) wxConvertToGTK((s), m_font)
+    #define wxGTK_CONV_SYS(s) wxConvertToGTK(s)
+    #define wxGTK_CONV_BACK(s)  wxConvLocal.cWC2WX( wxConvUTF8.cMB2WC((s)) )
 #endif
 
 // Some deprecated GTK+ prototypes we still use often
index ff7c526c4539f3ece48e7356a1dc32ab40d2f601..d43c5864443a9a7deecf8aa6cd0cd6f7b6b375d7 100644 (file)
@@ -96,7 +96,7 @@ wxColour wxColour::CreateByName(const wxString& name)
     wxColour col;
 
     GdkColor colGDK;
-    if ( gdk_color_parse( wxGTK_CONV( name ), &colGDK ) )
+    if ( gdk_color_parse( wxGTK_CONV_SYS( name ), &colGDK ) )
     {
         wxColourRefData *refData = new wxColourRefData;
         refData->m_color = colGDK;
index 04da6ccac7e31e95176f231cd2a183babf19de02..30330dd02d918ef844f8b4f4f1fd475c443c853d 100644 (file)
@@ -116,7 +116,7 @@ private:
                     m_weight;
     bool            m_underlined;
     wxString        m_faceName;
-    wxFontEncoding  m_encoding;  // Unused under GTK 2.0
+    wxFontEncoding  m_encoding;
     bool            m_noAA;      // No anti-aliasing
 
     // The native font info, basicly an XFLD under GTK 1.2 and
@@ -163,7 +163,8 @@ void wxFontRefData::Init(int pointSize,
     // And set its values
     if (!m_faceName.empty())
     {
-       pango_font_description_set_family( m_nativeFontInfo.description, wxGTK_CONV(m_faceName) );
+       pango_font_description_set_family( m_nativeFontInfo.description,
+                                          wxGTK_CONV_SYS(m_faceName) );
     }
     else
     {
@@ -228,8 +229,8 @@ void wxFontRefData::InitFromNative()
     // Pango description are never underlined (?)
     m_underlined = FALSE;
 
-    // Cannot we choose that
-    m_encoding = wxFONTENCODING_SYSTEM;
+    // always with GTK+ 2
+    m_encoding = wxFONTENCODING_UTF8;
 }
 
 wxFontRefData::wxFontRefData( const wxFontRefData& data )
@@ -485,15 +486,14 @@ bool wxFont::GetUnderlined() const
 
 wxFontEncoding wxFont::GetEncoding() const
 {
-    wxCHECK_MSG( Ok(), wxFONTENCODING_DEFAULT, wxT("invalid font") );
+    wxCHECK_MSG( Ok(), wxFONTENCODING_SYSTEM, wxT("invalid font") );
 
-    // m_encoding is unused in wxGTK2, return encoding that the user set.
     return M_FONTDATA->m_encoding;
 }
 
 bool wxFont::GetNoAntiAliasing() const
 {
-    wxCHECK_MSG( Ok(), wxFONTENCODING_DEFAULT, wxT("invalid font") );
+    wxCHECK_MSG( Ok(), false, wxT("invalid font") );
 
     return M_FONTDATA->m_noAA;
 }
index 08dae1a86782a600199aa573f4e3103c040f040c..f02968fc17307f52ac4c8213e6d3324a08b42c88 100644 (file)
@@ -747,7 +747,7 @@ void wxMenuItem::SetText( const wxString& str )
     oldLabel.Replace(wxT("_"), wxT(""));
     wxString label1 = wxStripMenuCodes(str);
     wxString oldhotkey = GetHotKey();    // Store the old hotkey in Ctrl-foo format
-    wxCharBuffer oldbuf = wxGTK_CONV( GetGtkHotKey(*this) );  // and as <control>foo
+    wxCharBuffer oldbuf = wxGTK_CONV_SYS( GetGtkHotKey(*this) );  // and as <control>foo
 
     DoSetText(str);
 
@@ -763,7 +763,7 @@ void wxMenuItem::SetText( const wxString& str )
         else
             label = GTK_LABEL( GTK_BIN(m_menuItem)->child );
 
-        gtk_label_set_text_with_mnemonic( GTK_LABEL(label), wxGTK_CONV(m_text) );
+        gtk_label_set_text_with_mnemonic( GTK_LABEL(label), wxGTK_CONV_SYS(m_text) );
     }
 
     guint accel_key;
@@ -777,7 +777,7 @@ void wxMenuItem::SetText( const wxString& str )
                                        accel_mods );
     }
 
-    wxCharBuffer buf = wxGTK_CONV( GetGtkHotKey(*this) );
+    wxCharBuffer buf = wxGTK_CONV_SYS( GetGtkHotKey(*this) );
     gtk_accelerator_parse( (const char*) buf, &accel_key, &accel_mods);
     if (accel_key != 0)
     {
@@ -954,7 +954,7 @@ bool wxMenu::GtkAppend(wxMenuItem *mitem, int pos)
         text = mitem->GetText();
         const wxBitmap *bitmap = &mitem->GetBitmap();
 
-        menuItem = gtk_image_menu_item_new_with_mnemonic( wxGTK_CONV( text ) );
+        menuItem = gtk_image_menu_item_new_with_mnemonic( wxGTK_CONV_SYS( text ) );
 
         GtkWidget *image;
         if (bitmap->HasPixbuf())
@@ -985,7 +985,7 @@ bool wxMenu::GtkAppend(wxMenuItem *mitem, int pos)
         {
             case wxITEM_CHECK:
             {
-                menuItem = gtk_check_menu_item_new_with_mnemonic( wxGTK_CONV( text ) );
+                menuItem = gtk_check_menu_item_new_with_mnemonic( wxGTK_CONV_SYS( text ) );
                 m_prevRadio = NULL;
                 break;
             }
@@ -996,12 +996,14 @@ bool wxMenu::GtkAppend(wxMenuItem *mitem, int pos)
                 if ( m_prevRadio == NULL )
                 {
                     // start of a new radio group
-                    m_prevRadio = menuItem = gtk_radio_menu_item_new_with_mnemonic( group, wxGTK_CONV( text ) );
+                    m_prevRadio = menuItem =
+                        gtk_radio_menu_item_new_with_mnemonic( group, wxGTK_CONV_SYS( text ) );
                 }
                 else // continue the radio group
                 {
                     group = gtk_radio_menu_item_get_group (GTK_RADIO_MENU_ITEM (m_prevRadio));
-                    m_prevRadio = menuItem = gtk_radio_menu_item_new_with_mnemonic( group, wxGTK_CONV( text ) );
+                    m_prevRadio = menuItem =
+                        gtk_radio_menu_item_new_with_mnemonic( group, wxGTK_CONV_SYS( text ) );
                 }
                 break;
             }
@@ -1012,7 +1014,7 @@ bool wxMenu::GtkAppend(wxMenuItem *mitem, int pos)
 
             case wxITEM_NORMAL:
             {
-                menuItem = gtk_menu_item_new_with_mnemonic( wxGTK_CONV( text ) );
+                menuItem = gtk_menu_item_new_with_mnemonic( wxGTK_CONV_SYS( text ) );
                 m_prevRadio = NULL;
                 break;
             }
@@ -1022,7 +1024,7 @@ bool wxMenu::GtkAppend(wxMenuItem *mitem, int pos)
 
     guint accel_key;
     GdkModifierType accel_mods;
-    wxCharBuffer buf = wxGTK_CONV( GetGtkHotKey(*mitem) );
+    wxCharBuffer buf = wxGTK_CONV_SYS( GetGtkHotKey(*mitem) );
 
     // wxPrintf( wxT("item: %s hotkey %s\n"), mitem->GetText().c_str(), GetGtkHotKey(*mitem).c_str() );
     gtk_accelerator_parse( (const char*) buf, &accel_key, &accel_mods);
index 4b321c358f415a75abe6bb9ead4b72eba3a3c4e4..d0fd5c36a0b8145856ca5dda138b844b44e7cebd 100644 (file)
@@ -180,6 +180,25 @@ wxWindow* wxFindWindowAtPoint(const wxPoint& pt)
     return wxGenericFindWindowAtPoint(pt);
 }
 
+#if !wxUSE_UNICODE
+
+wxCharBuffer wxConvertToGTK(const wxString& s, wxFontEncoding enc)
+{
+    if ( enc == wxFONTENCODING_UTF8 )
+    {
+        // no need for conversion at all
+        return wxCharBuffer(s);
+    }
+
+    const wxWCharBuffer wbuf = wxCSConv(enc).cMB2WC(s);
+    wxCharBuffer buf;
+    if ( wbuf )
+        buf = wxConvUTF8.cWC2MB(wbuf);
+
+    return buf;
+}
+
+#endif // !wxUSE_UNICODE
 
 // ----------------------------------------------------------------------------
 // subprocess routines
index ea483ebed5fe0236834faf2efd6f1f6a4991a88c..c29cc1aaf0dd95c73226682d25610cfa65a74d07 100644 (file)
@@ -256,7 +256,7 @@ void wxNativeFontInfo::SetUnderlined(bool WXUNUSED(underlined))
 
 void wxNativeFontInfo::SetFaceName(const wxString& facename)
 {
-    pango_font_description_set_family( description, wxGTK_CONV(facename) );
+    pango_font_description_set_family(description, wxGTK_CONV_SYS(facename));
 }
 
 void wxNativeFontInfo::SetFamily(wxFontFamily WXUNUSED(family))
@@ -276,7 +276,7 @@ bool wxNativeFontInfo::FromString(const wxString& s)
     if (description)
         pango_font_description_free( description );
 
-    description = pango_font_description_from_string( wxGTK_CONV( s ) );
+    description = pango_font_description_from_string( wxGTK_CONV_SYS( s ) );
 
     return true;
 }