- fixed newline font calc for non english languages

This commit is contained in:
Mark Vejvoda
2011-11-18 16:18:36 +00:00
parent f626ebbe45
commit 48da13808f
2 changed files with 33 additions and 6 deletions

View File

@@ -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<unsigned char> 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;
}

View File

@@ -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;
}