bugfixes for proper horizontal rendering of multibyte fonts

This commit is contained in:
Mark Vejvoda 2011-11-18 20:54:41 +00:00
parent 31fafe4528
commit 3ef4692b23
3 changed files with 23 additions and 4 deletions

View File

@ -168,6 +168,7 @@ Font::Font(FontTextHandlerType type) {
if(Font::forceFTGLFonts == false) {
textHandler = NULL;
textHandler = new TextFreetypeGL(type);
//printf("TextFreetypeGL is ON\n");
}
else
@ -178,6 +179,8 @@ Font::Font(FontTextHandlerType type) {
textHandler = NULL;
textHandler = new TextFTGL(type);
//printf("TextFTGL is ON\n");
TextFTGL::faceResolution = Font::faceResolution;
TextFTGL::langHeightText = Font::langHeightText;
}

View File

@ -228,6 +228,8 @@ int TextFTGL::GetFaceSize() {
}
void TextFTGL::Render(const char* str, const int len) {
//printf("Render TextFTGL\n");
/*
FTGL renders the whole string when len == 0
but we don't want any text rendered then.

View File

@ -93,6 +93,8 @@ void TextFreetypeGL::Render(const char* str, const int len) {
return;
}
//printf("Render TextFreetypeGL\n");
Pen pen ;
pen.x = 0; pen.y = 0;
@ -196,11 +198,23 @@ float TextFreetypeGL::Advance(const wchar_t* str, const int len) {
float TextFreetypeGL::Advance(const char* str, const int len) {
float result = 0;
for(unsigned int i = 0; i < strlen(str); ++i) {
TextureGlyph *glyph = texture_font_get_glyph( font, str[i] );
//result += glyph->width;
// for(unsigned int i = 0; i < strlen(str); ++i) {
// TextureGlyph *glyph = texture_font_get_glyph( font, str[i] );
// //result += glyph->width;
// result += glyph->advance_x;
// }
// for multibyte - we can't rely on sizeof(T) == character
FreetypeGLUnicodeStringItr<unsigned char> ustr((const unsigned char *)str);
for(int i = 0; (len < 0 && *ustr) || (len >= 0 && i < len); i++) {
unsigned int prevChar = (i > 0 ? *ustr-1 : 0);
unsigned int thisChar = *ustr++;
unsigned int nextChar = *ustr;
// Get glyph (build it if needed
TextureGlyph *glyph = texture_font_get_glyph( this->font, thisChar );
result += glyph->advance_x;
}
}
return result;
}