From d2e7b5bdd1610b97732e7bcca4f3b4f2db2bd145 Mon Sep 17 00:00:00 2001 From: Pavel Tyunin Date: Mon, 5 Oct 2020 18:10:27 +0300 Subject: [PATCH] Fix GetEncoding() after global fallback encoding is changed Save global fallback encoding when switching to it, so GetEncoding() can still return the correct value if global fallback encoding is changed later. Also do not switch to wxFONTENCODING_MAX when it is set as global fallback encoding. --- src/common/convauto.cpp | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/src/common/convauto.cpp b/src/common/convauto.cpp index f63d015c83..840841f5b6 100644 --- a/src/common/convauto.cpp +++ b/src/common/convauto.cpp @@ -320,11 +320,11 @@ wxConvAuto::ToWChar(wchar_t *dst, size_t dstLen, // if the conversion failed but we didn't really detect anything and // simply tried UTF-8 by default, retry it using the fall-back + if ( m_encDefault == wxFONTENCODING_DEFAULT ) + self->m_encDefault = GetFallbackEncoding(); if ( m_encDefault != wxFONTENCODING_MAX ) { - self->m_conv = new wxCSConv(m_encDefault == wxFONTENCODING_DEFAULT - ? GetFallbackEncoding() - : m_encDefault); + self->m_conv = new wxCSConv(m_encDefault); self->m_ownsConv = true; rc = m_conv->ToWChar(dst, dstLen, src, srcLen); @@ -372,10 +372,8 @@ wxFontEncoding wxConvAuto::GetEncoding() const return wxFONTENCODING_MAX; else if ( !m_ownsConv ) return wxFONTENCODING_UTF8; - else if ( m_encDefault != wxFONTENCODING_DEFAULT ) - return m_encDefault; else - return GetFallbackEncoding(); + return m_encDefault; } wxFAIL_MSG( "unknown BOM type" );