Font preview

This commit is contained in:
Joilnen Leite 2007-07-30 15:59:16 +00:00
parent ecd42c4342
commit 443a64135e
12 changed files with 71 additions and 10 deletions

@ -5,7 +5,7 @@ WITH_BF_VERSE = 'false'
BF_VERSE_INCLUDE = "#extern/verse/dist"
BF_PYTHON = '/usr'
BF_PYTHON_VERSION = '2.5'
BF_PYTHON_VERSION = '2.4'
BF_PYTHON_INC = '${BF_PYTHON}/include/python${BF_PYTHON_VERSION}'
BF_PYTHON_BINARY = '${BF_PYTHON}/bin/python${BF_PYTHON_VERSION}'
BF_PYTHON_LIB = 'python${BF_PYTHON_VERSION}' #BF_PYTHON+'/lib/python'+BF_PYTHON_VERSION+'/config/libpython'+BF_PYTHON_VERSION+'.a'
@ -27,7 +27,7 @@ BF_SDL_LIB = 'SDL' #BF_SDL #$(shell $(BF_SDL)/bin/sdl-config --libs) -lSDL_mixer
WITH_BF_FMOD = 'false'
BF_FMOD = LIBDIR + '/fmod'
WITH_BF_OPENEXR = 'true'
WITH_BF_OPENEXR = 'false'
BF_OPENEXR = '/usr'
BF_OPENEXR_INC = '${BF_OPENEXR}/include/OpenEXR'
BF_OPENEXR_LIB = 'Half IlmImf Iex Imath '

@ -21,7 +21,7 @@
<Tool
Name="VCCLCompilerTool"
InlineFunctionExpansion="1"
AdditionalIncludeDirectories="..\..\..\..\lib\windows\freetype\include;..\..\..\..\build\msvc_7\extern\ftgl\include;..\..\..\..\lib\windows\gettext\include;..\..\..\source\blender\blenlib;..\..\..\source\blender\makesdna"
AdditionalIncludeDirectories="..\..\..\..\lib\windows\freetype\include;..\..\..\..\build\msvc_7\extern\ftgl\include;..\..\..\..\lib\windows\gettext\include;..\..\..\source\blender\blenlib;..\..\..\source\blender\makesdna;..\..\..\source\blender\include"
PreprocessorDefinitions="WIN32;NDEBUG;_LIB;WCHAR_T16;HAVE_LC_MESSAGES;FTGL_LIBRARY_STATIC"
StringPooling="TRUE"
RuntimeLibrary="0"

@ -154,6 +154,10 @@ FTF_EXPORT void FTF_SetScale(float fsize);
FTF_EXPORT void FTF_End(void);
/* Font preview functions */
FTF_EXPORT int FTF_GetNewFont (const unsigned char *str, int datasize, int fontsize);
FTF_EXPORT float FTF_DrawNewFontString(char* str, unsigned int flag);
#ifdef __cplusplus
}
#endif

@ -4,7 +4,7 @@ Import ('env')
sources = env.Glob('intern/*.cpp')
incs = '. intern ../blenkernel ../blenlib ../makesdna'
incs = '. intern ../blenkernel ../blenlib ../makesdna ../include'
incs += ' ' + env['BF_FTGL_INC']
incs += ' ' + env['BF_FREETYPE_INC']
incs += ' ' + env['BF_GETTEXT_INC']

@ -43,8 +43,18 @@
#include "../FTF_Api.h"
#include "FTF_TTFont.h"
#ifdef __cplusplus
extern "C" {
#endif
#include "datatoc.h"
#ifdef __cplusplus
}
#endif
#define FTF_EXPORT
FTF_TTFont *newfont= 0; // preview font
static FTF_TTFont *_FTF_GetFont(void) {
static FTF_TTFont *theFont = NULL;
@ -55,8 +65,28 @@ static FTF_TTFont *_FTF_GetFont(void) {
return theFont;
}
FTF_EXPORT int FTF_GetNewFont (const unsigned char *str, int datasize, int fontsize) {
if (newfont) delete newfont;
newfont= new FTF_TTFont();
if (!(newfont->SetFont((unsigned char*)str, datasize, fontsize))) {
newfont->SetFont((unsigned char*)datatoc_bfont_ttf, datatoc_bfont_ttf_size, fontsize);
return 0;
}
return 1;
}
FTF_EXPORT float FTF_DrawNewFontString(char* str, unsigned int flag)
{
if (newfont)
return newfont->DrawString(str, flag);
return 0.0f;
}
FTF_EXPORT void FTF_End(void) {
delete _FTF_GetFont();
delete newfont;
}
FTF_EXPORT void FTF_SetSize(int size)
@ -174,3 +204,5 @@ FTF_EXPORT void FTF_SetScale(float fsize)
{
_FTF_GetFont()->SetScale(fsize);
}

@ -46,6 +46,7 @@ CFLAGS += $(LEVEL_1_C_WARNINGS)
CPPFLAGS += -I../../makesdna
CPPFLAGS += -I../../blenkernel
CPPFLAGS += -I../../blenlib
CPPFLAGS += -I../../include
CPPFLAGS += -I$(NAN_FTGL)/include
CPPFLAGS += -I$(NAN_FTGL)/include/FTGL
CPPFLAGS += -I$(NAN_GETTEXT)/include

@ -166,6 +166,7 @@ struct AutoComplete;
#define BUT_CURVE (32<<9)
#define BUT_TOGDUAL (33<<9)
#define ICONTOGN (34<<9)
#define FTPREVIEW (35<<9)
#define BUTTYPE (63<<9)

@ -170,8 +170,10 @@ typedef struct SpaceFile {
char file[80];
short type, ofs, flag, sort;
short maxnamelen, collums;
short maxnamelen, collums, f_fp, pad1;
int pad2;
char fp_str[8];
struct BlendHandle *libfiledata;
unsigned short retval; /* event */
@ -443,6 +445,7 @@ typedef struct SpaceImaSel {
#define FILE_LOADLIB 1
#define FILE_MAIN 2
#define FILE_LOADFONT 3
/* sfile->flag */
#define FILE_SHOWSHORT 1

@ -2420,7 +2420,7 @@ void do_fontbuts(unsigned short event)
sa= closest_bigger_area();
areawinset(sa->win);
activate_fileselect(FILE_SPECIAL, "SELECT FONT", str, load_buts_vfont);
activate_fileselect(FILE_LOADFONT, "SELECT FONT", str, load_buts_vfont);
break;
case B_PACKFONT:

@ -111,6 +111,8 @@
#include "BIF_fsmenu.h" /* include ourselves */
#include "FTF_Api.h"
#if defined WIN32 || defined __BeOS
int fnmatch(const char *pattern, const char *string, int flags)
{
@ -507,7 +509,7 @@ void test_flags_file(SpaceFile *sfile)
}
}
}
} else if (sfile->type==FILE_SPECIAL){
} else if (sfile->type==FILE_SPECIAL || sfile->type==FILE_LOADFONT){
if(BLI_testextensie(file->relname, ".py")) {
file->flags |= PYSCRIPTFILE;
} else if( BLI_testextensie(file->relname, ".ttf")
@ -1368,7 +1370,7 @@ static void activate_fileselect_(int type, char *title, char *file, short *menup
sfile->libfiledata= NULL;
}
}
else { /* FILE_BLENDER */
else { /* FILE_BLENDER or FILE_LOADFONT */
split_sfile(sfile, name); /* test filelist too */
BLI_cleanup_dir(G.sce, sfile->dir);
@ -2019,8 +2021,15 @@ void winqreadfilespace(ScrArea *sa, void *spacedata, BWinEvent *evt)
}
else {
if( strcmp(sfile->file, sfile->filelist[act].relname)) {
char tmpstr[240];
do_draw= 1;
BLI_strncpy(sfile->file, sfile->filelist[act].relname, sizeof(sfile->file));
if (sfile->f_fp) {
sprintf (tmpstr, "%s%s", sfile->dir, sfile->file);
/* printf ("%s\n", tmpstr); */
if (!FTF_GetNewFont ((const unsigned char *)tmpstr, 0, U.fontsize))
error ("No font file");
}
}
if(event==MIDDLEMOUSE && sfile->type) filesel_execute(sfile);
}

@ -158,6 +158,13 @@ void file_buttons(void)
xco+= 100; // scroll
}
else if(sfile->type==FILE_LOADFONT) {
uiDefIconButBitS(block, ICONTOG, FILE_SHOWSHORT, B_SORTFILELIST, ICON_BLANK3, xco+= XIC, 0, XIC, YIC, &sfile->f_fp, 0, 0, 0, 0, "Activate font preview");
if (sfile->f_fp)
uiDefButC(block, FTPREVIEW, 0, "Font preview", xco+= XIC, 0, 100, YIC, sfile->fp_str, (float)0, (float)16, 0, 0, "Font preview");
xco+= 100; // scroll
}
uiDrawBlock(block);

@ -1604,7 +1604,11 @@ static void ui_draw_text_icon(uiBut *but)
ui_rasterpos_safe(x, (but->y1+but->y2- 9.0)/2.0, but->aspect);
if(but->type==IDPOIN) transopts= 0; // no translation, of course!
else transopts= (U.transopts & USER_TR_BUTTONS);
BIF_DrawString(but->font, but->drawstr+but->ofs, transopts);
if (but->type == FTPREVIEW)
FTF_DrawNewFontString (but->drawstr+but->ofs, FTF_INPUT_UTF8);
else
BIF_DrawString(but->font, but->drawstr+but->ofs, transopts);
/* part text right aligned */
if(cpoin) {