mirror of
https://github.com/glest/glest-source.git
synced 2025-08-11 02:43:57 +02:00
- fixed up font alignment and added a way to force ftgl font mode:
--force-ftglfonts
This commit is contained in:
@@ -1891,16 +1891,27 @@ Vec2f Renderer::getCentered3DPos(const string &text, Font3D *font, Vec2f &pos, i
|
|||||||
if(lineHeight < h) {
|
if(lineHeight < h) {
|
||||||
//printf("line %d, lineHeight [%f] h [%d] text [%s]\n",__LINE__,lineHeight,h,text.c_str());
|
//printf("line %d, lineHeight [%f] h [%d] text [%s]\n",__LINE__,lineHeight,h,text.c_str());
|
||||||
|
|
||||||
//int realHeight = lineHeight + (h - lineHeight);
|
if(Font::forceFTGLFonts == true) {
|
||||||
// First go to top of bounding box
|
// First go to top of bounding box
|
||||||
pos.y += (h - lineHeight);
|
pos.y += (h - lineHeight);
|
||||||
|
|
||||||
pos.y -= ((h - lineHeight) / Font::scaleFontValueCenterHFactor);
|
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
|
||||||
|
|
||||||
|
//printf("h = %d lineHeight = %f heightGap = %f\n",h,lineHeight,heightGap);
|
||||||
|
|
||||||
// Now calculate till we get text to middle
|
// Now calculate till we get text to middle
|
||||||
//pos.y -= (realHeight / 2);
|
//pos.y -= (realHeight / 2);
|
||||||
//pos.y += (lineHeight / 2);
|
//pos.y += (lineHeight / 2);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
else if(lineHeight > h) {
|
else if(lineHeight > h) {
|
||||||
//printf("line %d, lineHeight [%f] h [%d] text [%s]\n",__LINE__,lineHeight,h,text.c_str());
|
//printf("line %d, lineHeight [%f] h [%d] text [%s]\n",__LINE__,lineHeight,h,text.c_str());
|
||||||
|
|
||||||
|
@@ -2605,6 +2605,15 @@ int glestMain(int argc, char** argv) {
|
|||||||
TextureGl::setEnableATIHacks(enableATIHacks);
|
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) {
|
if(config.getBool("EnableLegacyFonts","false") == true || hasCommandArgument(argc, argv,GAME_ARGS[GAME_ARG_ENABLE_LEGACYFONTS]) == true) {
|
||||||
Font::forceLegacyFonts = true;
|
Font::forceLegacyFonts = true;
|
||||||
Renderer::renderText3DEnabled = false;
|
Renderer::renderText3DEnabled = false;
|
||||||
|
@@ -64,6 +64,7 @@ public:
|
|||||||
static std::string fontTypeName;
|
static std::string fontTypeName;
|
||||||
static bool fontIsMultibyte;
|
static bool fontIsMultibyte;
|
||||||
static bool forceLegacyFonts;
|
static bool forceLegacyFonts;
|
||||||
|
static bool forceFTGLFonts;
|
||||||
static bool fontIsRightToLeft;
|
static bool fontIsRightToLeft;
|
||||||
static float scaleFontValue;
|
static float scaleFontValue;
|
||||||
static float scaleFontValueCenterHFactor;
|
static float scaleFontValueCenterHFactor;
|
||||||
|
@@ -55,6 +55,7 @@ const char *GAME_ARGS[] = {
|
|||||||
"--disable-vbo",
|
"--disable-vbo",
|
||||||
"--disable-sound",
|
"--disable-sound",
|
||||||
"--enable-legacyfonts",
|
"--enable-legacyfonts",
|
||||||
|
"--force-ftglfonts",
|
||||||
// "--use-video-settings",
|
// "--use-video-settings",
|
||||||
|
|
||||||
"--resolution",
|
"--resolution",
|
||||||
@@ -103,6 +104,7 @@ enum GAME_ARG_TYPE {
|
|||||||
GAME_ARG_DISABLE_VBO,
|
GAME_ARG_DISABLE_VBO,
|
||||||
GAME_ARG_DISABLE_SOUND,
|
GAME_ARG_DISABLE_SOUND,
|
||||||
GAME_ARG_ENABLE_LEGACYFONTS,
|
GAME_ARG_ENABLE_LEGACYFONTS,
|
||||||
|
GAME_ARG_FORCE_FTGLFONTS,
|
||||||
//GAME_ARG_USE_VIDEO_SETTINGS,
|
//GAME_ARG_USE_VIDEO_SETTINGS,
|
||||||
GAME_ARG_USE_RESOLUTION,
|
GAME_ARG_USE_RESOLUTION,
|
||||||
GAME_ARG_USE_COLORBITS,
|
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\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%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:");
|
// printf("\n \t\tWhere x is a string with the following format:");
|
||||||
|
@@ -43,6 +43,7 @@ std::string Font::fontTypeName = "Times New Roman";
|
|||||||
bool Font::fontIsMultibyte = false;
|
bool Font::fontIsMultibyte = false;
|
||||||
bool Font::forceLegacyFonts = false;
|
bool Font::forceLegacyFonts = false;
|
||||||
bool Font::fontIsRightToLeft = false;
|
bool Font::fontIsRightToLeft = false;
|
||||||
|
bool Font::forceFTGLFonts = false;
|
||||||
|
|
||||||
// This value is used to scale the font text rendering
|
// This value is used to scale the font text rendering
|
||||||
// in 3D render mode
|
// in 3D render mode
|
||||||
@@ -164,10 +165,14 @@ Font::Font(FontTextHandlerType type) {
|
|||||||
if(Font::forceLegacyFonts == false) {
|
if(Font::forceLegacyFonts == false) {
|
||||||
try {
|
try {
|
||||||
#if defined(USE_FREETYPEGL)
|
#if defined(USE_FREETYPEGL)
|
||||||
|
if(Font::forceFTGLFonts == false) {
|
||||||
textHandler = NULL;
|
textHandler = NULL;
|
||||||
textHandler = new TextFreetypeGL(type);
|
textHandler = new TextFreetypeGL(type);
|
||||||
|
}
|
||||||
|
|
||||||
#else
|
else
|
||||||
|
#endif
|
||||||
|
{
|
||||||
TextFTGL::faceResolution = Font::faceResolution;
|
TextFTGL::faceResolution = Font::faceResolution;
|
||||||
TextFTGL::langHeightText = Font::langHeightText;
|
TextFTGL::langHeightText = Font::langHeightText;
|
||||||
|
|
||||||
@@ -175,7 +180,8 @@ Font::Font(FontTextHandlerType type) {
|
|||||||
textHandler = new TextFTGL(type);
|
textHandler = new TextFTGL(type);
|
||||||
TextFTGL::faceResolution = Font::faceResolution;
|
TextFTGL::faceResolution = Font::faceResolution;
|
||||||
TextFTGL::langHeightText = Font::langHeightText;
|
TextFTGL::langHeightText = Font::langHeightText;
|
||||||
#endif
|
}
|
||||||
|
|
||||||
metrics.setTextHandler(this->textHandler);
|
metrics.setTextHandler(this->textHandler);
|
||||||
}
|
}
|
||||||
catch(exception &ex) {
|
catch(exception &ex) {
|
||||||
|
@@ -24,6 +24,7 @@
|
|||||||
|
|
||||||
#include "platform_common.h"
|
#include "platform_common.h"
|
||||||
#include "util.h"
|
#include "util.h"
|
||||||
|
#include "font.h"
|
||||||
|
|
||||||
using namespace std;
|
using namespace std;
|
||||||
using namespace Shared::Util;
|
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) {
|
float TextFreetypeGL::LineHeight(const char* str, const int len) {
|
||||||
|
//Font::scaleFontValueCenterHFactor = 30.0;
|
||||||
|
//Font::scaleFontValue = 1.0;
|
||||||
|
|
||||||
float result = 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
|
// for multibyte - we can't rely on sizeof(T) == character
|
||||||
FreetypeGLUnicodeStringItr<unsigned char> ustr((const unsigned char *)str);
|
// FreetypeGLUnicodeStringItr<unsigned char> ustr((const unsigned char *)str);
|
||||||
|
//
|
||||||
int i = 0;
|
// int i = 0;
|
||||||
if((len < 0 && *ustr) || (len >= 0 && i < len)) {
|
// if((len < 0 && *ustr) || (len >= 0 && i < len)) {
|
||||||
unsigned int prevChar = (i > 0 ? *ustr-1 : 0);
|
// unsigned int prevChar = (i > 0 ? *ustr-1 : 0);
|
||||||
unsigned int thisChar = *ustr++;
|
// unsigned int thisChar = *ustr++;
|
||||||
unsigned int nextChar = *ustr;
|
// unsigned int nextChar = *ustr;
|
||||||
|
//
|
||||||
TextureGlyph *glyph = texture_font_get_glyph( font, thisChar );
|
// TextureGlyph *glyph = texture_font_get_glyph( font, thisChar );
|
||||||
result = (float)glyph->height;
|
// //result = (float)glyph->height;
|
||||||
|
//
|
||||||
//printf("#1 LineHeight [%s] result = %f\n",str,result);
|
// 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') {
|
// if(str[0] == '\n') {
|
||||||
// TextureGlyph *glyph2 = texture_font_get_glyph( font, str[0] );
|
// 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) {
|
float TextFreetypeGL::LineHeight(const wchar_t* str, const int len) {
|
||||||
|
//Font::scaleFontValueCenterHFactor = 2.0;
|
||||||
|
|
||||||
float result = 0;
|
float result = 0;
|
||||||
if(wcslen(str) > 0) {
|
|
||||||
TextureGlyph *glyph = texture_font_get_glyph( font, str[0] );
|
result = font->height - font->linegap;
|
||||||
result = (float)glyph->height;
|
|
||||||
//result = (float)glyph->advance_y;
|
// if(wcslen(str) > 0) {
|
||||||
}
|
// TextureGlyph *glyph = texture_font_get_glyph( font, str[0] );
|
||||||
|
// result = (float)glyph->height;
|
||||||
|
// //result = (float)glyph->advance_y;
|
||||||
|
// }
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user