From 35d9b0f056de428d0c83846b209738463fa62372 Mon Sep 17 00:00:00 2001 From: Vadim Zeitlin Date: Fri, 27 Sep 2019 19:29:42 +0200 Subject: [PATCH 1/4] Rewrite a chain of "if"s as a switch No real changes, just make the code a bit more maintainable and easier to read. --- src/common/intl.cpp | 45 +++++++++++++++++++++------------------------ 1 file changed, 21 insertions(+), 24 deletions(-) diff --git a/src/common/intl.cpp b/src/common/intl.cpp index 96dd2389d6..6d4d200c95 100644 --- a/src/common/intl.cpp +++ b/src/common/intl.cpp @@ -877,37 +877,34 @@ wxString wxLocale::GetSystemEncodingName() wxFontEncoding wxLocale::GetSystemEncoding() { #if defined(__WIN32__) - UINT codepage = ::GetACP(); + const UINT codepage = ::GetACP(); - // wxWidgets only knows about CP1250-1257, 874, 932, 936, 949, 950 - if ( codepage >= 1250 && codepage <= 1257 ) + switch ( codepage ) { - return (wxFontEncoding)(wxFONTENCODING_CP1250 + codepage - 1250); - } + case 1250: + case 1251: + case 1252: + case 1253: + case 1254: + case 1255: + case 1256: + case 1257: + return (wxFontEncoding)(wxFONTENCODING_CP1250 + codepage - 1250); - if ( codepage == 874 ) - { - return wxFONTENCODING_CP874; - } + case 874: + return wxFONTENCODING_CP874; - if ( codepage == 932 ) - { - return wxFONTENCODING_CP932; - } + case 932: + return wxFONTENCODING_CP932; - if ( codepage == 936 ) - { - return wxFONTENCODING_CP936; - } + case 936: + return wxFONTENCODING_CP936; - if ( codepage == 949 ) - { - return wxFONTENCODING_CP949; - } + case 949: + return wxFONTENCODING_CP949; - if ( codepage == 950 ) - { - return wxFONTENCODING_CP950; + case 950: + return wxFONTENCODING_CP950; } #elif defined(__WXMAC__) CFStringEncoding encoding = 0 ; From 5dbfff839e2c744774ef9b349090c2e6b2ebaa8a Mon Sep 17 00:00:00 2001 From: Vadim Zeitlin Date: Fri, 27 Sep 2019 19:30:22 +0200 Subject: [PATCH 2/4] Add support for code page 1258 (Vietnamese) There doesn't seem to be any good reason to not support this one, when we support (or at least recognize) all the other CP125x encodings. --- src/common/intl.cpp | 1 + 1 file changed, 1 insertion(+) diff --git a/src/common/intl.cpp b/src/common/intl.cpp index 6d4d200c95..98ce930018 100644 --- a/src/common/intl.cpp +++ b/src/common/intl.cpp @@ -889,6 +889,7 @@ wxFontEncoding wxLocale::GetSystemEncoding() case 1255: case 1256: case 1257: + case 1258: return (wxFontEncoding)(wxFONTENCODING_CP1250 + codepage - 1250); case 874: From 7feaa024b3633a304e03afa4ac06cd1757869ccf Mon Sep 17 00:00:00 2001 From: Vadim Zeitlin Date: Fri, 27 Sep 2019 19:31:38 +0200 Subject: [PATCH 3/4] Add support for code page 1361 (Johab Korean) As with the previous commit, recognize the system CP1361 encoding, which can be mapped to an existing wxFONTENCODING_CP1361 constant. --- src/common/intl.cpp | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/common/intl.cpp b/src/common/intl.cpp index 98ce930018..150fa2de06 100644 --- a/src/common/intl.cpp +++ b/src/common/intl.cpp @@ -892,6 +892,9 @@ wxFontEncoding wxLocale::GetSystemEncoding() case 1258: return (wxFontEncoding)(wxFONTENCODING_CP1250 + codepage - 1250); + case 1361: + return wxFONTENCODING_CP1361; + case 874: return wxFONTENCODING_CP874; From 194870fe5e030446a52235a24f9060b0f4bcb410 Mon Sep 17 00:00:00 2001 From: Vadim Zeitlin Date: Fri, 27 Sep 2019 19:34:32 +0200 Subject: [PATCH 4/4] Recognize system UTF-8 encoding under MSW too Recent versions of Windows 10 (finally!) allow to set up UTF-8 as the system encoding, so recognize when it is returned by GetACP() in wxLocale::GetSystemEncoding() and GetSystemEncodingName(). --- src/common/intl.cpp | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/src/common/intl.cpp b/src/common/intl.cpp index 150fa2de06..8fbd6b00ed 100644 --- a/src/common/intl.cpp +++ b/src/common/intl.cpp @@ -825,8 +825,16 @@ wxString wxLocale::GetSystemEncodingName() #if defined(__WIN32__) // FIXME: what is the error return value for GetACP()? - UINT codepage = ::GetACP(); - encname.Printf(wxS("windows-%u"), codepage); + const UINT codepage = ::GetACP(); + switch ( codepage ) + { + case 65001: + encname = "UTF-8"; + break; + + default: + encname.Printf(wxS("windows-%u"), codepage); + } #elif defined(__WXMAC__) encname = wxCFStringRef::AsString( CFStringGetNameOfEncoding(CFStringGetSystemEncoding()) @@ -909,6 +917,9 @@ wxFontEncoding wxLocale::GetSystemEncoding() case 950: return wxFONTENCODING_CP950; + + case 65001: + return wxFONTENCODING_UTF8; } #elif defined(__WXMAC__) CFStringEncoding encoding = 0 ;