mirror of
https://github.com/glest/glest-source.git
synced 2025-02-24 19:52:25 +01:00
- updates for possible chinese support (but i really doubt this shows the right text) but stil la good start
This commit is contained in:
parent
879aaa7fe8
commit
cc958d266e
@ -2440,8 +2440,9 @@ int glestMain(int argc, char** argv) {
|
||||
Texture::useTextureCompression = config.getBool("EnableTextureCompression","false");
|
||||
// 256 for English
|
||||
// 30000 for Chinese
|
||||
Font::charCount = config.getInt("FONT_CHARCOUNT",intToStr(Font::charCount).c_str());
|
||||
Font::fontTypeName = config.getString("FONT_TYPENAME",Font::fontTypeName.c_str());
|
||||
Font::charCount = config.getInt("FONT_CHARCOUNT",intToStr(Font::charCount).c_str());
|
||||
Font::fontTypeName = config.getString("FONT_TYPENAME",Font::fontTypeName.c_str());
|
||||
Font::fontIsMultibyte = config.getBool("FONT_MULTIBYTE",intToStr(Font::fontIsMultibyte).c_str());
|
||||
// Example values:
|
||||
// DEFAULT_CHARSET (English) = 1
|
||||
// GB2312_CHARSET (Chinese) = 134
|
||||
@ -2463,7 +2464,7 @@ int glestMain(int argc, char** argv) {
|
||||
// Setup debug logging etc
|
||||
setupLogging(config, haveSpecialOutputCommandLineOption);
|
||||
|
||||
SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d] Font::charCount = %d, Font::fontTypeName [%s] Shared::Platform::charSet = %d\n",__FILE__,__FUNCTION__,__LINE__,Font::charCount,Font::fontTypeName.c_str(),Shared::Platform::charSet);
|
||||
SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d] Font::charCount = %d, Font::fontTypeName [%s] Shared::Platform::charSet = %d, Font::fontIsMultibyte = %d\n",__FILE__,__FUNCTION__,__LINE__,Font::charCount,Font::fontTypeName.c_str(),Shared::Platform::charSet,Font::fontIsMultibyte);
|
||||
|
||||
NetworkInterface::setDisplayMessageFunction(ExceptionHandler::DisplayMessage);
|
||||
MenuStateMasterserver::setDisplayMessageFunction(ExceptionHandler::DisplayMessage);
|
||||
@ -2531,20 +2532,25 @@ int glestMain(int argc, char** argv) {
|
||||
|
||||
lang.loadStrings(language);
|
||||
|
||||
if( lang.hasString("FONT_CHARCOUNT") &&
|
||||
lang.hasString("FONT_TYPENAME") &&
|
||||
lang.hasString("FONT_CHARSET")) {
|
||||
if( lang.hasString("FONT_CHARCOUNT")) {
|
||||
// 256 for English
|
||||
// 30000 for Chinese
|
||||
Font::charCount = strToInt(lang.get("FONT_CHARCOUNT"));
|
||||
}
|
||||
if( lang.hasString("FONT_TYPENAME")) {
|
||||
Font::fontTypeName = lang.get("FONT_TYPENAME");
|
||||
}
|
||||
if( lang.hasString("FONT_CHARSET")) {
|
||||
// Example values:
|
||||
// DEFAULT_CHARSET (English) = 1
|
||||
// GB2312_CHARSET (Chinese) = 134
|
||||
Shared::Platform::charSet = strToInt(lang.get("FONT_CHARSET"));
|
||||
}
|
||||
SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d] Font::charCount = %d, Font::fontTypeName [%s] Shared::Platform::charSet = %d\n",__FILE__,__FUNCTION__,__LINE__,Font::charCount,Font::fontTypeName.c_str(),Shared::Platform::charSet);
|
||||
if(SystemFlags::VERBOSE_MODE_ENABLED) printf("Using Font::charCount = %d, Font::fontTypeName [%s] Shared::Platform::charSet = %d\n",Font::charCount,Font::fontTypeName.c_str(),Shared::Platform::charSet);
|
||||
if( lang.hasString("FONT_MULTIBYTE")) {
|
||||
Font::fontIsMultibyte = strToBool(lang.get("FONT_MULTIBYTE"));
|
||||
}
|
||||
SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d] Font::charCount = %d, Font::fontTypeName [%s] Shared::Platform::charSet = %d, Font::fontIsMultibyte = %d\n",__FILE__,__FUNCTION__,__LINE__,Font::charCount,Font::fontTypeName.c_str(),Shared::Platform::charSet,Font::fontIsMultibyte);
|
||||
if(SystemFlags::VERBOSE_MODE_ENABLED) printf("Using Font::charCount = %d, Font::fontTypeName [%s] Shared::Platform::charSet = %d, Font::fontIsMultibyte = %d\n",Font::charCount,Font::fontTypeName.c_str(),Shared::Platform::charSet,Font::fontIsMultibyte);
|
||||
|
||||
SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__);
|
||||
|
||||
|
@ -47,6 +47,7 @@ class Font{
|
||||
public:
|
||||
static int charCount;
|
||||
static std::string fontTypeName;
|
||||
static bool fontIsMultibyte;
|
||||
|
||||
public:
|
||||
enum Width{
|
||||
|
@ -21,6 +21,7 @@ namespace Shared{ namespace Graphics{
|
||||
|
||||
int Font::charCount= 256;
|
||||
std::string Font::fontTypeName = "Times New Roman";
|
||||
bool Font::fontIsMultibyte = false;
|
||||
|
||||
// =====================================================
|
||||
// class FontMetrics
|
||||
|
@ -13,6 +13,7 @@
|
||||
|
||||
#include "opengl.h"
|
||||
#include "font_gl.h"
|
||||
//#include <stdlib.h>
|
||||
#include "leak_dumper.h"
|
||||
|
||||
namespace Shared{ namespace Graphics{ namespace Gl{
|
||||
@ -32,6 +33,22 @@ void TextRenderer2DGl::begin(const Font2D *font){
|
||||
this->font= static_cast<const Font2DGl*>(font);
|
||||
}
|
||||
|
||||
//// Convert a narrow string to a wide string//
|
||||
//std::wstring widen(const std::string& str) {
|
||||
// // Make space for wide string
|
||||
// wchar_t* buffer = new wchar_t[str.size() + 1];
|
||||
// // convert ASCII to UNICODE
|
||||
// mbstowcs( buffer, str.c_str(), str.size() );
|
||||
// // NULL terminate it
|
||||
// buffer[str.size()] = 0;
|
||||
// // Clean memory and return it
|
||||
// std::wstring wstr = buffer;
|
||||
// delete [] buffer;
|
||||
// return wstr;
|
||||
//
|
||||
//}
|
||||
//// Widen an individual character
|
||||
|
||||
void TextRenderer2DGl::render(const string &text, int x, int y, bool centered, Vec3f *color) {
|
||||
assert(rendering);
|
||||
|
||||
@ -57,19 +74,44 @@ void TextRenderer2DGl::render(const string &text, int x, int y, bool centered, V
|
||||
}
|
||||
glRasterPos2f(rasterPos.x, rasterPos.y);
|
||||
|
||||
for (int i=0; utext[i]!='\0'; ++i) {
|
||||
switch(utext[i]){
|
||||
case '\t':
|
||||
rasterPos= Vec2f((rasterPos.x/size+3.f)*size, y-(size+1.f)*line);
|
||||
glRasterPos2f(rasterPos.x, rasterPos.y);
|
||||
break;
|
||||
case '\n':
|
||||
line++;
|
||||
rasterPos= Vec2f(static_cast<float>(x), y-(metrics->getHeight()*2.f)*line);
|
||||
glRasterPos2f(rasterPos.x, rasterPos.y);
|
||||
break;
|
||||
default:
|
||||
glCallList(font->getHandle()+utext[i]);
|
||||
if(Font::fontIsMultibyte == true) {
|
||||
//setlocale(LC_CTYPE, "en_ca.UTF-8");
|
||||
|
||||
//wstring wText = widen(text);
|
||||
//glListBase(font->getHandle());
|
||||
//glCallLists(wText.length(), GL_UNSIGNED_SHORT, &wText[0]);
|
||||
|
||||
//string utfText = text;
|
||||
//glListBase(font->getHandle());
|
||||
//glCallLists(utfText.length(), GL_UNSIGNED_SHORT, &utfText[0]);
|
||||
|
||||
string utfText = text;
|
||||
glListBase(font->getHandle());
|
||||
glCallLists(text.length(), GL_UNSIGNED_SHORT, &utext[0]);
|
||||
|
||||
//std::locale loc("");
|
||||
//wstring wText = widen(text);
|
||||
//std::string strBuffer(Text.size() * 4 + 1, 0);
|
||||
//std::use_facet<std::ctype<wchar_t> >(loc).narrow(&Text[0], &Text[0] + Text.size(), '?', &strBuffer[0]);
|
||||
//string utfText = std::string(&strBuffer[0]);
|
||||
//glListBase(font->getHandle());
|
||||
//glCallLists(utfText.length(), GL_UNSIGNED_SHORT, &utfText[0]);
|
||||
}
|
||||
else {
|
||||
for (int i=0; utext[i]!='\0'; ++i) {
|
||||
switch(utext[i]){
|
||||
case '\t':
|
||||
rasterPos= Vec2f((rasterPos.x/size+3.f)*size, y-(size+1.f)*line);
|
||||
glRasterPos2f(rasterPos.x, rasterPos.y);
|
||||
break;
|
||||
case '\n':
|
||||
line++;
|
||||
rasterPos= Vec2f(static_cast<float>(x), y-(metrics->getHeight()*2.f)*line);
|
||||
glRasterPos2f(rasterPos.x, rasterPos.y);
|
||||
break;
|
||||
default:
|
||||
glCallList(font->getHandle()+utext[i]);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user