]> git.saurik.com Git - wxWidgets.git/commitdiff
serialize wxNativeEncodingInfo using font names, not numbers which are subject to...
authorVadim Zeitlin <vadim@wxwidgets.org>
Sun, 11 Apr 2004 10:50:22 +0000 (10:50 +0000)
committerVadim Zeitlin <vadim@wxwidgets.org>
Sun, 11 Apr 2004 10:50:22 +0000 (10:50 +0000)
git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@26704 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775

src/msw/fontutil.cpp

index a74885be8ab51a4c4121c8bdba5000e127eb621e..6bea2a9a399cf35b6e07b1a8cee4731cbf28f886 100644 (file)
@@ -63,10 +63,29 @@ bool wxNativeEncodingInfo::FromString(const wxString& s)
     wxStringTokenizer tokenizer(s, _T(";"));
 
     wxString encid = tokenizer.GetNextToken();
+
+    // we support 2 formats: the old one (and still used if !wxUSE_FONTMAP)
+    // used the raw encoding values but the new one uses the encoding names
     long enc;
-    if ( !encid.ToLong(&enc) )
-        return FALSE;
-    encoding = (wxFontEncoding)enc;
+    if ( encid.ToLong(&enc) )
+    {
+        // old format, intepret as encoding -- but after minimal checks
+        if ( enc < 0 || enc >= wxFONTENCODING_MAX )
+            return false;
+
+        encoding = (wxFontEncoding)enc;
+    }
+    else // not a number, interpret as an encoding name
+    {
+#if wxUSE_FONTMAP
+        encoding = wxFontMapper::GetEncodingFromName(encid);
+        if ( encoding == wxFONTENCODING_MAX )
+#endif // wxUSE_FONTMAP
+        {
+            // failed to parse the name (or couldn't even try...)
+            return false;
+        }
+    }
 
     facename = tokenizer.GetNextToken();
 
@@ -94,7 +113,17 @@ wxString wxNativeEncodingInfo::ToString() const
 {
     wxString s;
 
-    s << (long)encoding << _T(';') << facename;
+    s
+#if wxUSE_FONTMAP
+      // use the encoding names as this is safer than using the numerical
+      // values which may change with time (because new encodings are
+      // inserted...)
+      << wxFontMapper::GetEncodingName(encoding)
+#else // !wxUSE_FONTMAP
+      // we don't have any choice but to use the raw value
+      << (long)encoding
+#endif // wxUSE_FONTMAP/!wxUSE_FONTMAP
+      << _T(';') << facename;
 
     // ANSI_CHARSET is assumed anyhow
     if ( charset != ANSI_CHARSET )