From 9fddd2bdec4f879a44304118e2f44929c2755483 Mon Sep 17 00:00:00 2001 From: Rob Haarsma Date: Wed, 19 Jan 2005 13:53:43 +0000 Subject: Added experimental option to use GL textured interface fonts. Set preferred method in userprefs->language & font. Kinda requested by Kaito, i'm sure he regrets after seeing my code changes. This commit includes a patch provided by Jacques Baurain, which seemed nescessary to handle font sizing properly. Thank you ! --- source/blender/ftfont/FTF_Api.h | 4 + source/blender/ftfont/FTF_Settings.h | 2 + source/blender/ftfont/intern/FTF_Api.cpp | 19 +++- source/blender/ftfont/intern/FTF_TTFont.cpp | 157 +++++++++++++++++++++------- source/blender/ftfont/intern/FTF_TTFont.h | 12 +++ 5 files changed, 151 insertions(+), 43 deletions(-) (limited to 'source/blender/ftfont') diff --git a/source/blender/ftfont/FTF_Api.h b/source/blender/ftfont/FTF_Api.h index 8f603d73ae1..15fa55c905d 100644 --- a/source/blender/ftfont/FTF_Api.h +++ b/source/blender/ftfont/FTF_Api.h @@ -148,6 +148,10 @@ FTF_EXPORT void FTF_SetLanguage(char* str); */ FTF_EXPORT void FTF_SetEncoding(char* str); +FTF_EXPORT void FTF_SetPosition(float x, float y); +FTF_EXPORT void FTF_SetMode(int mode); +FTF_EXPORT void FTF_SetScale(float fsize); + FTF_EXPORT void FTF_End(void); #ifdef __cplusplus diff --git a/source/blender/ftfont/FTF_Settings.h b/source/blender/ftfont/FTF_Settings.h index d9263baf5a2..dc325c1de41 100644 --- a/source/blender/ftfont/FTF_Settings.h +++ b/source/blender/ftfont/FTF_Settings.h @@ -43,5 +43,7 @@ #define FTF_INPUT_SYSTEM_ENCODING FTF_BIT(1) #define FTF_USE_GETTEXT FTF_BIT(2) #define FTF_INPUT_UTF8 FTF_BIT(3) +#define FTF_PIXMAPFONT 0 +#define FTF_TEXTUREFONT 1 #endif /* __FTF_SETTINGS_H */ diff --git a/source/blender/ftfont/intern/FTF_Api.cpp b/source/blender/ftfont/intern/FTF_Api.cpp index 46638d9f4eb..036e13a7e6e 100644 --- a/source/blender/ftfont/intern/FTF_Api.cpp +++ b/source/blender/ftfont/intern/FTF_Api.cpp @@ -155,11 +155,22 @@ FTF_EXPORT void FTF_SetLanguage(char* str) _FTF_GetFont()->SetLanguage(str); } -/** - * added by phase - * - */ FTF_EXPORT void FTF_SetEncoding(char* str) { _FTF_GetFont()->SetEncoding(str); } + +FTF_EXPORT void FTF_SetPosition(float x, float y) +{ + _FTF_GetFont()->SetPosition(x, y); +} + +FTF_EXPORT void FTF_SetMode(int mode) +{ + _FTF_GetFont()->SetMode(mode); +} + +FTF_EXPORT void FTF_SetScale(float fsize) +{ + _FTF_GetFont()->SetScale(fsize); +} diff --git a/source/blender/ftfont/intern/FTF_TTFont.cpp b/source/blender/ftfont/intern/FTF_TTFont.cpp index ff599e9444c..d25c60ea402 100644 --- a/source/blender/ftfont/intern/FTF_TTFont.cpp +++ b/source/blender/ftfont/intern/FTF_TTFont.cpp @@ -51,6 +51,7 @@ #define FTF_MAX_STR_SIZE 512 + int utf8towchar(wchar_t *w, char *c) { int len=0; @@ -102,6 +103,8 @@ FTF_TTFont::FTF_TTFont(void) font=NULL; fontm= fonts= fontl= NULL; font_size=FONT_SIZE_DEFAULT; + mode = FTF_PIXMAPFONT; + fsize = 1.0; strcpy(encoding_name, SYSTEM_ENCODING_DEFAULT); //set messagepath directory @@ -153,10 +156,13 @@ FTF_TTFont::~FTF_TTFont(void) void FTF_TTFont::SetFontSize(char size) { - if(size=='s') font=fonts; - else if(size=='l') font=fontl; - else font=fontm; - + if(mode == FTF_PIXMAPFONT) { + if(size=='s') font=fonts; + else if(size=='l') font=fontl; + else font=fontm; + } else if(mode == FTF_TEXTUREFONT) { + font=fontl; + } } int FTF_TTFont::SetFont(const unsigned char* str, int datasize, int fontsize) @@ -171,34 +177,60 @@ int FTF_TTFont::SetFont(const unsigned char* str, int datasize, int fontsize) fontm= NULL; fontl= NULL; - if(datasize) font = new FTGLPixmapFont(str, datasize); - else font = new FTGLPixmapFont( (char *)str); + if(mode == FTF_PIXMAPFONT) { - err = font->Error(); + if(datasize) font = new FTGLPixmapFont(str, datasize); + else font = new FTGLPixmapFont( (char *)str); - if(err) { - printf("Failed to open font %s\n", str); - return 0; - } else { - - fontm= font; + err = font->Error(); - if(datasize) fonts = new FTGLPixmapFont(str, datasize); - else fonts = new FTGLPixmapFont((char *)str); - if(datasize) fontl = new FTGLPixmapFont(str, datasize); - else fontl = new FTGLPixmapFont((char *)str); - - success = fonts->FaceSize(fontsize-2<8?8:fontsize-2); - success = fontm->FaceSize(fontsize-1<8?8:fontsize-1); - success = fontl->FaceSize(fontsize); - if(!success) return 0; + if(err) { + printf("Failed to open font %s\n", str); + return 0; + } else { + + fontm= font; + + if(datasize) fonts = new FTGLPixmapFont(str, datasize); + else fonts = new FTGLPixmapFont((char *)str); + if(datasize) fontl = new FTGLPixmapFont(str, datasize); + else fontl = new FTGLPixmapFont((char *)str); + + success = fonts->FaceSize(fontsize-2<8?8:fontsize-2); + success = fontm->FaceSize(fontsize-1<8?8:fontsize-1); + success = fontl->FaceSize(fontsize); + if(!success) return 0; + + success = fonts->CharMap(ft_encoding_unicode); + success = fontm->CharMap(ft_encoding_unicode); + success = fontl->CharMap(ft_encoding_unicode); + if(!success) return 0; + + return 1; + } + + } else if(mode == FTF_TEXTUREFONT) { + + if(datasize) font = new FTGLTextureFont(str, datasize); + else font = new FTGLTextureFont( (char *)str); - success = fonts->CharMap(ft_encoding_unicode); - success = fontm->CharMap(ft_encoding_unicode); - success = fontl->CharMap(ft_encoding_unicode); - if(!success) return 0; + err = font->Error(); - return 1; + if(err) { + printf("Failed to open font %s\n", str); + return 0; + } else { + + fontl= font; + + success = fontl->FaceSize(fontsize); + if(!success) return 0; + + success = fontl->CharMap(ft_encoding_unicode); + if(!success) return 0; + + return 1; + } } } @@ -242,9 +274,13 @@ void FTF_TTFont::SetEncoding(char* str) void FTF_TTFont::SetSize(int size) { - fonts->FaceSize(size-2<8?8:size-2); - fontm->FaceSize(size-1<8?8:size-1); - fontl->FaceSize(size); + if(mode == FTF_PIXMAPFONT) { + fonts->FaceSize(size-2<8?8:size-2); + fontm->FaceSize(size-1<8?8:size-1); + fontl->FaceSize(size); + } else if(mode == FTF_TEXTUREFONT) { + fontl->FaceSize(size); + } font_size = size; } @@ -284,15 +320,33 @@ float FTF_TTFont::DrawString(char* str, unsigned int flag) glGetFloatv(GL_CURRENT_COLOR, color); - glPixelTransferf(GL_RED_SCALE, color[0]); - glPixelTransferf(GL_GREEN_SCALE, color[1]); - glPixelTransferf(GL_BLUE_SCALE, color[2]); - - font->Render(wstr); + if(mode == FTF_PIXMAPFONT) { + + glPixelTransferf(GL_RED_SCALE, color[0]); + glPixelTransferf(GL_GREEN_SCALE, color[1]); + glPixelTransferf(GL_BLUE_SCALE, color[2]); + + font->Render(wstr); + + glPixelTransferf(GL_RED_SCALE, 1.0); + glPixelTransferf(GL_GREEN_SCALE, 1.0); + glPixelTransferf(GL_BLUE_SCALE, 1.0); + + } else if(mode == FTF_TEXTUREFONT) { + + glEnable(GL_BLEND); + glEnable(GL_TEXTURE_2D); + + glPushMatrix(); + glTranslatef(pen_x, pen_y, 0.0); + glScalef(fsize, fsize, 1.0); + + font->Render(wstr); + glPopMatrix(); - glPixelTransferf(GL_RED_SCALE, 1.0); - glPixelTransferf(GL_GREEN_SCALE, 1.0); - glPixelTransferf(GL_BLUE_SCALE, 1.0); + glDisable(GL_BLEND); + glDisable(GL_TEXTURE_2D); + } return font->Advance(wstr); } @@ -308,7 +362,11 @@ float FTF_TTFont::GetStringWidth(char* str, unsigned int flag) else len=utf8towchar(wstr,str); - return font->Advance(wstr); + if(mode == FTF_PIXMAPFONT) { + return font->Advance(wstr); + } else if(mode == FTF_TEXTUREFONT) { + return font->Advance(wstr) * fsize; + } } @@ -324,3 +382,24 @@ void FTF_TTFont::GetBoundingBox(char* str, float *llx, float *lly, float *llz, f font->BBox(wstr, *llx, *lly, *llz, *urx, *ury, *urz); } + + +void FTF_TTFont::SetPosition(float x, float y) +{ + pen_x = x; + pen_y = y; +} + + +void FTF_TTFont::SetMode(int m) +{ + mode = m; +} + + +void FTF_TTFont::SetScale(float size) +{ + fsize = size; +} + + diff --git a/source/blender/ftfont/intern/FTF_TTFont.h b/source/blender/ftfont/intern/FTF_TTFont.h index 103a25a1a71..15682bd4fde 100644 --- a/source/blender/ftfont/intern/FTF_TTFont.h +++ b/source/blender/ftfont/intern/FTF_TTFont.h @@ -38,6 +38,7 @@ #define __FTF_TRUETYPE_FONT_H #include "FTGLPixmapFont.h" +#include "FTGLTextureFont.h" #include //#include @@ -91,6 +92,13 @@ public: void SetEncoding(char* str); + /** + * functions to communicate with blender ui rasterpos + */ + void SetPosition(float x, float y); + void SetMode(int mode); + void SetScale(float fsize); + protected: char messagepath[1024]; @@ -99,6 +107,10 @@ protected: char font_name[128]; int font_size; + int mode; // 0 = pixmap, 1 = texture + float pen_x, pen_y; //rasterpos + float fsize; + /** FTGL's */ FTFont* font; /* active */ -- cgit v1.2.3