diff options
author | Diego Borghetti <bdiego@gmail.com> | 2009-02-17 19:56:29 +0300 |
---|---|---|
committer | Diego Borghetti <bdiego@gmail.com> | 2009-02-17 19:56:29 +0300 |
commit | 16a61743e133e505bd4666ad30d1697764171ad8 (patch) | |
tree | 5ba2783ade41a70fbe23ef08c2a2c6ae3984c7d1 /source/blender | |
parent | 9aa7e981bde5ad1b6f798ef5048cc4c373d09eb2 (diff) |
Making the things compiled!!
I change the #if 0 with #if WITH_FREETYPE2, also fix a lot of typos, etc.
This is the basic but now it draw text!!, I am using the "User Preference"
space to test the library, nobody is working on that and the option are
in the outliner now so...
TODO-next: using the 4x4 mat, string size, bounding box, aspect and rotate.
Notes: I update the Makefile, missing some include and other things so
maybe scons, cmake and msvc also need update ?
Diffstat (limited to 'source/blender')
-rw-r--r-- | source/blender/blenfont/BLF_api.h | 16 | ||||
-rw-r--r-- | source/blender/blenfont/intern/Makefile | 38 | ||||
-rw-r--r-- | source/blender/blenfont/intern/blf.c | 97 | ||||
-rw-r--r-- | source/blender/blenfont/intern/blf_dir.c | 12 | ||||
-rw-r--r-- | source/blender/blenfont/intern/blf_font.c | 61 | ||||
-rw-r--r-- | source/blender/blenfont/intern/blf_glyph.c | 96 | ||||
-rw-r--r-- | source/blender/blenfont/intern/blf_internal.h | 23 | ||||
-rw-r--r-- | source/blender/blenfont/intern/blf_internal_types.h | 16 | ||||
-rw-r--r-- | source/blender/blenfont/intern/blf_lang.c | 10 | ||||
-rw-r--r-- | source/blender/editors/interface/text.c | 14 | ||||
-rw-r--r-- | source/blender/editors/space_info/Makefile | 1 | ||||
-rw-r--r-- | source/blender/editors/space_info/space_info.c | 24 | ||||
-rw-r--r-- | source/blender/windowmanager/intern/wm_files.c | 5 | ||||
-rw-r--r-- | source/blender/windowmanager/intern/wm_init_exit.c | 4 |
14 files changed, 336 insertions, 81 deletions
diff --git a/source/blender/blenfont/BLF_api.h b/source/blender/blenfont/BLF_api.h index d91fbbf0fa9..cec3c81ee13 100644 --- a/source/blender/blenfont/BLF_api.h +++ b/source/blender/blenfont/BLF_api.h @@ -29,6 +29,18 @@ #ifndef BLF_API_H #define BLF_API_H +int BLF_init(void); +void BLF_exit(void); + +int BLF_load(char *name); +int BLF_load_mem(char *name, unsigned char *mem, int mem_size); + +void BLF_set(int fontid); +void BLF_aspect(float aspect); +void BLF_position(float x, float y, float z); +void BLF_size(int size, int dpi); +void BLF_draw(char *str); + /* Read the .Blanguages file, return 1 on success or 0 if fails. */ int BLF_lang_init(void); @@ -49,8 +61,6 @@ int BLF_lang_error(void); /* Return the code string for the specified language code. */ char *BLF_lang_find_code(short langid); -#if 0 - /* Add a path to the font dir paths. */ void BLF_dir_add(const char *path); @@ -63,6 +73,4 @@ char **BLF_dir_get(int *ndir); /* Free the data return by BLF_dir_get. */ void BLF_dir_free(char **dirs, int count); -#endif /* zero!! */ - #endif /* BLF_API_H */ diff --git a/source/blender/blenfont/intern/Makefile b/source/blender/blenfont/intern/Makefile index 94e80466782..18bf42f3fa5 100644 --- a/source/blender/blenfont/intern/Makefile +++ b/source/blender/blenfont/intern/Makefile @@ -33,10 +33,46 @@ include nan_compile.mk CFLAGS += $(LEVEL_1_C_WARNINGS) -CPPFLAGS += -I$(NAN_GUARDEDALLOC)/include +# OpenGL and Freetype2 +CPPFLAGS += -I$(NAN_GLEW)/include +CPPFLAGS += $(OGL_CPPFLAGS) +CPPFLAGS += -I$(NAN_FREETYPE)/include + +ifeq ($(OS), windows) + CPPFLAGS += -I$(NAN_ICONV)/include + ifeq ($(FREE_WINDOWS), true) + CPPFLAGS += -I$(NAN_FREETYPE)/include/freetype2 + CPPFLAGS += -DUSE_GETTEXT_DLL + endif +else + CPPFLAGS += -I$(NAN_FREETYPE)/include/freetype2 +endif + +ifeq ($(OS),linux) + ifeq ($(CPU),alpha) + CPPFLAGS += -I$(NAN_MESA)/include + endif + ifeq ($(CPU),i386) + CPPFLAGS += -I$(NAN_MESA)/include + endif + ifeq ($(CPU),powerpc) + CPPFLAGS += -I/usr/src/MesaCVS/include + endif +endif + +ifeq ($(WITH_FREETYPE2), true) + CPPFLAGS += -DWITH_FREETYPE2 +endif + +# Modules +CPPFLAGS += -I../../editors/include CPPFLAGS += -I../../makesdna CPPFLAGS += -I../../blenlib CPPFLAGS += -I../../blenkernel CPPFLAGS += -I../../ftfont +# Memory allocator +CPPFLAGS += -I$(NAN_GUARDEDALLOC)/include + +# Our own headers CPPFLAGS += -I.. diff --git a/source/blender/blenfont/intern/blf.c b/source/blender/blenfont/intern/blf.c index b503ea06404..b602a7f1234 100644 --- a/source/blender/blenfont/intern/blf.c +++ b/source/blender/blenfont/intern/blf.c @@ -26,20 +26,23 @@ * ***** END GPL LICENSE BLOCK ***** */ -#if 0 - #include <stdio.h> #include <stdlib.h> #include <string.h> +#ifdef WITH_FREETYPE2 + #include <ft2build.h> #include FT_FREETYPE_H #include FT_GLYPH_H +#endif /* WITH_FREETYPE2 */ + #include "MEM_guardedalloc.h" #include "DNA_listBase.h" +#include "DNA_vec_types.h" #include "BKE_utildefines.h" @@ -47,10 +50,15 @@ #include "BLI_linklist.h" /* linknode */ #include "BLI_string.h" +#include "BIF_gl.h" +#include "BIF_glutil.h" + #include "blf_internal_types.h" #include "blf_internal.h" +#ifdef WITH_FREETYPE2 + /* Max number of font in memory. * Take care that now every font have a glyph cache per size/dpi, * so we don't need load the same font with different size, just @@ -67,31 +75,55 @@ int global_font_num= 0; /* Current font. */ int global_font_cur= 0; +#endif /* WITH_FREETYPE2 */ + int BLF_init(void) { +#ifdef WITH_FREETYPE2 int i; for (i= 0; i < BLF_MAX_FONT; i++) global_font[i]= NULL; return(blf_font_init()); +#else + return(0); +#endif } -int blf_search(char *name) +void BLF_exit(void) { +#ifdef WITH_FREETYPE2 FontBLF *font; int i; for (i= 0; i < global_font_num; i++) { font= global_font[i]; + blf_font_free(font); + } + + blf_font_exit(); +#endif +} + +int blf_search(char *name) +{ +#ifdef WITH_FREETYPE2 + FontBLF *font; + int i; + + for (i= 0; i < BLF_MAX_FONT; i++) { + font= global_font[i]; if (font && (!strcmp(font->name, name))) return(i); } +#endif return(-1); } int BLF_load(char *name) { +#ifdef WITH_FREETYPE2 FontBLF *font; char *filename; int i; @@ -101,30 +133,44 @@ int BLF_load(char *name) /* check if we already load this font. */ i= blf_search(name); - if (i >= 0) + if (i >= 0) { + font= global_font[i]; + font->ref++; + printf("Increment reference (%d): %s\n", font->ref, name); return(i); + } - if (global_font_num+1 >= BLF_MAX_FONT) + if (global_font_num+1 >= BLF_MAX_FONT) { + printf("Too many fonts!!!\n"); return(-1); + } filename= blf_dir_search(name); - if (!filename) + if (!filename) { + printf("Can't found font: %s\n", name); return(-1); + } font= blf_font_new(name, filename); MEM_freeN(filename); - if (!font) + if (!font) { + printf("Can't load font: %s\n", name); return(-1); + } global_font[global_font_num]= font; i= global_font_num; global_font_num++; return(i); +#else + return(-1); +#endif /* WITH_FREETYPE2 */ } int BLF_load_mem(char *name, unsigned char *mem, int mem_size) { +#ifdef WITH_FREETYPE2 FontBLF *font; int i; @@ -132,39 +178,55 @@ int BLF_load_mem(char *name, unsigned char *mem, int mem_size) return(-1); i= blf_search(name); - if (i >= 0) + if (i >= 0) { + font= global_font[i]; + font->ref++; + printf("Increment reference (%d): %s\n", font->ref, name); return(i); + } - if (global_font_num+1 >= BLF_MAX_FONT) + if (global_font_num+1 >= BLF_MAX_FONT) { + printf("Too many fonts!!!\n"); return(-1); + } - font= blf_font_new_from_mem(name, mem, size); - if (!font) + font= blf_font_new_from_mem(name, mem, mem_size); + if (!font) { + printf("Can't load font, %s from memory!!\n", name); return(-1); + } global_font[global_font_num]= font; i= global_font_num; global_font_num++; return(i); +#else + return(-1); +#endif /* WITH_FREETYPE2 */ } void BLF_set(int fontid) { - if (fontid >= 0 && fontid < global_font_num) +#ifdef WITH_FREETYPE2 + if (fontid >= 0 && fontid < BLF_MAX_FONT) global_font_cur= fontid; +#endif } void BLF_aspect(float aspect) { +#ifdef WITH_FREETYPE2 FontBLF *font; font= global_font[global_font_cur]; if (font) font->aspect= aspect; +#endif } void BLF_position(float x, float y, float z) { +#ifdef WITH_FREETYPE2 FontBLF *font; font= global_font[global_font_cur]; @@ -173,23 +235,27 @@ void BLF_position(float x, float y, float z) font->pos[1]= y; font->pos[2]= z; } +#endif } void BLF_size(int size, int dpi) { +#ifdef WITH_FREETYPE2 FontBLF *font; font= global_font[global_font_cur]; if (font) blf_font_size(font, size, dpi); +#endif } void BLF_draw(char *str) { +#ifdef WITH_FREETYPE2 FontBLF *font; font= global_font[global_font_cur]; - if (font) { + if (font && font->glyph_cache) { glEnable(GL_BLEND); glEnable(GL_TEXTURE_2D); glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); @@ -200,9 +266,8 @@ void BLF_draw(char *str) blf_font_draw(font, str); glPopMatrix(); - glDisable(GL_TEXTURE_2D); glDisable(GL_BLEND); + glDisable(GL_TEXTURE_2D); } +#endif /* WITH_FREETYPE2 */ } - -#endif diff --git a/source/blender/blenfont/intern/blf_dir.c b/source/blender/blenfont/intern/blf_dir.c index dea422a1765..1216c610515 100644 --- a/source/blender/blenfont/intern/blf_dir.c +++ b/source/blender/blenfont/intern/blf_dir.c @@ -29,9 +29,19 @@ #include <stdlib.h> #include <string.h> +#ifdef WITH_FREETYPE2 + +#include <ft2build.h> + +#include FT_FREETYPE_H +#include FT_GLYPH_H + +#endif /* WITH_FREETYPE2 */ + #include "MEM_guardedalloc.h" #include "DNA_listBase.h" +#include "DNA_vec_types.h" #include "BKE_utildefines.h" @@ -39,6 +49,8 @@ #include "BLI_linklist.h" /* linknode */ #include "BLI_string.h" +#include "BIF_gl.h" + #include "blf_internal_types.h" static ListBase global_font_dir= { NULL, NULL }; diff --git a/source/blender/blenfont/intern/blf_font.c b/source/blender/blenfont/intern/blf_font.c index 28b33640692..62a64851109 100644 --- a/source/blender/blenfont/intern/blf_font.c +++ b/source/blender/blenfont/intern/blf_font.c @@ -26,31 +26,39 @@ * ***** END GPL LICENSE BLOCK ***** */ -#if 0 - #include <stdio.h> #include <stdlib.h> #include <string.h> +#ifdef WITH_FREETYPE2 + #include <ft2build.h> #include FT_FREETYPE_H #include FT_GLYPH_H +#endif /* WITH_FREETYPE2 */ + #include "MEM_guardedalloc.h" #include "DNA_listBase.h" +#include "DNA_vec_types.h" #include "BKE_utildefines.h" #include "BLI_blenlib.h" #include "BLI_linklist.h" /* linknode */ #include "BLI_string.h" +#include "BLI_arithb.h" + +#include "BIF_gl.h" #include "blf_internal_types.h" #include "blf_internal.h" +#ifdef WITH_FREETYPE2 + /* freetype2 handle. */ FT_Library global_ft_lib; @@ -61,7 +69,7 @@ int blf_font_init(void) void blf_font_exit(void) { - FT_Done_Freetype(global_ft_lib); + FT_Done_FreeType(global_ft_lib); } void blf_font_fill(FontBLF *font) @@ -95,21 +103,20 @@ FontBLF *blf_font_new(char *name, char *filename) font= (FontBLF *)MEM_mallocN(sizeof(FontBLF), "blf_font_new"); err= FT_New_Face(global_ft_lib, filename, 0, &font->face); if (err) { - printf("BLF: Can't load font: %s\n", filename); MEM_freeN(font); return(NULL); } err= FT_Select_Charmap(font->face, ft_encoding_unicode); if (err) { - printf("Warning: FT_Select_Charmap fail!!\n"); + printf("Can't set the unicode character map!\n"); FT_Done_Face(font->face); MEM_freeN(font); return(NULL); } - font->name= MEM_strdup(name); - font->filename= MEM_strdup(filename); + font->name= BLI_strdup(name); + font->filename= BLI_strdup(filename); blf_font_fill(font); return(font); } @@ -120,22 +127,21 @@ FontBLF *blf_font_new_from_mem(char *name, unsigned char *mem, int mem_size) FT_Error err; font= (FontBLF *)MEM_mallocN(sizeof(FontBLF), "blf_font_new_from_mem"); - err= FT_New_Memory_Face(global_ft_lib, mem, size, 0, &font->face); + err= FT_New_Memory_Face(global_ft_lib, mem, mem_size, 0, &font->face); if (err) { - printf("BLF: Can't load font: %s, from memory!!\n", name); MEM_freeN(font); return(NULL); } err= FT_Select_Charmap(font->face, ft_encoding_unicode); if (err) { - printf("BLF: FT_Select_Charmap fail!!\n"); + printf("Can't set the unicode character map!\n"); FT_Done_Face(font->face); MEM_freeN(font); return(NULL); } - font->name= MEM_strdup(name); + font->name= BLI_strdup(name); font->filename= NULL; blf_font_fill(font); return(font); @@ -149,7 +155,7 @@ void blf_font_size(FontBLF *font, int size, int dpi) err= FT_Set_Char_Size(font->face, 0, (size * 64), dpi, dpi); if (err) { /* FIXME: here we can go through the fixed size and choice a close one */ - printf("Warning: The current face don't support the size (%d) and dpi (%d)\n", size, dpi); + printf("The current font don't support the size, %d and dpi, %d\n", size, dpi); return; } @@ -163,6 +169,8 @@ void blf_font_size(FontBLF *font, int size, int dpi) gc= blf_glyph_cache_new(font); if (gc) font->glyph_cache= gc; + else + font->glyph_cache= NULL; } } @@ -182,11 +190,11 @@ void blf_font_draw(FontBLF *font, char *str) g_prev= NULL; while (str[i]) { - c= blf_uf8_next((unsigned char *)str, &i); + c= blf_utf8_next((unsigned char *)str, &i); if (c == 0) break; - glyph_index= FT_Get_Char_Index(face, c); + glyph_index= FT_Get_Char_Index(font->face, c); g= blf_glyph_search(font->glyph_cache, glyph_index); if (!g) g= blf_glyph_add(font, glyph_index, c); @@ -195,11 +203,11 @@ void blf_font_draw(FontBLF *font, char *str) if (!g) continue; - if (use_kering && g_prev) { + if (has_kerning && g_prev) { delta.x= 0; delta.y= 0; - FT_Get_Kerning(font->face, g_prev->index, glyph_index, FT_KERNING_MODE_UNFITTED, &delta); + FT_Get_Kerning(font->face, g_prev->index, glyph_index, FT_KERNING_UNFITTED, &delta); pen_x += delta.x >> 6; } @@ -209,4 +217,23 @@ void blf_font_draw(FontBLF *font, char *str) } } -#endif /* zero!! */ +void blf_font_free(FontBLF *font) +{ + GlyphCacheBLF *gc; + + font->glyph_cache= NULL; + while (font->cache.first) { + gc= font->cache.first; + BLI_remlink(&font->cache, gc); + blf_glyph_cache_free(gc); + } + + FT_Done_Face(font->face); + if (font->filename) + MEM_freeN(font->filename); + if (font->name) + MEM_freeN(font->name); + MEM_freeN(font); +} + +#endif /* WITH_FREETYPE2 */ diff --git a/source/blender/blenfont/intern/blf_glyph.c b/source/blender/blenfont/intern/blf_glyph.c index ca8751a8746..3918be3d469 100644 --- a/source/blender/blenfont/intern/blf_glyph.c +++ b/source/blender/blenfont/intern/blf_glyph.c @@ -26,20 +26,25 @@ * ***** END GPL LICENSE BLOCK ***** */ -#if 0 - #include <stdio.h> #include <stdlib.h> #include <string.h> +#include <math.h> + +#ifdef WITH_FREETYPE2 #include <ft2build.h> #include FT_FREETYPE_H #include FT_GLYPH_H +#include FT_OUTLINE_H + +#endif /* WITH_FREETYPE2 */ #include "MEM_guardedalloc.h" #include "DNA_listBase.h" +#include "DNA_vec_types.h" #include "BKE_utildefines.h" @@ -47,10 +52,14 @@ #include "BLI_linklist.h" /* linknode */ #include "BLI_string.h" +#include "BIF_gl.h" + #include "blf_internal_types.h" #include "blf_internal.h" +#ifdef WITH_FREETYPE2 + GlyphCacheBLF *blf_glyph_cache_find(FontBLF *font, int size, int dpi) { GlyphCacheBLF *p; @@ -70,7 +79,7 @@ GlyphCacheBLF *blf_glyph_cache_new(FontBLF *font) GlyphCacheBLF *gc; int i; - gc= (GlyphCacheBLF *)MEM_mallocN(sizeof(GlyphCacheBLF)); + gc= (GlyphCacheBLF *)MEM_mallocN(sizeof(GlyphCacheBLF), "blf_glyph_cache_new"); gc->next= NULL; gc->prev= NULL; gc->size= font->size; @@ -81,30 +90,30 @@ GlyphCacheBLF *blf_glyph_cache_new(FontBLF *font) gc->bucket[i].last= NULL; } - gc->textures= (GLuint *)malloc(sizeof(GLunit)*256); + gc->textures= (GLuint *)malloc(sizeof(GLuint)*256); gc->ntex= 256; gc->cur_tex= -1; gc->x_offs= 0; gc->y_offs= 0; gc->pad= 3; - gc->num_glyphs= font->face.num_glyphs; - gc->rem_glyphs= font->face.num_glyphs; - gc->ascender= ((float)font->size.metrics.ascender) / 64.0f; - gc->descender= ((float)font->size.metrics.descender) / 64.0f; + gc->num_glyphs= font->face->num_glyphs; + gc->rem_glyphs= font->face->num_glyphs; + gc->ascender= ((float)font->face->size->metrics.ascender) / 64.0f; + gc->descender= ((float)font->face->size->metrics.descender) / 64.0f; if (FT_IS_SCALABLE(font->face)) { gc->max_glyph_width= (float)((font->face->bbox.xMax - font->face->bbox.xMin) * - (((float)font->face->size.metrics.x_ppem) / + (((float)font->face->size->metrics.x_ppem) / ((float)font->face->units_per_EM))); gc->max_glyph_height= (float)((font->face->bbox.yMax - font->face->bbox.yMin) * - (((float)font->face->size.metrics.y_ppem) / + (((float)font->face->size->metrics.y_ppem) / ((float)font->face->units_per_EM))); } else { - gc->max_glyph_width= ((float)font->face->metrics.max_advance) / 64.0f; - gc->max_glyph_height= ((float)font->face->size.metrics.height) / 64.0f; + gc->max_glyph_width= ((float)font->face->size->metrics.max_advance) / 64.0f; + gc->max_glyph_height= ((float)font->face->size->metrics.height) / 64.0f; } gc->p2_width= 0; @@ -114,24 +123,42 @@ GlyphCacheBLF *blf_glyph_cache_new(FontBLF *font) return(gc); } +void blf_glyph_cache_free(GlyphCacheBLF *gc) +{ + GlyphBLF *g; + int i; + + for (i= 0; i < 257; i++) { + while (gc->bucket[i].first) { + g= gc->bucket[i].first; + BLI_remlink(&(gc->bucket[i]), g); + blf_glyph_free(g); + } + } + + glDeleteTextures(gc->cur_tex+1, gc->textures); + free((void *)gc->textures); + MEM_freeN(gc); +} + void blf_glyph_cache_texture(FontBLF *font, GlyphCacheBLF *gc) { - int tot_mem; + int tot_mem, i; unsigned char *buf; /* move the index. */ gc->cur_tex++; - if (gc->cur_tex > gc->ntex) { + if (gc->cur_tex >= gc->ntex) { gc->ntex *= 2; - gc->textures= (GLuint *)realloc((void *)gc->textures, sizeof(GLunit)*gc->ntex); + gc->textures= (GLuint *)realloc((void *)gc->textures, sizeof(GLuint)*gc->ntex); } gc->p2_width= blf_next_p2((gc->rem_glyphs * gc->max_glyph_width) + (gc->pad * 2)); if (gc->p2_width > font->max_tex_size) gc->p2_width= font->max_tex_size; - i= (int)((gc->p2_width - (gc->pad * 2)) / gc->p2_width); + i= (int)((gc->p2_width - (gc->pad * 2)) / gc->max_glyph_width); gc->p2_height= blf_next_p2(((gc->num_glyphs / i) + 1) * gc->max_glyph_height); if (gc->p2_height > font->max_tex_size) @@ -141,7 +168,8 @@ void blf_glyph_cache_texture(FontBLF *font, GlyphCacheBLF *gc) buf= (unsigned char *)malloc(tot_mem); memset((void *)buf, 0, tot_mem); - glGenTextures(1, (GLuint*)gc->texures[gc->cur_tex]); + glGenTextures(1, &gc->textures[gc->cur_tex]); + glBindTexture(GL_TEXTURE_2D, gc->textures[gc->cur_tex]); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST); @@ -169,11 +197,11 @@ GlyphBLF *blf_glyph_search(GlyphCacheBLF *gc, FT_UInt idx) GlyphBLF *blf_glyph_add(FontBLF *font, FT_UInt index, unsigned int c) { FT_GlyphSlot slot; - GlyphCache *gc; + GlyphCacheBLF *gc; GlyphBLF *g; FT_Error err; FT_Bitmap bitmap; - FTBBox bbox; + FT_BBox bbox; unsigned int key; g= blf_glyph_search(font->glyph_cache, index); @@ -188,7 +216,7 @@ GlyphBLF *blf_glyph_add(FontBLF *font, FT_UInt index, unsigned int c) slot= font->face->glyph; err= FT_Render_Glyph(slot, FT_RENDER_MODE_NORMAL); - if (err) + if (err || slot->format != FT_GLYPH_FORMAT_BITMAP) return(NULL); g= (GlyphBLF *)MEM_mallocN(sizeof(GlyphBLF), "blf_glyph_add"); @@ -216,6 +244,7 @@ GlyphBLF *blf_glyph_add(FontBLF *font, FT_UInt index, unsigned int c) bitmap= slot->bitmap; g->tex= gc->textures[gc->cur_tex]; + g->xoff= gc->x_offs; g->yoff= gc->y_offs; g->width= bitmap.width; @@ -233,8 +262,8 @@ GlyphBLF *blf_glyph_add(FontBLF *font, FT_UInt index, unsigned int c) } g->advance= ((float)slot->advance.x) / 64.0f; - g->pos_x= bitmap.left; - g->pos_y= bitmap.top; + g->pos_x= slot->bitmap_left; + g->pos_y= slot->bitmap_top; FT_Outline_Get_CBox(&(slot->outline), &bbox); g->box.xmin= ((float)bbox.xMin) / 64.0f; @@ -242,19 +271,28 @@ GlyphBLF *blf_glyph_add(FontBLF *font, FT_UInt index, unsigned int c) g->box.ymin= ((float)bbox.yMin) / 64.0f; g->box.ymax= ((float)bbox.yMax) / 64.0f; - g->uv[0][0]= ((float)g->xoff) / ((float)g->p2_width); - g->uv[0][1]= ((float)g->yoff) / ((float)g->p2_height); - g->uv[1][0]= ((float)(g->xoff + g->width)) / ((float)g->p2_width); - g->uv[1][1]= ((float)(g->yoff + g->height)) / ((float)g->p2_height); + g->uv[0][0]= ((float)g->xoff) / ((float)gc->p2_width); + g->uv[0][1]= ((float)g->yoff) / ((float)gc->p2_height); + g->uv[1][0]= ((float)(g->xoff + g->width)) / ((float)gc->p2_width); + g->uv[1][1]= ((float)(g->yoff + g->height)) / ((float)gc->p2_height); /* update the x offset for the next glyph. */ gc->x_offs += (int)(g->box.xmax - g->box.xmin + gc->pad); key= blf_hash(g->index); - BLI_addhead(&gc->bucket[key], g); + BLI_addhead(&(gc->bucket[key]), g); + gc->rem_glyphs--; return(g); } +void blf_glyph_free(GlyphBLF *g) +{ + /* don't need free the texture, the GlyphCache already + * have a list of all the texture and free it. + */ + MEM_freeN(g); +} + void blf_glyph_render(GlyphBLF *g, float x, float y) { GLint cur_tex; @@ -262,7 +300,7 @@ void blf_glyph_render(GlyphBLF *g, float x, float y) glGetIntegerv(GL_TEXTURE_2D_BINDING_EXT, &cur_tex); if (cur_tex != g->tex) - glBindTexture(GL_TEXTURE_2D, &g->tex); + glBindTexture(GL_TEXTURE_2D, g->tex); dx= floor(x + g->pos_x); glBegin(GL_QUADS); @@ -280,4 +318,4 @@ void blf_glyph_render(GlyphBLF *g, float x, float y) glEnd(); } -#endif /* zero!! */ +#endif /* WITH_FREETYPE2 */ diff --git a/source/blender/blenfont/intern/blf_internal.h b/source/blender/blenfont/intern/blf_internal.h index 8af94a8fb99..6bb7578935f 100644 --- a/source/blender/blenfont/intern/blf_internal.h +++ b/source/blender/blenfont/intern/blf_internal.h @@ -35,4 +35,27 @@ int blf_utf8_next(unsigned char *buf, int *iindex); char *blf_dir_search(const char *file); int blf_dir_split(const char *str, char *file, int *size); +#ifdef WITH_FREETYPE2 + +int blf_font_init(void); +void blf_font_exit(void); + +FontBLF *blf_font_new(char *name, char *filename); +FontBLF *blf_font_new_from_mem(char *name, unsigned char *mem, int mem_size); + +void blf_font_free(FontBLF *font); +void blf_font_size(FontBLF *font, int size, int dpi); +void blf_font_draw(FontBLF *font, char *str); + +GlyphCacheBLF *blf_glyph_cache_find(FontBLF *font, int size, int dpi); +GlyphCacheBLF *blf_glyph_cache_new(FontBLF *font); +void blf_glyph_cache_free(GlyphCacheBLF *gc); + +GlyphBLF *blf_glyph_search(GlyphCacheBLF *gc, FT_UInt idx); +GlyphBLF *blf_glyph_add(FontBLF *font, FT_UInt index, unsigned int c); + +void blf_glyph_free(GlyphBLF *g); +void blf_glyph_render(GlyphBLF *g, float x, float y); + +#endif /* WITH_FREETYPE2 */ #endif /* BLF_INTERNAL_H */ diff --git a/source/blender/blenfont/intern/blf_internal_types.h b/source/blender/blenfont/intern/blf_internal_types.h index 5aacb2343bb..f8d5159bd9b 100644 --- a/source/blender/blenfont/intern/blf_internal_types.h +++ b/source/blender/blenfont/intern/blf_internal_types.h @@ -36,11 +36,11 @@ typedef struct DirBLF { char *path; } DirBLF; -#if 0 +#ifdef WITH_FREETYPE2 -typedef struct _GlyphCacheBLF { - struct _GlyphCacheBLF *next; - struct _GlyphCacheBLF *prev; +typedef struct GlyphCacheBLF { + struct GlyphCacheBLF *next; + struct GlyphCacheBLF *prev; /* font size. */ int size; @@ -88,9 +88,9 @@ typedef struct _GlyphCacheBLF { float descender; } GlyphCacheBLF; -typedef struct _GlyphBLF { - struct _GlyphBLF *next; - struct _GlyphBLF *prev; +typedef struct GlyphBLF { + struct GlyphBLF *next; + struct GlyphBLF *prev; /* and the character, as UTF8 */ unsigned int c; @@ -173,7 +173,7 @@ typedef struct FontBLF { GlyphCacheBLF *glyph_cache; } FontBLF; -#endif /* zero!! */ +#endif /* WITH_FREETYPE2 */ typedef struct LangBLF { struct LangBLF *next; diff --git a/source/blender/blenfont/intern/blf_lang.c b/source/blender/blenfont/intern/blf_lang.c index 0aaf399cf58..730440a5ae5 100644 --- a/source/blender/blenfont/intern/blf_lang.c +++ b/source/blender/blenfont/intern/blf_lang.c @@ -29,9 +29,17 @@ #include <stdlib.h> #include <string.h> +#ifdef WITH_FREETYPE2 +#include <ft2build.h> + +#include FT_FREETYPE_H +#include FT_GLYPH_H +#endif + #include "MEM_guardedalloc.h" #include "DNA_listBase.h" +#include "DNA_vec_types.h" #include "BKE_utildefines.h" @@ -39,6 +47,8 @@ #include "BLI_linklist.h" /* linknode */ #include "BLI_string.h" +#include "BIF_gl.h" + #include "blf_internal_types.h" // XXX 2.50 Remove this later. diff --git a/source/blender/editors/interface/text.c b/source/blender/editors/interface/text.c index 8d4a3e4fb29..c3dc40e59ef 100644 --- a/source/blender/editors/interface/text.c +++ b/source/blender/editors/interface/text.c @@ -96,6 +96,18 @@ void UI_SetScale(float aspect) void ui_text_init_userdef(void) { + int id; + + id= BLF_load_mem("default", (unsigned char*)datatoc_bfont_ttf, datatoc_bfont_ttf_size); + if (id == -1) + printf("Warning can't load built-in font ??\n"); + else { + BLF_set(id); + BLF_size(12, 72); + BLF_size(11, 96); + BLF_size(14, 96); + } + #ifdef INTERNATIONAL if(U.transopts & USER_DOTRANSLATE) start_interface_font(); @@ -124,7 +136,6 @@ int UI_DrawString(BMF_Font* font, char *str, int translate) else if (!strcmp(code, "zh_CN")) string_to_utf8(str, utf_8, "GB2312"); /* Chinese */ } - return FTF_DrawString(utf_8, FTF_INPUT_UTF8); } else @@ -208,7 +219,6 @@ void set_interface_font(char *str) if(U.transopts & USER_DOTRANSLATE) { if(FTF_SetFont((unsigned char*)str, 0, U.fontsize)) { BLF_lang_set(U.language); - if(strlen(str) < FILE_MAXDIR) strcpy(U.fontname, str); G.ui_international = TRUE; } diff --git a/source/blender/editors/space_info/Makefile b/source/blender/editors/space_info/Makefile index 31401d8f628..13f7a0d169f 100644 --- a/source/blender/editors/space_info/Makefile +++ b/source/blender/editors/space_info/Makefile @@ -46,6 +46,7 @@ CPPFLAGS += -I../../blenlib CPPFLAGS += -I../../makesdna CPPFLAGS += -I../../imbuf CPPFLAGS += -I../../python +CPPFLAGS += -I../../blenfont CPPFLAGS += -I$(NAN_GUARDEDALLOC)/include # own include diff --git a/source/blender/editors/space_info/space_info.c b/source/blender/editors/space_info/space_info.c index 8b01080495b..141127d7eb5 100644 --- a/source/blender/editors/space_info/space_info.c +++ b/source/blender/editors/space_info/space_info.c @@ -48,6 +48,7 @@ #include "ED_screen.h" #include "BIF_gl.h" +#include "BLF_api.h" #include "WM_api.h" #include "WM_types.h" @@ -141,8 +142,29 @@ static void info_main_area_draw(const bContext *C, ARegion *ar) UI_view2d_view_ortho(C, v2d); /* data... */ + // XXX 2.50 Testing new font library - Diego + glColor3f(1.0, 0.0, 0.0); + BLF_aspect(1.0); + + BLF_size(14, 96); + BLF_position(5.0, 5.0, 0.0); + BLF_draw("Hello Blender, size 14, dpi 96"); + + glColor3f(0.0, 0.0, 1.0); + BLF_size(11, 96); + BLF_position(200.0, 50.0, 0.0); + BLF_draw("Another Hello Blender, size 11 and dpi 96!!"); + + glColor3f(0.8, 0.0, 0.7); + BLF_size(12, 72); + BLF_position(5.0, 100.0, 0.0); + BLF_draw("Hello World, size 12, dpi 72"); - + glColor3f(0.8, 0.7, 0.5); + BLF_size(12, 96); + BLF_position(5.0, 200.0, 0.0); + BLF_draw("And this make a new glyph cache!!"); + /* reset view matrix */ UI_view2d_view_restore(C); diff --git a/source/blender/windowmanager/intern/wm_files.c b/source/blender/windowmanager/intern/wm_files.c index d4501c88e15..cf93b4f0df3 100644 --- a/source/blender/windowmanager/intern/wm_files.c +++ b/source/blender/windowmanager/intern/wm_files.c @@ -589,6 +589,9 @@ int WM_read_homefile(bContext *C, wmOperator *op) strcpy(G.sce, scestr); /* restore */ + BLF_lang_init(); + BLF_init(); + init_userdef_themes(); /* When loading factory settings, the reset solid OpenGL lights need to be applied. */ @@ -598,8 +601,6 @@ int WM_read_homefile(bContext *C, wmOperator *op) G.save_over = 0; // start with save preference untitled.blend G.fileflags &= ~G_FILE_AUTOPLAY; /* disable autoplay in .B.blend... */ // mainwindow_set_filename_to_title(""); // empty string re-initializes title to "Blender" - - BLF_lang_init(); // refresh_interface_font(); diff --git a/source/blender/windowmanager/intern/wm_init_exit.c b/source/blender/windowmanager/intern/wm_init_exit.c index 9f56cfa9bd1..df3ad0d6d5c 100644 --- a/source/blender/windowmanager/intern/wm_init_exit.c +++ b/source/blender/windowmanager/intern/wm_init_exit.c @@ -223,8 +223,10 @@ void WM_exit(bContext *C) // free_imagepaint(); // fsmenu_free(); - + + BLF_exit(); BLF_lang_exit(); + RE_FreeAllRender(); // free_txt_data(); |