diff --git a/source/glest_game/main/main.cpp b/source/glest_game/main/main.cpp index 2e2158555..6e090b618 100644 --- a/source/glest_game/main/main.cpp +++ b/source/glest_game/main/main.cpp @@ -2471,10 +2471,12 @@ int glestMain(int argc, char** argv) { if(config.getBool("EnableLegacyFonts","false") == true || hasCommandArgument(argc, argv,GAME_ARGS[GAME_ARG_ENABLE_LEGACYFONTS]) == true) { Font::forceLegacyFonts = true; + Renderer::renderText3DEnabled = false; if(SystemFlags::VERBOSE_MODE_ENABLED) printf("**WARNING** Forcing Legacy Fonts Enabled\n"); } - - Renderer::renderText3DEnabled = config.getBool("Enable3DFontRendering",intToStr(Renderer::renderText3DEnabled).c_str()); + else { + Renderer::renderText3DEnabled = config.getBool("Enable3DFontRendering",intToStr(Renderer::renderText3DEnabled).c_str()); + } if(hasCommandArgument(argc, argv,GAME_ARGS[GAME_ARG_USE_VIDEO_SETTINGS]) == true) { int foundParamIndIndex = -1; diff --git a/source/shared_lib/include/util/string_utils.h b/source/shared_lib/include/util/string_utils.h index 89490282a..e478ef193 100644 --- a/source/shared_lib/include/util/string_utils.h +++ b/source/shared_lib/include/util/string_utils.h @@ -243,6 +243,8 @@ namespace Shared { namespace Util { */ static String ConvertToUTF8(const String& s); + static char* ConvertFromUTF8(const char* str); + /*! ** \brief Formatted string ** \param format The format of the new string diff --git a/source/shared_lib/sources/util/properties.cpp b/source/shared_lib/sources/util/properties.cpp index 4345c0a65..ee972f366 100644 --- a/source/shared_lib/sources/util/properties.cpp +++ b/source/shared_lib/sources/util/properties.cpp @@ -289,14 +289,28 @@ void Properties::load(const string &path, bool clearCurrentProperties) { //printf("\n[%ls]\n",lineBuffer); //printf("\n[%s]\n",&lineBuffer[0]); - // If the file is NOT in UTF-8 format convert each line - if(is_utf8_language == false && Font::forceLegacyFonts == false) { - char *utfStr = String::ConvertToUTF8(&lineBuffer[0]); + if(lineBuffer[0] != '\0') { + // If the file is NOT in UTF-8 format convert each line + if(is_utf8_language == false && Font::forceLegacyFonts == false) { + char *utfStr = String::ConvertToUTF8(&lineBuffer[0]); - //printf("\nBefore [%s] After [%s]\n",&lineBuffer[0],utfStr); + //printf("\nBefore [%s] After [%s]\n",&lineBuffer[0],utfStr); - memset(&lineBuffer[0],0,maxLine); - memcpy(&lineBuffer[0],&utfStr[0],strlen(utfStr)); + memset(&lineBuffer[0],0,maxLine); + memcpy(&lineBuffer[0],&utfStr[0],strlen(utfStr)); + + delete [] utfStr; + } + else if(is_utf8_language == true && Font::forceLegacyFonts == true) { + char *asciiStr = String::ConvertFromUTF8(&lineBuffer[0]); + + //printf("\nBefore [%s] After [%s]\n",&lineBuffer[0],utfStr); + + memset(&lineBuffer[0],0,maxLine); + memcpy(&lineBuffer[0],&asciiStr[0],strlen(asciiStr)); + + delete [] asciiStr; + } } // bool isRLM = utf8::starts_with_rlm(&lineBuffer[0], &lineBuffer[0] + strlen(lineBuffer)); diff --git a/source/shared_lib/sources/util/string_utils.cpp b/source/shared_lib/sources/util/string_utils.cpp index f5ea0343b..45f56186a 100644 --- a/source/shared_lib/sources/util/string_utils.cpp +++ b/source/shared_lib/sources/util/string_utils.cpp @@ -346,6 +346,99 @@ namespace Shared { namespace Util { } + char* String::ConvertFromUTF8(const char* str) { + +/* + int length = strlen(str); + char *pBuffer = new char[length * 8]; + memset(pBuffer,0,length * 8); + + int len = 0; + for(unsigned int i = 0 ; i < length; i++) + { + if (((Shared::Platform::byte)str[i]) < 0x80) + { + pBuffer[len++] = ((Shared::Platform::byte)str[i]); + continue; + } + if (((Shared::Platform::byte)str[i]) >= 0xC0) + { + wchar_t c = ((Shared::Platform::byte)str[i++]) - 0xC0; + while(((Shared::Platform::byte)str[i]) >= 0x80) + c = (c << 6) | (((Shared::Platform::byte)str[i++]) - 0x80); + --i; + pBuffer[len++] = c; + continue; + } + } + pBuffer[len] = 0; + return pBuffer; +*/ + + const unsigned char *in = reinterpret_cast(str); + int len = strlen(str); + char *out = new char[len*8]; + memset(out,0,len*8); + int outc; + int inpos = 0; + int outpos = 0; + while (inpos < len || len == -1) { + if (in[inpos]<0x80) { + out[outpos++] = in[inpos]; + if (in[inpos] == 0 && len == -1) + break; + inpos++; + } + else if (in[inpos]<0xE0) { + // Shouldn't happen. + if(in[inpos]<0xC0 || (len!=-1 && inpos+1 >= len) || + (in[inpos+1]&0xC0)!= 0x80) { + out[outpos++] = '?'; + inpos++; + continue; + } + outc = ((((wchar_t)in[inpos])&0x1F)<<6) | + (((wchar_t)in[inpos+1])&0x3F); + if (outc < 256) + out[outpos] = ((char*)&outc)[0]; + else + out[outpos] = '?'; + outpos++; + inpos+=2; + } + else if (in[inpos]<0xF0) { + // Shouldn't happen. + if ((len!=-1 && inpos+2 >= len) || + (in[inpos+1]&0xC0)!= 0x80 || + (in[inpos+2]&0xC0)!= 0x80) { + out[outpos++] = '?'; + inpos++; + continue; + } + out[outpos++] = '?'; + inpos+=3; + } + else if (in[inpos]<0xF8) { + // Shouldn't happen. + if ((len!=-1 && inpos+3 >= len) || + (in[inpos+1]&0xC0)!= 0x80 || + (in[inpos+2]&0xC0)!= 0x80 || + (in[inpos+3]&0xC0)!= 0x80) { + out[outpos++] = '?'; + inpos++; + continue; + } + out[outpos++] = '?'; + inpos+=4; + } + else { + out[outpos++] = '?'; + inpos++; + } + } + return out; + } + char* String::ConvertToUTF8(const char* s) { if (NULL != s && *s != '\0')