From 48da13808fbfdb2fe15e35163ace7b9074464f2d Mon Sep 17 00:00:00 2001 From: Mark Vejvoda Date: Fri, 18 Nov 2011 16:18:36 +0000 Subject: [PATCH] - fixed newline font calc for non english languages --- .../graphics/gl/font_text_freetypegl.cpp | 30 ++++++++++++++++--- .../sources/graphics/gl/text_renderer_gl.cpp | 9 ++++-- 2 files changed, 33 insertions(+), 6 deletions(-) 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 8006fdf6e..27a18e53c 100644 --- a/source/shared_lib/sources/graphics/gl/font_text_freetypegl.cpp +++ b/source/shared_lib/sources/graphics/gl/font_text_freetypegl.cpp @@ -186,7 +186,8 @@ float TextFreetypeGL::Advance(const wchar_t* str, const int len) { for(unsigned int i = 0; i < wcslen(str); ++i) { TextureGlyph *glyph = texture_font_get_glyph( font, str[i] ); - result += glyph->width; + //result += glyph->width; + result += glyph->advance_x; } return result; } @@ -196,17 +197,37 @@ float TextFreetypeGL::Advance(const char* str, const int len) { for(unsigned int i = 0; i < strlen(str); ++i) { TextureGlyph *glyph = texture_font_get_glyph( font, str[i] ); - result += glyph->width; + //result += glyph->width; + result += glyph->advance_x; } return result; } float TextFreetypeGL::LineHeight(const char* str, const int len) { float result = 0; - if(strlen(str) > 0) { - TextureGlyph *glyph = texture_font_get_glyph( font, str[0] ); + + // 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); } + +// if(str[0] == '\n') { +// TextureGlyph *glyph2 = texture_font_get_glyph( font, str[0] ); +// float result2 = (float)glyph2->height; +// +// printf("#2 LineHeight [%s] result = %f result2 = %f\n",str,result,result2); +// } + return result; } @@ -215,6 +236,7 @@ float TextFreetypeGL::LineHeight(const wchar_t* str, const int len) { if(wcslen(str) > 0) { TextureGlyph *glyph = texture_font_get_glyph( font, str[0] ); result = (float)glyph->height; + //result = (float)glyph->advance_y; } return result; } 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 08945bbe8..0edd6babd 100644 --- a/source/shared_lib/sources/graphics/gl/text_renderer_gl.cpp +++ b/source/shared_lib/sources/graphics/gl/text_renderer_gl.cpp @@ -557,7 +557,7 @@ void TextRenderer3DGl::internalRender(const string &text, float x, float y, boo float scaleZ = 1.0; glScalef(scaleX, scaleY, scaleZ); - if(text.find("\n") == renderText.npos && renderText.find("\t") == renderText.npos) { + if(renderText.find("\n") == renderText.npos && renderText.find("\t") == renderText.npos) { //assertGl(); font->getTextHandler()->Render(renderText.c_str()); specialFTGLErrorCheckWorkaround(renderText); @@ -604,8 +604,13 @@ void TextRenderer3DGl::internalRender(const string &text, float x, float y, boo { line++; //assertGl(); - float yLineValue = (font->getTextHandler()->LineHeight(parts[i].c_str()) * Font::scaleFontValue); + //float yLineValue = (font->getTextHandler()->LineHeight(parts[i].c_str()) * Font::scaleFontValue); + //float yLineValue = (font->getTextHandler()->LineHeight("W") * Font::scaleFontValue); + float yLineValue = font->getTextHandler()->LineHeight("W"); //assertGl(); + + //printf("Trying to render newline [%s] i = %d yLineValue = %f font->getTextHandler()->LineHeight(parts[i].c_str()) = %f\n",renderText.c_str(),i,yLineValue,font->getTextHandler()->LineHeight(parts[i].c_str())); + translatePos= Vec3f(translatePos.x, translatePos.y - yLineValue, translatePos.z); needsRecursiveRender = true; }