- added some bug fixes to check if lng files are utf-8 or not and deal with it appropriately

This commit is contained in:
Mark Vejvoda
2011-06-08 07:18:06 +00:00
parent bf9702cdca
commit f65bfe8710
29 changed files with 3072 additions and 83 deletions

View File

@@ -57,6 +57,7 @@
#include "randomgen.h"
#include <algorithm>
#include "platform_util.h"
#include "utf8.h"
#include "leak_dumper.h"
using namespace Shared::Platform;
@@ -1934,6 +1935,33 @@ void copyFileTo(string fromFileName, string toFileName) {
#endif
}
bool valid_utf8_file(const char* file_name) {
#if defined(WIN32) && !defined(__MINGW32__)
wstring wstr = utf8_decode(file_name);
FILE *fp = _wfopen(wstr.c_str(), L"r");
ifstream ifs(fp);
#else
ifstream ifs(file_name);
#endif
if (!ifs) {
return false; // even better, throw here
}
istreambuf_iterator<char> it(ifs.rdbuf());
istreambuf_iterator<char> eos;
bool result = utf8::is_valid(it, eos);
ifs.close();
#if defined(WIN32) && !defined(__MINGW32__)
if(fp) {
fclose(fp);
}
#endif
return result;
}
// =====================================
// ModeInfo
// =====================================

View File

@@ -41,12 +41,15 @@ void createGlFontBitmaps(uint32 &base, const string &type, int size, int width,
}
if(SystemFlags::VERBOSE_MODE_ENABLED) printf("About to try font [%s]\n",type.c_str());
printf("About to try font [%s]\n",type.c_str());
XFontStruct* fontInfo = XLoadQueryFont(display, type.c_str());
if(fontInfo == NULL) {
string default_font = FontGl::getDefault_fontType();
//throw std::runtime_error("Font not found: [" + type + "]");
SystemFlags::OutputDebug(SystemFlags::debugError,"Font not found [%s] trying to fallback to [%s]\n",type.c_str(),default_font.c_str());
printf("Font not found [%s] trying to fallback to [%s]\n",type.c_str(),default_font.c_str());
fontInfo = XLoadQueryFont(display, default_font.c_str());
if(fontInfo == NULL) {