From 226e8783c00138b467f4defa1ca399fe504f6dc4 Mon Sep 17 00:00:00 2001 From: Mark Vejvoda Date: Tue, 7 Jun 2011 02:37:58 +0000 Subject: [PATCH] - added packaged game fonts - updated code to search new default font folder - added chinese language file from the fourm for testing --- source/glest_game/facilities/game_util.cpp | 12 ++-- source/glest_game/main/main.cpp | 3 + .../shared_lib/include/graphics/font_text.h | 2 + .../shared_lib/include/graphics/gl/font_gl.h | 11 +--- .../include/graphics/gl/text_renderer_gl.h | 12 ---- source/shared_lib/sources/graphics/font.cpp | 2 +- .../shared_lib/sources/graphics/font_text.cpp | 2 + .../sources/graphics/gl/font_gl.cpp | 8 --- .../sources/graphics/gl/font_textFTGL.cpp | 7 ++- .../sources/graphics/gl/text_renderer_gl.cpp | 63 +++---------------- .../sources/platform/unix/gl_wrap.cpp | 2 - .../sources/platform/win32/gl_wrap_billy.cpp | 4 -- 12 files changed, 30 insertions(+), 98 deletions(-) diff --git a/source/glest_game/facilities/game_util.cpp b/source/glest_game/facilities/game_util.cpp index 1cc9616e..94eaeedd 100644 --- a/source/glest_game/facilities/game_util.cpp +++ b/source/glest_game/facilities/game_util.cpp @@ -1,7 +1,7 @@ // ============================================================== // This file is part of Glest (www.glest.org) // -// Copyright (C) 2001-2008 Marti�o Figueroa +// Copyright (C) 2001-2008 Martiño Figueroa // // You can redistribute this code and/or modify it under // the terms of the GNU General Public License as published @@ -151,11 +151,11 @@ string getAboutString2(int i){ string getTeammateName(int i) { switch(i) { - case 0: return "Martiño Figueroa"; - case 1: return "José Luis González"; - case 2: return "Tucho Fernández"; - case 3: return "José Zanni"; - case 4: return "Félix Menéndez"; + case 0: return "Marti�o Figueroa"; + case 1: return "Jos� Luis Gonz�lez"; + case 2: return "Tucho Fern�ndez"; + case 3: return "Jos� Zanni"; + case 4: return "F�lix Men�ndez"; case 5: return "Marcos Caruncho"; case 6: return "Matthias Braun"; case 7: return "Titus Tscharntke"; diff --git a/source/glest_game/main/main.cpp b/source/glest_game/main/main.cpp index 2366bfe7..e1d2f370 100644 --- a/source/glest_game/main/main.cpp +++ b/source/glest_game/main/main.cpp @@ -38,6 +38,7 @@ #include "cache_manager.h" #include #include "core_data.h" +#include "font_text.h" //#include "unicode/uclean.h" // For gcc backtrace on crash! @@ -1148,6 +1149,7 @@ int setupGameItemPaths(int argc, char** argv, Config *config) { } } + Text::DEFAULT_FONT_PATH = pathCache[GameConstants::path_data_CacheLookupKey]; return 0; } @@ -2448,6 +2450,7 @@ int glestMain(int argc, char** argv) { FontGl::setDefault_fontType(config.getString("DefaultFont",FontGl::getDefault_fontType().c_str())); UPNP_Tools::isUPNP = !config.getBool("DisableUPNP","false"); Texture::useTextureCompression = config.getBool("EnableTextureCompression","false"); + // 256 for English // 30000 for Chinese Font::charCount = config.getInt("FONT_CHARCOUNT",intToStr(Font::charCount).c_str()); diff --git a/source/shared_lib/include/graphics/font_text.h b/source/shared_lib/include/graphics/font_text.h index c55581d5..04d71d67 100644 --- a/source/shared_lib/include/graphics/font_text.h +++ b/source/shared_lib/include/graphics/font_text.h @@ -23,6 +23,8 @@ class Text { public: + static std::string DEFAULT_FONT_PATH; + Text(); virtual ~Text(); diff --git a/source/shared_lib/include/graphics/gl/font_gl.h b/source/shared_lib/include/graphics/gl/font_gl.h index 8554ff75..0b47929f 100644 --- a/source/shared_lib/include/graphics/gl/font_gl.h +++ b/source/shared_lib/include/graphics/gl/font_gl.h @@ -28,20 +28,15 @@ namespace Shared { namespace Graphics { namespace Gl { class FontGl { protected: -//#ifndef USE_FTGL GLuint handle; -//#endif - static string default_fonttype; public: -//#ifndef USE_FTGL - GLuint getHandle() const {return handle;} -//#endif + GLuint getHandle() const {return handle;} - static string getDefault_fontType() { return default_fonttype; } - static void setDefault_fontType(string value) { default_fonttype = value; } + static string getDefault_fontType() {return default_fonttype;} + static void setDefault_fontType(string value) {default_fonttype = value;} }; // ===================================================== diff --git a/source/shared_lib/include/graphics/gl/text_renderer_gl.h b/source/shared_lib/include/graphics/gl/text_renderer_gl.h index 51484eac..e9f9bdba 100644 --- a/source/shared_lib/include/graphics/gl/text_renderer_gl.h +++ b/source/shared_lib/include/graphics/gl/text_renderer_gl.h @@ -19,10 +19,6 @@ namespace Shared { namespace Graphics { namespace Gl { class Font2DGl; class Font3DGl; -//#ifdef USE_FTGL -// class TextFTGL; -//#endif - // ===================================================== // class TextRenderer2DGl @@ -33,10 +29,6 @@ private: Font2DGl *font; bool rendering; -//#ifdef USE_FTGL -// TextFTGL *fontFTGL; -//#endif - public: TextRenderer2DGl(); virtual ~TextRenderer2DGl(); @@ -55,10 +47,6 @@ private: Font3DGl *font; bool rendering; -//#ifdef USE_FTGL -// TextFTGL *fontFTGL; -//#endif - public: TextRenderer3DGl(); virtual ~TextRenderer3DGl(); diff --git a/source/shared_lib/sources/graphics/font.cpp b/source/shared_lib/sources/graphics/font.cpp index 2f2a4b8e..0220e617 100644 --- a/source/shared_lib/sources/graphics/font.cpp +++ b/source/shared_lib/sources/graphics/font.cpp @@ -28,7 +28,7 @@ using namespace Shared::Graphics::Gl; using namespace std; using namespace Shared::Util; -namespace Shared{ namespace Graphics{ +namespace Shared { namespace Graphics { // Init statics int Font::charCount = 256; diff --git a/source/shared_lib/sources/graphics/font_text.cpp b/source/shared_lib/sources/graphics/font_text.cpp index 9e264962..7a2927b9 100644 --- a/source/shared_lib/sources/graphics/font_text.cpp +++ b/source/shared_lib/sources/graphics/font_text.cpp @@ -12,6 +12,8 @@ using namespace std; +std::string Text::DEFAULT_FONT_PATH = ""; + //==================================================================== Text::Text() {} Text::~Text() {} diff --git a/source/shared_lib/sources/graphics/gl/font_gl.cpp b/source/shared_lib/sources/graphics/gl/font_gl.cpp index 7bf223d9..2b1bc177 100644 --- a/source/shared_lib/sources/graphics/gl/font_gl.cpp +++ b/source/shared_lib/sources/graphics/gl/font_gl.cpp @@ -27,7 +27,6 @@ string FontGl::default_fonttype = "fixed"; void Font2DGl::init() { if(inited == false) { -//#ifndef USE_FTGL if(getTextHandler() == NULL) { assertGl(); handle= glGenLists(charCount); @@ -36,21 +35,18 @@ void Font2DGl::init() { createGlFontBitmaps(handle, type, size, width, charCount, metrics); assertGl(); } -//#endif inited= true; } } void Font2DGl::end() { if(inited) { -//#ifndef USE_FTGL if(getTextHandler() == NULL) { assertGl(); //assert(glIsList(handle)); glDeleteLists(handle, 1); assertGl(); } -//#endif inited = false; } } @@ -61,28 +57,24 @@ void Font2DGl::end() { void Font3DGl::init() { if(inited == false) { -//#ifndef USE_FTGL if(getTextHandler() == NULL) { assertGl(); handle= glGenLists(charCount); createGlFontOutlines(handle, type, width, depth, charCount, metrics); assertGl(); } -//#endif inited= true; } } void Font3DGl::end() { if(inited) { -//#ifndef USE_FTGL if(getTextHandler() == NULL) { assertGl(); assert(glIsList(handle)); glDeleteLists(handle, 1); assertGl(); } -//#endif } } diff --git a/source/shared_lib/sources/graphics/gl/font_textFTGL.cpp b/source/shared_lib/sources/graphics/gl/font_textFTGL.cpp index b92a0f97..dbe485b5 100644 --- a/source/shared_lib/sources/graphics/gl/font_textFTGL.cpp +++ b/source/shared_lib/sources/graphics/gl/font_textFTGL.cpp @@ -38,7 +38,7 @@ TextFTGL::TextFTGL() { //setenv("MEGAGLEST_FONT","/usr/share/fonts/truetype/ttf-sil-doulos/DoulosSILR.ttf",0); // Russian / Cyrillic //setenv("MEGAGLEST_FONT","/usr/share/fonts/truetype/ttf-sil-charis/CharisSILR.ttf",0); // Russian / Cyrillic //setenv("MEGAGLEST_FONT","/usr/share/fonts/truetype/ubuntu-font-family/Ubuntu-R.ttf",0); // Russian / Cyrillic - //setenv("MEGAGLEST_FONT","/usr/share/fonts/truetype/ttf-japanese-gothic.ttf",0); // Japanese + //setenv("MEGAGLEST_FONT","/usr/share/fonts/truetype/takao/TakaoPGothic.ttf",0); // Japanese //setenv("MEGAGLEST_FONT","/usr/share/fonts/truetype/ttf-sil-scheherazade/ScheherazadeRegOT.ttf",0); // Arabic //setenv("MEGAGLEST_FONT","/usr/share/fonts/truetype/linux-libertine/LinLibertine_Re.ttf",0); // Hebrew //setenv("MEGAGLEST_FONT","/usr/share/fonts/truetype/unifont/unifont.ttf",0); // Czech? @@ -219,6 +219,11 @@ const char* TextFTGL::findFont(const char *firstFontToTry) { } #endif + string data_path = Text::DEFAULT_FONT_PATH; + const string defaultFont = data_path + "data/core/fonts/gothub__.ttf"; + + CHECK_FONT_PATH("/usr/share/fonts/truetype/uralic/gothub__.ttf") + // Check a couple of common paths for Gothic Uralic/bold as a last resort // Debian /* diff --git a/source/shared_lib/sources/graphics/gl/text_renderer_gl.cpp b/source/shared_lib/sources/graphics/gl/text_renderer_gl.cpp index 6b1deb45..4362fcd2 100644 --- a/source/shared_lib/sources/graphics/gl/text_renderer_gl.cpp +++ b/source/shared_lib/sources/graphics/gl/text_renderer_gl.cpp @@ -1,7 +1,7 @@ // ============================================================== // This file is part of Glest Shared Library (www.glest.org) // -// Copyright (C) 2001-2008 Martio Figueroa +// Copyright (C) 2001-2008 Martiño Figueroa // // You can redistribute this code and/or modify it under // the terms of the GNU General Public License as published @@ -15,14 +15,8 @@ #include "font_gl.h" #include "font_text.h" -//#ifdef USE_FTGL -//#include "font_textFTGL.h" #include #include -//#include "string_utils.h" -//using namespace Shared::Util; -//#endif - #include "leak_dumper.h" namespace Shared { namespace Graphics { namespace Gl { @@ -34,29 +28,16 @@ namespace Shared { namespace Graphics { namespace Gl { TextRenderer2DGl::TextRenderer2DGl() { rendering= false; this->font = NULL; -//#ifdef USE_FTGL -// fontFTGL = new TextFTGL(); -//#endif - } TextRenderer2DGl::~TextRenderer2DGl() { -//#ifdef USE_FTGL -// delete fontFTGL; -// fontFTGL = NULL; -//#endif } void TextRenderer2DGl::begin(Font2D *font) { assert(!rendering); - rendering= true; - - this->font= static_cast(font); -//#ifdef USE_FTGL -// this->font->getMetrics()->setHeight(fontFTGL->LineHeight(" ")); -// this->font->getMetrics()->setWidth(i,fontFTGL->Advance(" ")); -//#endif + rendering = true; + this->font = static_cast(font); } // Convert a narrow string to a wide string// @@ -89,21 +70,20 @@ void TextRenderer2DGl::render(const string &text, int x, int y, bool centered, V const unsigned char *utext = NULL; FontMetrics *metrics = NULL; - Vec2f rasterPos; -//#ifdef USE_FTGL - if(font->getTextHandler() != NULL) { - //font->getTextHandler()->SetFaceSize(size); + //printf("font->getTextHandler() [%p] centered = %d text [%s]\n",font->getTextHandler(),centered,text.c_str()); + Vec2f rasterPos; + if(font->getTextHandler() != NULL) { if(centered) { rasterPos.x= x - font->getTextHandler()->Advance(text.c_str()) / 2.f; rasterPos.y= y + font->getTextHandler()->LineHeight(text.c_str()) / 2.f; } else { rasterPos= Vec2f(static_cast(x), static_cast(y)); + rasterPos.y= y + (font->getTextHandler()->LineHeight(text.c_str()) / 8.f); } } else { -//#else utext= reinterpret_cast(text.c_str()); metrics= font->getMetrics(); if(centered) { @@ -114,12 +94,9 @@ void TextRenderer2DGl::render(const string &text, int x, int y, bool centered, V rasterPos= Vec2f(static_cast(x), static_cast(y)); } } -//#endif glRasterPos2f(rasterPos.x, rasterPos.y); if(Font::fontIsMultibyte == true) { - -//#ifdef USE_FTGL if(font->getTextHandler() != NULL) { //String str("資料"); //WString wstr(str); @@ -228,8 +205,6 @@ void TextRenderer2DGl::render(const string &text, int x, int y, bool centered, V } } else { -//#else - //setlocale(LC_CTYPE, "en_ca.UTF-8"); //wstring wText = widen(text); @@ -252,11 +227,8 @@ void TextRenderer2DGl::render(const string &text, int x, int y, bool centered, V //glListBase(font->getHandle()); //glCallLists(utfText.length(), GL_UNSIGNED_SHORT, &utfText[0]); } -//#endif } else { - -//#ifdef USE_FTGL if(font->getTextHandler() != NULL) { if(text.find("\n") == text.npos && text.find("\t") == text.npos) { font->getTextHandler()->Render(text.c_str()); @@ -314,7 +286,6 @@ void TextRenderer2DGl::render(const string &text, int x, int y, bool centered, V } } else { -//#else for (int i=0; utext[i]!='\0'; ++i) { switch(utext[i]){ case '\t': @@ -331,7 +302,6 @@ void TextRenderer2DGl::render(const string &text, int x, int y, bool centered, V } } } -//#endif } if(color != NULL) { @@ -352,16 +322,9 @@ void TextRenderer2DGl::end() { TextRenderer3DGl::TextRenderer3DGl() { rendering= false; this->font = NULL; -//#ifdef USE_FTGL -// fontFTGL = new TextFTGL(); -//#endif } TextRenderer3DGl::~TextRenderer3DGl() { -//#ifdef USE_FTGL -// delete fontFTGL; -// fontFTGL = NULL; -//#endif } void TextRenderer3DGl::begin(Font3D *font) { @@ -390,10 +353,7 @@ void TextRenderer3DGl::render(const string &text, float x, float y, float size, float scale= size / 10.f; Vec3f translatePos; -//#ifdef USE_FTGL if(font->getTextHandler() != NULL) { - //font->getTextHandler()->SetFaceSize(size); - if(centered) { translatePos.x = x - scale * font->getTextHandler()->Advance(text.c_str()) / 2.f; translatePos.y = y - scale * font->getTextHandler()->LineHeight(text.c_str()) / 2.f; @@ -406,7 +366,6 @@ void TextRenderer3DGl::render(const string &text, float x, float y, float size, } } else { -//#else utext= reinterpret_cast(text.c_str()); if(centered) { FontMetrics *metrics= font->getMetrics(); @@ -422,14 +381,11 @@ void TextRenderer3DGl::render(const string &text, float x, float y, float size, translatePos.z = 0; } } -//#endif glTranslatef(translatePos.x, translatePos.y, translatePos.z); glScalef(scale, scale, scale); if(Font::fontIsMultibyte == true) { - -//#ifdef USE_FTGL if(font->getTextHandler() != NULL) { if(text.find("\n") == text.npos && text.find("\t") == text.npos) { font->getTextHandler()->Render(text.c_str()); @@ -488,7 +444,6 @@ void TextRenderer3DGl::render(const string &text, float x, float y, float size, } } else { -//#else //setlocale(LC_CTYPE, "en_ca.UTF-8"); //wstring wText = widen(text); @@ -511,12 +466,10 @@ void TextRenderer3DGl::render(const string &text, float x, float y, float size, //glListBase(font->getHandle()); //glCallLists(utfText.length(), GL_UNSIGNED_SHORT, &utfText[0]); } -//#endif } else { if(font->getTextHandler() != NULL) { -//#ifdef USE_FTGL if(text.find("\n") == text.npos && text.find("\t") == text.npos) { font->getTextHandler()->Render(text.c_str()); } @@ -574,12 +527,10 @@ void TextRenderer3DGl::render(const string &text, float x, float y, float size, } } else { -//#else for (int i=0; utext[i]!='\0'; ++i) { glCallList(font->getHandle()+utext[i]); } } -//#endif } glPopMatrix(); glPopAttrib(); diff --git a/source/shared_lib/sources/platform/unix/gl_wrap.cpp b/source/shared_lib/sources/platform/unix/gl_wrap.cpp index 00bb1fd1..54b52168 100644 --- a/source/shared_lib/sources/platform/unix/gl_wrap.cpp +++ b/source/shared_lib/sources/platform/unix/gl_wrap.cpp @@ -35,7 +35,6 @@ namespace Shared { namespace Platform { void createGlFontBitmaps(uint32 &base, const string &type, int size, int width, int charCount, FontMetrics &metrics) { -//#ifndef USE_FTGL Display* display = glXGetCurrentDisplay(); if(display == 0) { throw std::runtime_error("Couldn't create font: display is 0"); @@ -146,7 +145,6 @@ void createGlFontBitmaps(uint32 &base, const string &type, int size, int width, glXUseXFont(fontInfo->fid, 0, charCount, base); XFreeFont(display, fontInfo); -//#endif } void createGlFontOutlines(uint32 &base, const string &type, int width, diff --git a/source/shared_lib/sources/platform/win32/gl_wrap_billy.cpp b/source/shared_lib/sources/platform/win32/gl_wrap_billy.cpp index aac1aad6..8ad5d06c 100644 --- a/source/shared_lib/sources/platform/win32/gl_wrap_billy.cpp +++ b/source/shared_lib/sources/platform/win32/gl_wrap_billy.cpp @@ -27,7 +27,6 @@ using namespace Shared::Util; namespace Shared{ namespace Platform{ -//#ifndef USE_FTGL // ====================================== // Global Fcs // ====================================== @@ -40,13 +39,11 @@ int CALLBACK EnumFontFamExProc(ENUMLOGFONTEX *lpelfe, systemFontList->push_back((char *)lpelfe->elfFullName); return 1; // I want to get all fonts } -//#endif void createGlFontBitmaps(uint32 &base, const string &type, int size, int width, int charCount, FontMetrics &metrics) { //return; -//#ifndef USE_FTGL // -adecw-screen-medium-r-normal--18-180-75-75-m-160-gb2312.1980-1 this is a Chinese font std::string useRealFontName = type; @@ -173,7 +170,6 @@ void createGlFontBitmaps(uint32 &base, const string &type, int size, int width, //} assert(err); -//#endif } void createGlFontOutlines(uint32 &base, const string &type, int width,