Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBrecht Van Lommel <brechtvanlommel@pandora.be>2011-09-21 19:14:47 +0400
committerBrecht Van Lommel <brechtvanlommel@pandora.be>2011-09-21 19:14:47 +0400
commita12e06dc3591bc1e95372e08a08cf85fb53960e1 (patch)
tree7983f6602f1dbccd55717dea428683e0e52bb48d /source/blender/blenfont/intern
parent2dbfa5a3e4b54d59a6e71b01f8f4cebf1c220af7 (diff)
Blenfont: add BLF_unload function to unload/reload fonts.
Diffstat (limited to 'source/blender/blenfont/intern')
-rw-r--r--source/blender/blenfont/intern/blf.c68
1 files changed, 45 insertions, 23 deletions
diff --git a/source/blender/blenfont/intern/blf.c b/source/blender/blenfont/intern/blf.c
index cccecd00bf7..ec0605236dd 100644
--- a/source/blender/blenfont/intern/blf.c
+++ b/source/blender/blenfont/intern/blf.c
@@ -61,10 +61,7 @@
#define BLF_MAX_FONT 16
/* Font array. */
-static FontBLF *global_font[BLF_MAX_FONT];
-
-/* Number of font. */
-static int global_font_num= 0;
+static FontBLF *global_font[BLF_MAX_FONT] = {0};
/* Default size and dpi, for BLF_draw_default. */
static int global_font_default= -1;
@@ -99,10 +96,12 @@ void BLF_exit(void)
FontBLF *font;
int i;
- for (i= 0; i < global_font_num; i++) {
+ for (i= 0; i < BLF_MAX_FONT; i++) {
font= global_font[i];
- if (font)
+ if (font) {
blf_font_free(font);
+ global_font[i]= NULL;
+ }
}
blf_font_exit();
@@ -113,7 +112,7 @@ void BLF_cache_clear(void)
FontBLF *font;
int i;
- for (i= 0; i < global_font_num; i++) {
+ for (i= 0; i < BLF_MAX_FONT; i++) {
font= global_font[i];
if (font)
blf_glyph_cache_clear(font);
@@ -130,6 +129,18 @@ static int blf_search(const char *name)
if (font && (!strcmp(font->name, name)))
return i;
}
+
+ return -1;
+}
+
+static int blf_search_available(void)
+{
+ int i;
+
+ for (i= 0; i < BLF_MAX_FONT; i++)
+ if(!global_font[i])
+ return i;
+
return -1;
}
@@ -149,7 +160,8 @@ int BLF_load(const char *name)
return i;
}
- if (global_font_num+1 >= BLF_MAX_FONT) {
+ i = blf_search_available();
+ if (i == -1) {
printf("Too many fonts!!!\n");
return -1;
}
@@ -168,9 +180,7 @@ int BLF_load(const char *name)
return -1;
}
- global_font[global_font_num]= font;
- i= global_font_num;
- global_font_num++;
+ global_font[i]= font;
return i;
}
@@ -186,7 +196,8 @@ int BLF_load_unique(const char *name)
/* Don't search in the cache!! make a new
* object font, this is for keep fonts threads safe.
*/
- if (global_font_num+1 >= BLF_MAX_FONT) {
+ i = blf_search_available();
+ if (i == -1) {
printf("Too many fonts!!!\n");
return -1;
}
@@ -205,9 +216,7 @@ int BLF_load_unique(const char *name)
return -1;
}
- global_font[global_font_num]= font;
- i= global_font_num;
- global_font_num++;
+ global_font[i]= font;
return i;
}
@@ -234,7 +243,8 @@ int BLF_load_mem(const char *name, unsigned char *mem, int mem_size)
return i;
}
- if (global_font_num+1 >= BLF_MAX_FONT) {
+ i = blf_search_available();
+ if (i == -1) {
printf("Too many fonts!!!\n");
return -1;
}
@@ -250,9 +260,7 @@ int BLF_load_mem(const char *name, unsigned char *mem, int mem_size)
return -1;
}
- global_font[global_font_num]= font;
- i= global_font_num;
- global_font_num++;
+ global_font[i]= font;
return i;
}
@@ -268,7 +276,8 @@ int BLF_load_mem_unique(const char *name, unsigned char *mem, int mem_size)
* Don't search in the cache, make a new object font!
* this is to keep the font thread safe.
*/
- if (global_font_num+1 >= BLF_MAX_FONT) {
+ i = blf_search_available();
+ if (i == -1) {
printf("Too many fonts!!!\n");
return -1;
}
@@ -284,12 +293,25 @@ int BLF_load_mem_unique(const char *name, unsigned char *mem, int mem_size)
return -1;
}
- global_font[global_font_num]= font;
- i= global_font_num;
- global_font_num++;
+ global_font[i]= font;
return i;
}
+void BLF_unload(const char *name)
+{
+ FontBLF *font;
+ int i;
+
+ for (i= 0; i < BLF_MAX_FONT; i++) {
+ font= global_font[i];
+
+ if (font && (!strcmp(font->name, name))) {
+ blf_font_free(font);
+ global_font[i]= NULL;
+ }
+ }
+}
+
void BLF_enable(int fontid, int option)
{
FontBLF *font= BLF_get(fontid);