- better bullet proofing of reading lng files
- able to run in old font mode for comparison
This commit is contained in:
parent
f1aa231e4b
commit
1d5dcb4ded
|
@ -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;
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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));
|
||||
|
|
|
@ -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<const unsigned char*>(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')
|
||||
|
|
Loading…
Reference in New Issue
Block a user