Added experimental option to use GL textured interface fonts.
authorRob Haarsma <phaseIV@zonnet.nl>
Wed, 19 Jan 2005 13:53:43 +0000 (13:53 +0000)
committerRob Haarsma <phaseIV@zonnet.nl>
Wed, 19 Jan 2005 13:53:43 +0000 (13:53 +0000)
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 !

16 files changed:
source/blender/ftfont/FTF_Api.h
source/blender/ftfont/FTF_Settings.h
source/blender/ftfont/intern/FTF_Api.cpp
source/blender/ftfont/intern/FTF_TTFont.cpp
source/blender/ftfont/intern/FTF_TTFont.h
source/blender/include/BIF_language.h
source/blender/include/blendef.h
source/blender/makesdna/DNA_userdef_types.h
source/blender/src/header_info.c
source/blender/src/headerbuttons.c
source/blender/src/interface.c
source/blender/src/interface_draw.c
source/blender/src/language.c
source/blender/src/outliner.c
source/blender/src/space.c
source/blender/src/usiblender.c

index 8f603d73ae1903d5f3383a4190954ed4691ad5cf..15fa55c905dacf731e54943f1d5b3b20f5e988e2 100644 (file)
@@ -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
index d9263baf5a2d16d1ed7768f5d1d711f73967da0e..dc325c1de41ae436bbe3042db651a8f03b1b74a5 100644 (file)
@@ -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 */
index 46638d9f4eb59792dca19409562685df53afb11e..036e13a7e6edd54d46fcd88b69ef4a0e7fe9d61b 100644 (file)
@@ -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);
+}
index ff599e9444cb2bb2ccc472f65d4e82bf09a210ed..d25c60ea4028fb596760eea9a3a256f5e124b93d 100644 (file)
@@ -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;
+}
+
+
index 103a25a1a714ffc4ecd7d26f3995d33b4ae49324..15682bd4fde6acd11b8b53728bc5500d340c8a8b 100644 (file)
@@ -38,6 +38,7 @@
 #define __FTF_TRUETYPE_FONT_H
 
 #include "FTGLPixmapFont.h"
+#include "FTGLTextureFont.h"
 
 #include <stdio.h>
 //#include <iconv.h>
@@ -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 */
        
index 414207c2e44ffc53a82e248c17cd965ca43985bc..28b57aa1017d7ed6c1dd219f30592e8e17531009 100644 (file)
@@ -48,5 +48,8 @@ char *fontsize_pup(void);
 int BIF_DrawString(struct BMF_Font* font, char *str, int translate);
 float BIF_GetStringWidth(struct BMF_Font* font, char *str, int translate);
 
+void BIF_RasterPos(float x, float y);
+void refresh_interface_font(void);
+
 #endif /* BIF_LANGUAGE_H */
 
index d4d2b2eba9b5f875075f9c10f78744d0c822b702..904928c65adfc8c684b5878109655af0491ff31a 100644 (file)
 #define B_SETTRANSBUTS         315
 #define B_DOLANGUIFONT         316
 #define B_RESTOREFONT          317
+#define B_USETEXTUREFONT       318
+#define B_SCALETEXTUREFONT     319
 
 #define B_UITHEMECHANGED       320
 #define B_UITHEMECOLORMOD      321
index 7d35bbb7873d3be1884113c758dfea0d2eab2f4b..2b7ff9d326eb9947fe4456e5643919ad3b1c9c24 100644 (file)
@@ -204,6 +204,7 @@ extern UserDef U; /* from usiblender.c !!!! */
 #define USER_TR_FILESELECT             8
 #define USER_TR_TEXTEDIT               16
 #define USER_DOTRANSLATE               32
+#define USER_USETEXTUREFONT            64
 
 /* dupflag */
 
index 5ef7fc7a2dde1d4d385b3872339e16cc815913b8..f1ec2bbe27adac1b4d4725257983c6a4d50f2d8f 100644 (file)
@@ -898,6 +898,7 @@ static void do_info_filemenu(void *arg, int event)
                
                        BKE_reset_undo();
                        BKE_write_undo("original");     /* save current state */
+                       refresh_interface_font();
                }
                break;
        case 31: /* save default settings */
@@ -1820,11 +1821,13 @@ static void info_text(int x, int y)
        glColor3ub(0, 0, 0);
 
        glRasterPos2i(x, y);
+       BIF_RasterPos(x, y);
 
        BIF_DrawString(G.font, headerstr, (U.transopts & USER_TR_MENUS));
        hsize= BIF_GetStringWidth(G.font, headerstr, (U.transopts & USER_TR_BUTTONS));
        
        glRasterPos2i(x+hsize+10,       y);
+       BIF_RasterPos(x+hsize+10,       y);
 
        BIF_DrawString(G.font, infostr, (U.transopts & USER_TR_MENUS));
 }
index 6a2d139f17d362ba02bf36954c8aa634e268bf6a..68194e25d8ab179969c7d7679eedc33b6e586804 100644 (file)
@@ -1575,6 +1575,7 @@ void do_global_buttons(unsigned short event)
                break;
 
        case B_SETFONTSIZE:             /* is button from space.c  *info* */
+               refresh_interface_font();
                FTF_SetSize(U.fontsize); 
                allqueue(REDRAWALL, 0);
                break;
@@ -1584,11 +1585,37 @@ void do_global_buttons(unsigned short event)
                break;
 
        case B_RESTOREFONT:             /* is button from space.c  *info* */
-               U.fontsize= 0;
-               start_interface_font();
-               allqueue(REDRAWALL, 0);
+               {
+                       extern float lang_texsize;
+
+                       lang_texsize = 1.0;
+                       FTF_SetScale(lang_texsize);
+
+                       U.fontsize= 0;
+                       start_interface_font();
+                       allqueue(REDRAWALL, 0);
+               }
                break;
                
+       case B_USETEXTUREFONT:          /* is button from space.c  *info* */
+               if(U.transopts & USER_USETEXTUREFONT)
+                       FTF_SetMode(FTF_TEXTUREFONT);
+               else
+                       FTF_SetMode(FTF_PIXMAPFONT);
+
+               refresh_interface_font();
+               allqueue(REDRAWALL, 0);
+               break;
+
+       case B_SCALETEXTUREFONT:                /* is button from space.c  *info* */
+               {
+                       extern float lang_texsize;
+
+                       FTF_SetScale(lang_texsize);
+                       allqueue(REDRAWALL, 0);
+               }
+               break;
+
        case B_DOLANGUIFONT:    /* is button from space.c  *info* */
                if(U.transopts & USER_DOTRANSLATE)
                        start_interface_font();
index 454826c85d792a06e56335c12309dcb32e88335a..4a08b6ee98331b91f2a3864193269fc136423d37 100644 (file)
@@ -3454,6 +3454,8 @@ static uiOverDraw *ui_draw_but_tip(uiBut *but)
 
                
 #ifdef INTERNATIONAL
+       extern float lang_texsize;
+
        if(G.ui_international == TRUE) {
                float llx,lly,llz,urx,ury,urz;  //for FTF_GetBoundingBox()
 
@@ -3462,11 +3464,15 @@ static uiOverDraw *ui_draw_but_tip(uiBut *but)
 
                        x1= (but->x1+but->x2)/2; x2= 10+x1+ but->aspect*FTF_GetStringWidth(but->tip, FTF_USE_GETTEXT | FTF_INPUT_UTF8);  //BMF_GetStringWidth(but->font, but->tip);
                        y1= but->y1-(ury+FTF_GetSize())-12; y2= but->y1-12;
+                       y1 *= lang_texsize;
+                       y2 *= lang_texsize;
                } else {
                        FTF_GetBoundingBox(but->tip, &llx,&lly,&llz,&urx,&ury,&urz, FTF_NO_TRANSCONV | FTF_INPUT_UTF8);
 
                        x1= (but->x1+but->x2)/2; x2= 10+x1+ but->aspect*FTF_GetStringWidth(but->tip, FTF_NO_TRANSCONV | FTF_INPUT_UTF8);  //BMF_GetStringWidth(but->font, but->tip);
                        y1= but->y1-(ury+FTF_GetSize())-12; y2= but->y1-12;
+                       y1 *= lang_texsize;
+                       y2 *= lang_texsize;
                }
        } else {
                x1= (but->x1+but->x2)/2; x2= 10+x1+ but->aspect*BMF_GetStringWidth(but->font, but->tip);
index b731615b6a9dc621b4d4666978e02935a285415c..b6bb28fbf669fd46f2fa19a06f0b97d8af5173b5 100644 (file)
@@ -115,6 +115,8 @@ void ui_rasterpos_safe(float x, float y, float aspect)
        }
        
        if(doit) glRasterPos2f(x, y);
+
+       BIF_RasterPos(x, y);
 }
 
 /* ************** generic embossed rect, for window sliders etc ************* */
index 55e0b864abce0d06e26b7c8d1bc6ce7ce4c17d14..8f9c476a1424d5996d5452217d3c65b0451e3cdb 100644 (file)
  */
 
 
+#ifdef WIN32
+#include "BLI_winstuff.h"
+#endif
+
 #include <string.h>
 #include <stdlib.h>
 
@@ -40,6 +44,7 @@
 #include "BLI_blenlib.h"
 #include "BLI_linklist.h"      /* linknode */
 
+#include "BIF_gl.h"
 #include "BIF_language.h"
 #include "BIF_space.h"         /* allqueue() */
 #include "BIF_toolbox.h"       /* error() */
@@ -66,20 +71,51 @@ struct _LANGMenuEntry {
 
 static LANGMenuEntry *langmenu= 0;
 static int tot_lang = 0;
+float lang_texsize = 1.0;
+
 #endif // INTERNATIONAL
 
+void BIF_RasterPos(float x, float y)
+{
+#ifdef INTERNATIONAL
+       FTF_SetPosition(x, y);
+#endif // INTERNATIONAL
+}
+
+void refresh_interface_font(void)
+{
+#ifdef INTERNATIONAL
+       if(U.transopts & USER_DOTRANSLATE)
+               start_interface_font();
+       else
+               G.ui_international = FALSE;
+#else // INTERNATIONAL
+       G.ui_international = FALSE;
+#endif
+}
 
 int BIF_DrawString(BMF_Font* font, char *str, int translate)
 {
 
 #ifdef INTERNATIONAL
-       if(G.ui_international == TRUE)
+       if(G.ui_international == TRUE) {
                if(translate)
                        return FTF_DrawString(str, FTF_USE_GETTEXT | FTF_INPUT_UTF8);
                else
                        return FTF_DrawString(str, FTF_NO_TRANSCONV | FTF_INPUT_UTF8);
-       else
+       } else {
                return BMF_DrawString(font, str);
+/*
+               glEnable(GL_TEXTURE_2D);
+               glEnable(GL_BLEND);
+               BMF_GetFontTexture(font);??
+               glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
+               BMF_DrawStringTexture(font, str, pen_x, pen_y, 0.0);
+               glDisable(GL_TEXTURE_2D);
+               glDisable(GL_BLEND);
+               return 0;
+*/
+       }
 #else
        return BMF_DrawString(font, str);
 #endif
index 3bfdfe9e54891b62f6b1d5acdef7558116eda396..b3c00331e2e02183f82772052381307743a78e2d 100644 (file)
@@ -1992,6 +1992,7 @@ static void outliner_draw_tree_element(SpaceOops *soops, TreeElement *te, int st
                if(active==1) BIF_ThemeColor(TH_TEXT_HI); 
                else BIF_ThemeColor(TH_TEXT);
                glRasterPos2i(startx+offsx, *starty+5);
+               BIF_RasterPos(startx+offsx, *starty+5);
                BIF_DrawString(G.font, te->name, 0);
                
                offsx+= OL_X + BIF_GetStringWidth(G.font, te->name, 0);
index 54c69657d1adb9bf37fb0b08e6e0c6f5a440c812..cd8951a5691b7d88acf43db4e9b478e288e6ec21 100644 (file)
@@ -2538,12 +2538,19 @@ void drawinfospace(ScrArea *sa, void *spacedata)
                                (xpos+edgsp+(2.2*mpref)+(3*midsp)),y2,mpref+(0.5*mpref)+3,buth,
                                &U.language, 0, 0, 0, 0, "Select interface language");
                                
-                       /* uiDefButBitS(block, TOG, USER_TR_TEXTEDIT, B_SETTRANSBUTS, "FTF All windows",
-                               (xpos+edgsp+(4*mpref)+(4*midsp)),y1,mpref,buth,
+                       uiDefButBitS(block, TOG, USER_USETEXTUREFONT, B_USETEXTUREFONT, "Use Textured Fonts",
+                               (xpos+edgsp+(4*mpref)+(4*midsp)),y2,mpref,buth,
                                &(U.transopts), 0, 0, 0, 0,
-                               "Use FTF drawing for fileselect and textwindow "
-                               "(under construction)");
-                       */
+                               "Use Textured Fonts");
+
+                       if(U.transopts & USER_USETEXTUREFONT) {
+                               extern float lang_texsize;
+
+                               uiDefButF(block, NUM, B_SCALETEXTUREFONT, "Scale Factor",
+                                       (xpos+edgsp+(4*mpref)+(4*midsp)),y1,mpref,buth,
+                                       &lang_texsize, 0.2, 2.0, 100, 2, "Tweak scaling for textured font");
+                       }
+
                }
 
 /* end of INTERNATIONAL */
index 8f92dbb71fff581a0540f722bfce68845cad5adc..037e1e9f43978eee57a2ec2fcf666b135a8a1d5f 100644 (file)
@@ -215,12 +215,9 @@ static void init_userdef_file(void)
 #ifdef INTERNATIONAL
        read_languagefile();
        
-       if(U.transopts & USER_DOTRANSLATE)
-               start_interface_font();
-       else
-               G.ui_international = FALSE;
+       refresh_interface_font();
 #endif // INTERNATIONAL
-       
+
 }
 
 void BIF_read_file(char *name)
@@ -248,6 +245,7 @@ void BIF_read_file(char *name)
                undo_editmode_clear();
                BKE_reset_undo();
                BKE_write_undo("original");     /* save current state */
+               refresh_interface_font();
        }
        else BIF_undo_push("Import file");
 }