mirror of
https://github.com/glest/glest-source.git
synced 2025-08-14 04:13:58 +02: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:
@@ -2440,8 +2440,9 @@ int glestMain(int argc, char** argv) {
|
|||||||
Texture::useTextureCompression = config.getBool("EnableTextureCompression","false");
|
Texture::useTextureCompression = config.getBool("EnableTextureCompression","false");
|
||||||
// 256 for English
|
// 256 for English
|
||||||
// 30000 for Chinese
|
// 30000 for Chinese
|
||||||
Font::charCount = config.getInt("FONT_CHARCOUNT",intToStr(Font::charCount).c_str());
|
Font::charCount = config.getInt("FONT_CHARCOUNT",intToStr(Font::charCount).c_str());
|
||||||
Font::fontTypeName = config.getString("FONT_TYPENAME",Font::fontTypeName.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:
|
// Example values:
|
||||||
// DEFAULT_CHARSET (English) = 1
|
// DEFAULT_CHARSET (English) = 1
|
||||||
// GB2312_CHARSET (Chinese) = 134
|
// GB2312_CHARSET (Chinese) = 134
|
||||||
@@ -2463,7 +2464,7 @@ int glestMain(int argc, char** argv) {
|
|||||||
// Setup debug logging etc
|
// Setup debug logging etc
|
||||||
setupLogging(config, haveSpecialOutputCommandLineOption);
|
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);
|
NetworkInterface::setDisplayMessageFunction(ExceptionHandler::DisplayMessage);
|
||||||
MenuStateMasterserver::setDisplayMessageFunction(ExceptionHandler::DisplayMessage);
|
MenuStateMasterserver::setDisplayMessageFunction(ExceptionHandler::DisplayMessage);
|
||||||
@@ -2531,20 +2532,25 @@ int glestMain(int argc, char** argv) {
|
|||||||
|
|
||||||
lang.loadStrings(language);
|
lang.loadStrings(language);
|
||||||
|
|
||||||
if( lang.hasString("FONT_CHARCOUNT") &&
|
if( lang.hasString("FONT_CHARCOUNT")) {
|
||||||
lang.hasString("FONT_TYPENAME") &&
|
|
||||||
lang.hasString("FONT_CHARSET")) {
|
|
||||||
// 256 for English
|
// 256 for English
|
||||||
// 30000 for Chinese
|
// 30000 for Chinese
|
||||||
Font::charCount = strToInt(lang.get("FONT_CHARCOUNT"));
|
Font::charCount = strToInt(lang.get("FONT_CHARCOUNT"));
|
||||||
|
}
|
||||||
|
if( lang.hasString("FONT_TYPENAME")) {
|
||||||
Font::fontTypeName = lang.get("FONT_TYPENAME");
|
Font::fontTypeName = lang.get("FONT_TYPENAME");
|
||||||
|
}
|
||||||
|
if( lang.hasString("FONT_CHARSET")) {
|
||||||
// Example values:
|
// Example values:
|
||||||
// DEFAULT_CHARSET (English) = 1
|
// DEFAULT_CHARSET (English) = 1
|
||||||
// GB2312_CHARSET (Chinese) = 134
|
// GB2312_CHARSET (Chinese) = 134
|
||||||
Shared::Platform::charSet = strToInt(lang.get("FONT_CHARSET"));
|
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( lang.hasString("FONT_MULTIBYTE")) {
|
||||||
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);
|
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__);
|
SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__);
|
||||||
|
|
||||||
|
@@ -47,6 +47,7 @@ class Font{
|
|||||||
public:
|
public:
|
||||||
static int charCount;
|
static int charCount;
|
||||||
static std::string fontTypeName;
|
static std::string fontTypeName;
|
||||||
|
static bool fontIsMultibyte;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
enum Width{
|
enum Width{
|
||||||
|
@@ -21,6 +21,7 @@ namespace Shared{ namespace Graphics{
|
|||||||
|
|
||||||
int Font::charCount= 256;
|
int Font::charCount= 256;
|
||||||
std::string Font::fontTypeName = "Times New Roman";
|
std::string Font::fontTypeName = "Times New Roman";
|
||||||
|
bool Font::fontIsMultibyte = false;
|
||||||
|
|
||||||
// =====================================================
|
// =====================================================
|
||||||
// class FontMetrics
|
// class FontMetrics
|
||||||
|
@@ -13,6 +13,7 @@
|
|||||||
|
|
||||||
#include "opengl.h"
|
#include "opengl.h"
|
||||||
#include "font_gl.h"
|
#include "font_gl.h"
|
||||||
|
//#include <stdlib.h>
|
||||||
#include "leak_dumper.h"
|
#include "leak_dumper.h"
|
||||||
|
|
||||||
namespace Shared{ namespace Graphics{ namespace Gl{
|
namespace Shared{ namespace Graphics{ namespace Gl{
|
||||||
@@ -32,6 +33,22 @@ void TextRenderer2DGl::begin(const Font2D *font){
|
|||||||
this->font= static_cast<const Font2DGl*>(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) {
|
void TextRenderer2DGl::render(const string &text, int x, int y, bool centered, Vec3f *color) {
|
||||||
assert(rendering);
|
assert(rendering);
|
||||||
|
|
||||||
@@ -57,19 +74,44 @@ void TextRenderer2DGl::render(const string &text, int x, int y, bool centered, V
|
|||||||
}
|
}
|
||||||
glRasterPos2f(rasterPos.x, rasterPos.y);
|
glRasterPos2f(rasterPos.x, rasterPos.y);
|
||||||
|
|
||||||
for (int i=0; utext[i]!='\0'; ++i) {
|
if(Font::fontIsMultibyte == true) {
|
||||||
switch(utext[i]){
|
//setlocale(LC_CTYPE, "en_ca.UTF-8");
|
||||||
case '\t':
|
|
||||||
rasterPos= Vec2f((rasterPos.x/size+3.f)*size, y-(size+1.f)*line);
|
//wstring wText = widen(text);
|
||||||
glRasterPos2f(rasterPos.x, rasterPos.y);
|
//glListBase(font->getHandle());
|
||||||
break;
|
//glCallLists(wText.length(), GL_UNSIGNED_SHORT, &wText[0]);
|
||||||
case '\n':
|
|
||||||
line++;
|
//string utfText = text;
|
||||||
rasterPos= Vec2f(static_cast<float>(x), y-(metrics->getHeight()*2.f)*line);
|
//glListBase(font->getHandle());
|
||||||
glRasterPos2f(rasterPos.x, rasterPos.y);
|
//glCallLists(utfText.length(), GL_UNSIGNED_SHORT, &utfText[0]);
|
||||||
break;
|
|
||||||
default:
|
string utfText = text;
|
||||||
glCallList(font->getHandle()+utext[i]);
|
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]);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user