- fixed up font alignment and added a way to force ftgl font mode:

--force-ftglfonts
This commit is contained in:
Mark Vejvoda
2011-11-18 19:53:56 +00:00
parent 48da13808f
commit 31fafe4528
6 changed files with 76 additions and 32 deletions

View File

@@ -43,6 +43,7 @@ std::string Font::fontTypeName = "Times New Roman";
bool Font::fontIsMultibyte = false;
bool Font::forceLegacyFonts = false;
bool Font::fontIsRightToLeft = false;
bool Font::forceFTGLFonts = false;
// This value is used to scale the font text rendering
// in 3D render mode
@@ -164,18 +165,23 @@ Font::Font(FontTextHandlerType type) {
if(Font::forceLegacyFonts == false) {
try {
#if defined(USE_FREETYPEGL)
textHandler = NULL;
textHandler = new TextFreetypeGL(type);
if(Font::forceFTGLFonts == false) {
textHandler = NULL;
textHandler = new TextFreetypeGL(type);
}
#else
TextFTGL::faceResolution = Font::faceResolution;
TextFTGL::langHeightText = Font::langHeightText;
textHandler = NULL;
textHandler = new TextFTGL(type);
TextFTGL::faceResolution = Font::faceResolution;
TextFTGL::langHeightText = Font::langHeightText;
else
#endif
{
TextFTGL::faceResolution = Font::faceResolution;
TextFTGL::langHeightText = Font::langHeightText;
textHandler = NULL;
textHandler = new TextFTGL(type);
TextFTGL::faceResolution = Font::faceResolution;
TextFTGL::langHeightText = Font::langHeightText;
}
metrics.setTextHandler(this->textHandler);
}
catch(exception &ex) {

View File

@@ -24,6 +24,7 @@
#include "platform_common.h"
#include "util.h"
#include "font.h"
using namespace std;
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) {
//Font::scaleFontValueCenterHFactor = 30.0;
//Font::scaleFontValue = 1.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
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);
}
// 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 glyph->height = %d glyph->advance_y = %f\n",str,result,glyph->height,glyph->advance_y);
// }
// if(str[0] == '\n') {
// 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) {
//Font::scaleFontValueCenterHFactor = 2.0;
float result = 0;
if(wcslen(str) > 0) {
TextureGlyph *glyph = texture_font_get_glyph( font, str[0] );
result = (float)glyph->height;
//result = (float)glyph->advance_y;
}
result = font->height - font->linegap;
// if(wcslen(str) > 0) {
// TextureGlyph *glyph = texture_font_get_glyph( font, str[0] );
// result = (float)glyph->height;
// //result = (float)glyph->advance_y;
// }
return result;
}