From 97e19785a9cb812f816bfc6061650434ba958868 Mon Sep 17 00:00:00 2001 From: Titus Tscharntke Date: Fri, 1 Jul 2011 00:03:30 +0000 Subject: [PATCH] fonts really fixed now? --- source/glest_game/graphics/renderer.cpp | 20 +++---------------- source/shared_lib/sources/graphics/font.cpp | 2 +- .../sources/graphics/gl/font_textFTGL.cpp | 16 +++++++++------ .../sources/graphics/gl/text_renderer_gl.cpp | 3 --- 4 files changed, 14 insertions(+), 27 deletions(-) diff --git a/source/glest_game/graphics/renderer.cpp b/source/glest_game/graphics/renderer.cpp index 20e94406..6308929a 100644 --- a/source/glest_game/graphics/renderer.cpp +++ b/source/glest_game/graphics/renderer.cpp @@ -1444,26 +1444,12 @@ Vec2f Renderer::getCentered3DPos(const string &text, Font3D *font, Vec2f &pos, i if(lineWidth < w) { pos.x += ((w / 2.f) - (lineWidth / 2.f)); } - + const Metrics &metrics= Metrics::getInstance(); float lineHeight = (font->getTextHandler()->LineHeight(text.c_str()) * Font::scaleFontValue); - lineHeight= lineHeight / (2.f + 0.2f * FontMetrics::DEFAULT_Y_OFFSET_FACTOR); + lineHeight=metrics.toVirtualY(lineHeight); + //lineHeight= lineHeight / (2.f + 0.2f * FontMetrics::DEFAULT_Y_OFFSET_FACTOR); pos.y += (h / 2.f) - (lineHeight / 2.f); -// //h /= 2.f; -// float lineHeight = (font->getTextHandler()->LineHeight(text.c_str()) * Font::scaleFontValue); -// if(lineHeight < h) { -// //pos.y += ((float)h / 2.f); -// //pos.y -= ((float(h) / 2.f) - (lineHeight / 2.f)); -// pos.y += (lineHeight / 2.f) + FontMetrics::DEFAULT_Y_OFFSET_FACTOR; -// //pos.y -= h; -// //printf("Center text [%s] h = %d, lineHeight = %f, pos.y = %f\n",text.c_str(),h,lineHeight,pos.y); -// -// //printf("Center text [%s] h = %d, lineHeight = %f, pos.y = %f\n",text.c_str(),h,lineHeight,pos.y); -// } -// else { -// pos.y += ((float)h / 2.f) - FontMetrics::DEFAULT_Y_OFFSET_FACTOR; -// } - return pos; } diff --git a/source/shared_lib/sources/graphics/font.cpp b/source/shared_lib/sources/graphics/font.cpp index 7799c1bc..3d9ef9c0 100644 --- a/source/shared_lib/sources/graphics/font.cpp +++ b/source/shared_lib/sources/graphics/font.cpp @@ -38,7 +38,7 @@ bool Font::fontIsMultibyte = false; bool Font::forceLegacyFonts = false; float FontMetrics::DEFAULT_Y_OFFSET_FACTOR = 2.0f; bool Font::fontIsRightToLeft = false; -float Font::scaleFontValue = 0.75; +float Font::scaleFontValue = 1.0; int Font::baseSize = 0; //int Font::scaleFontYOffset = 0; // diff --git a/source/shared_lib/sources/graphics/gl/font_textFTGL.cpp b/source/shared_lib/sources/graphics/gl/font_textFTGL.cpp index 2bc113a0..b232b9f7 100644 --- a/source/shared_lib/sources/graphics/gl/font_textFTGL.cpp +++ b/source/shared_lib/sources/graphics/gl/font_textFTGL.cpp @@ -225,13 +225,17 @@ float TextFTGL::LineHeight(const char* str, const int len) { //FTBBox box = ftFont->BBox(str); //printf("String [%s] lineheight = %f upper_y = %f lower_y = %f\n",str,ftFont->LineHeight(),box.Upper().Y(),box.Lower().Y()); - //return ftFont->Ascender() + ftFont->Descender(); - return ftFont->LineHeight(); - //FTBBox box = ftFont->BBox(str); - //float result = box.Upper().Y()- box.Lower().Y(); - //printf("For str [%s] LineHeight = %f, result = %f\n",str, ftFont->LineHeight(),result); - //return result; + //printf("ftFont->Ascender():%f ftFont->Descender()*-1 = %f ftFont->LineHeight() = %f\n",ftFont->Ascender(),ftFont->Descender()*-1 , ftFont->LineHeight()); + //return ftFont->Ascender() + ftFont->Descender()*-1 - ftFont->LineHeight(); + //return ftFont->LineHeight(); + + FTBBox box = ftFont->BBox("yW"); + float result = box.Upper().Y()- box.Lower().Y(); + //printf("ftFont->BBox(''yW'')%f\n",result); + return result; +// printf("For str [%s] LineHeight = %f, result = %f\n",str, ftFont->LineHeight(),result); +// return result; //float urx = box.Upper().X(); //float llx = box.Lower().X(); 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 da92a39a..51f9e263 100644 --- a/source/shared_lib/sources/graphics/gl/text_renderer_gl.cpp +++ b/source/shared_lib/sources/graphics/gl/text_renderer_gl.cpp @@ -592,9 +592,6 @@ void TextRenderer3DGl::internalRender(const string &text, float x, float y, boo { line++; //assertGl(); - //printf("NEWLINE before [%s]\n",parts[i].c_str()); - parts[i] = parts[i].erase(0); - //printf("NEWLINE after [%s]\n",parts[i].c_str()); float yLineValue = (font->getTextHandler()->LineHeight(parts[i].c_str()) * Font::scaleFontValue); //assertGl(); translatePos= Vec3f(translatePos.x, translatePos.y - yLineValue, translatePos.z);