From 31fafe45287e5c6fc78b1d60e0905707d71fb51a Mon Sep 17 00:00:00 2001 From: Mark Vejvoda Date: Fri, 18 Nov 2011 19:53:56 +0000 Subject: [PATCH] - fixed up font alignment and added a way to force ftgl font mode: --force-ftglfonts --- source/glest_game/graphics/renderer.cpp | 19 +++++-- source/glest_game/main/main.cpp | 9 ++++ source/shared_lib/include/graphics/font.h | 1 + .../include/platform/sdl/platform_main.h | 3 ++ source/shared_lib/sources/graphics/font.cpp | 26 ++++++---- .../graphics/gl/font_text_freetypegl.cpp | 50 ++++++++++++------- 6 files changed, 76 insertions(+), 32 deletions(-) diff --git a/source/glest_game/graphics/renderer.cpp b/source/glest_game/graphics/renderer.cpp index 164b7ea0a..c62e2598a 100644 --- a/source/glest_game/graphics/renderer.cpp +++ b/source/glest_game/graphics/renderer.cpp @@ -1891,15 +1891,26 @@ Vec2f Renderer::getCentered3DPos(const string &text, Font3D *font, Vec2f &pos, i if(lineHeight < h) { //printf("line %d, lineHeight [%f] h [%d] text [%s]\n",__LINE__,lineHeight,h,text.c_str()); - //int realHeight = lineHeight + (h - lineHeight); - // First go to top of bounding box - pos.y += (h - lineHeight); + if(Font::forceFTGLFonts == true) { + // First go to top of bounding box + pos.y += (h - lineHeight); + pos.y -= ((h - lineHeight) / Font::scaleFontValueCenterHFactor); + } + else { + pos.y += (float)(((float)h) / 2.0); + float heightGap = (float)(((float)h - lineHeight) / 2.0); +#ifdef USE_STREFLOP + pos.y -= streflop::ceil(heightGap); +#else + pos.y -= ceil(heightGap); +#endif - pos.y -= ((h - lineHeight) / Font::scaleFontValueCenterHFactor); + //printf("h = %d lineHeight = %f heightGap = %f\n",h,lineHeight,heightGap); // Now calculate till we get text to middle //pos.y -= (realHeight / 2); //pos.y += (lineHeight / 2); + } } else if(lineHeight > h) { //printf("line %d, lineHeight [%f] h [%d] text [%s]\n",__LINE__,lineHeight,h,text.c_str()); diff --git a/source/glest_game/main/main.cpp b/source/glest_game/main/main.cpp index 7c3622bba..63a4ce5c8 100644 --- a/source/glest_game/main/main.cpp +++ b/source/glest_game/main/main.cpp @@ -2605,6 +2605,15 @@ int glestMain(int argc, char** argv) { TextureGl::setEnableATIHacks(enableATIHacks); } + if(config.getBool("ForceFTGLFonts","false") == true || hasCommandArgument(argc, argv,GAME_ARGS[GAME_ARG_FORCE_FTGLFONTS]) == true) { + Font::forceFTGLFonts = true; + //if(SystemFlags::VERBOSE_MODE_ENABLED) printf("**WARNING** Forcing Legacy Fonts Enabled\n"); + printf("**WARNING** Forcing use of FTGL Fonts\n"); + } + else { + Renderer::renderText3DEnabled = config.getBool("Enable3DFontRendering",intToStr(Renderer::renderText3DEnabled).c_str()); + } + if(config.getBool("EnableLegacyFonts","false") == true || hasCommandArgument(argc, argv,GAME_ARGS[GAME_ARG_ENABLE_LEGACYFONTS]) == true) { Font::forceLegacyFonts = true; Renderer::renderText3DEnabled = false; diff --git a/source/shared_lib/include/graphics/font.h b/source/shared_lib/include/graphics/font.h index 0f914529b..467544e1f 100644 --- a/source/shared_lib/include/graphics/font.h +++ b/source/shared_lib/include/graphics/font.h @@ -64,6 +64,7 @@ public: static std::string fontTypeName; static bool fontIsMultibyte; static bool forceLegacyFonts; + static bool forceFTGLFonts; static bool fontIsRightToLeft; static float scaleFontValue; static float scaleFontValueCenterHFactor; diff --git a/source/shared_lib/include/platform/sdl/platform_main.h b/source/shared_lib/include/platform/sdl/platform_main.h index fb85514f2..01f2b78f5 100644 --- a/source/shared_lib/include/platform/sdl/platform_main.h +++ b/source/shared_lib/include/platform/sdl/platform_main.h @@ -55,6 +55,7 @@ const char *GAME_ARGS[] = { "--disable-vbo", "--disable-sound", "--enable-legacyfonts", + "--force-ftglfonts", // "--use-video-settings", "--resolution", @@ -103,6 +104,7 @@ enum GAME_ARG_TYPE { GAME_ARG_DISABLE_VBO, GAME_ARG_DISABLE_SOUND, GAME_ARG_ENABLE_LEGACYFONTS, + GAME_ARG_FORCE_FTGLFONTS, //GAME_ARG_USE_VIDEO_SETTINGS, GAME_ARG_USE_RESOLUTION, GAME_ARG_USE_COLORBITS, @@ -215,6 +217,7 @@ void printParameterHelp(const char *argv0, bool foundInvalidArgs) { printf("\n%s\t\t\tenables using the legacy font system.",GAME_ARGS[GAME_ARG_ENABLE_LEGACYFONTS]); + printf("\n%s\t\t\tforces use of the FTGL font system.",GAME_ARGS[GAME_ARG_FORCE_FTGLFONTS]); // printf("\n%s=x\t\t\toverride video settings.",GAME_ARGS[GAME_ARG_USE_VIDEO_SETTINGS]); // printf("\n \t\tWhere x is a string with the following format:"); diff --git a/source/shared_lib/sources/graphics/font.cpp b/source/shared_lib/sources/graphics/font.cpp index f31891998..b913fda2c 100644 --- a/source/shared_lib/sources/graphics/font.cpp +++ b/source/shared_lib/sources/graphics/font.cpp @@ -43,6 +43,7 @@ std::string Font::fontTypeName = "Times New Roman"; bool Font::fontIsMultibyte = false; bool Font::forceLegacyFonts = false; bool Font::fontIsRightToLeft = false; +bool Font::forceFTGLFonts = false; // This value is used to scale the font text rendering // in 3D render mode @@ -164,18 +165,23 @@ Font::Font(FontTextHandlerType type) { if(Font::forceLegacyFonts == false) { try { #if defined(USE_FREETYPEGL) - textHandler = NULL; - textHandler = new TextFreetypeGL(type); + if(Font::forceFTGLFonts == false) { + textHandler = NULL; + textHandler = new TextFreetypeGL(type); + } -#else - TextFTGL::faceResolution = Font::faceResolution; - TextFTGL::langHeightText = Font::langHeightText; - - textHandler = NULL; - textHandler = new TextFTGL(type); - TextFTGL::faceResolution = Font::faceResolution; - TextFTGL::langHeightText = Font::langHeightText; + else #endif + { + TextFTGL::faceResolution = Font::faceResolution; + TextFTGL::langHeightText = Font::langHeightText; + + textHandler = NULL; + textHandler = new TextFTGL(type); + TextFTGL::faceResolution = Font::faceResolution; + TextFTGL::langHeightText = Font::langHeightText; + } + metrics.setTextHandler(this->textHandler); } catch(exception &ex) { diff --git a/source/shared_lib/sources/graphics/gl/font_text_freetypegl.cpp b/source/shared_lib/sources/graphics/gl/font_text_freetypegl.cpp index 27a18e53c..35d0692ac 100644 --- a/source/shared_lib/sources/graphics/gl/font_text_freetypegl.cpp +++ b/source/shared_lib/sources/graphics/gl/font_text_freetypegl.cpp @@ -24,6 +24,7 @@ #include "platform_common.h" #include "util.h" +#include "font.h" using namespace std; using namespace Shared::Util; @@ -204,22 +205,30 @@ float TextFreetypeGL::Advance(const char* str, const int len) { } float TextFreetypeGL::LineHeight(const char* str, const int len) { + //Font::scaleFontValueCenterHFactor = 30.0; + //Font::scaleFontValue = 1.0; + float result = 0; + result = font->height - font->linegap; + //printf("#2 LineHeight [%s] height = %f linegap = %f ascender = %f descender = %f\n",str,font->height,font->linegap,font->ascender,font->descender); + + //result += (result * Font::scaleFontValue); + // for multibyte - we can't rely on sizeof(T) == character - FreetypeGLUnicodeStringItr ustr((const unsigned char *)str); - - int i = 0; - if((len < 0 && *ustr) || (len >= 0 && i < len)) { - unsigned int prevChar = (i > 0 ? *ustr-1 : 0); - unsigned int thisChar = *ustr++; - unsigned int nextChar = *ustr; - - TextureGlyph *glyph = texture_font_get_glyph( font, thisChar ); - result = (float)glyph->height; - - //printf("#1 LineHeight [%s] result = %f\n",str,result); - } +// FreetypeGLUnicodeStringItr ustr((const unsigned char *)str); +// +// int i = 0; +// if((len < 0 && *ustr) || (len >= 0 && i < len)) { +// unsigned int prevChar = (i > 0 ? *ustr-1 : 0); +// unsigned int thisChar = *ustr++; +// unsigned int nextChar = *ustr; +// +// TextureGlyph *glyph = texture_font_get_glyph( font, thisChar ); +// //result = (float)glyph->height; +// +// printf("#1 LineHeight [%s] result = %f glyph->height = %d glyph->advance_y = %f\n",str,result,glyph->height,glyph->advance_y); +// } // if(str[0] == '\n') { // TextureGlyph *glyph2 = texture_font_get_glyph( font, str[0] ); @@ -232,12 +241,17 @@ float TextFreetypeGL::LineHeight(const char* str, const int len) { } float TextFreetypeGL::LineHeight(const wchar_t* str, const int len) { + //Font::scaleFontValueCenterHFactor = 2.0; + float result = 0; - if(wcslen(str) > 0) { - TextureGlyph *glyph = texture_font_get_glyph( font, str[0] ); - result = (float)glyph->height; - //result = (float)glyph->advance_y; - } + + result = font->height - font->linegap; + +// if(wcslen(str) > 0) { +// TextureGlyph *glyph = texture_font_get_glyph( font, str[0] ); +// result = (float)glyph->height; +// //result = (float)glyph->advance_y; +// } return result; }