mirror of
https://github.com/glest/glest-source.git
synced 2025-08-16 05:13:59 +02:00
- added some bug fixes to check if lng files are utf-8 or not and deal with it appropriately
This commit is contained in:
@@ -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
|
||||
// =====================================
|
||||
|
@@ -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) {
|
||||
|
Reference in New Issue
Block a user