free font style memory

This commit is contained in:
Albert Cahalan 2005-01-02 20:46:03 +00:00
parent eed601cc22
commit cf711e956e

View file

@ -1467,11 +1467,13 @@ typedef struct family_info {
} family_info; } family_info;
static TTF_Font * medium_font, * small_font, * large_font, * locale_font; static TTF_Font * medium_font, * small_font, * large_font, * locale_font;
static style_info * user_font_styles[MAX_FONTS];
static family_info * user_font_families[MAX_FONTS]; static family_info * user_font_families[MAX_FONTS];
static int num_font_styles;
static int num_font_families; static int num_font_families;
static style_info **user_font_styles;
static int num_font_styles;
static int num_font_styles_max;
static TTF_Font *getfonthandle(int desire) static TTF_Font *getfonthandle(int desire)
{ {
@ -1833,12 +1835,25 @@ static void groupfonts(void)
{ {
if(++high >= num_font_styles) if(++high >= num_font_styles)
break; break;
if(compar_fontgroup(&user_font_styles[low],&user_font_styles[high])) if(compar_fontgroup(user_font_styles+low, user_font_styles+high))
break; break;
} }
groupfonts_range(user_font_styles+low,high-low); groupfonts_range(user_font_styles+low, high-low);
low = high; low = high;
} }
i = num_font_styles;
while(i--)
{
free(user_font_styles[i]->filename);
free(user_font_styles[i]->directory);
free(user_font_styles[i]->family);
free(user_font_styles[i]->style);
free(user_font_styles[i]);
}
free(user_font_styles);
user_font_styles = NULL; // just to catch bugs
qsort(user_font_families, num_font_families, sizeof user_font_families[0], compar_fontkiller); qsort(user_font_families, num_font_families, sizeof user_font_families[0], compar_fontkiller);
low = 0; low = 0;
for(;;) for(;;)
@ -14120,7 +14135,7 @@ static void loadfonts(const char * const dir, int fatal)
/* Read directory for images: */ /* Read directory for fonts: */
num_files = 0; num_files = 0;
do do
@ -14160,21 +14175,25 @@ static void loadfonts(const char * const dir, int fatal)
/* Do something with each file (load TTFs): */ /* Do something with each file (load TTFs): */
for (i = 0; i < num_files && num_font_styles + 3 < MAX_FONTS; i++) for (i = 0; i < num_files /* && num_font_styles + 3 < MAX_FONTS */; i++)
{ {
if (num_font_styles==num_font_styles_max)
{
num_font_styles_max = num_font_styles_max * 5 / 4 + 30;
user_font_styles = realloc(user_font_styles, num_font_styles_max * sizeof *user_font_styles);
}
/* Ignore things starting with "." (e.g., "." and ".." dirs): */ /* Ignore things starting with "." (e.g., "." and ".." dirs): */
if (d_names[i][0]!='.')
if (strstr(d_names[i], ".") != d_names[i])
{ {
/* If it's a directory, recurse down into it: */ /* If it's a directory, recurse down into it: */
snprintf(fname, sizeof(fname), "%s/%s", dir, d_names[i]); snprintf(fname, sizeof(fname), "%s/%s", dir, d_names[i]);
debug(fname); debug(fname);
stat(fname, &sbuf); stat(fname, &sbuf);
if (S_ISDIR(sbuf.st_mode)) if (S_ISDIR(sbuf.st_mode))
loadfonts(fname,fatal); loadfonts(fname,fatal);
// Loadable: TrueType (.ttf), Type1 (.pfa and .pfb), and various useless bitmap fonts.
// Compressed files (with .gz or .bz2) might also work.
if (strstr(d_names[i], ".ttf") || strstr(d_names[i], ".pfa") || strstr(d_names[i], ".pfb")) if (strstr(d_names[i], ".ttf") || strstr(d_names[i], ".pfa") || strstr(d_names[i], ".pfb"))
{ {
//printf("Loading font: %s/%s\n", dir, d_names[i]); //printf("Loading font: %s/%s\n", dir, d_names[i]);
@ -14200,15 +14219,15 @@ static void loadfonts(const char * const dir, int fatal)
free(d_names[i]); free(d_names[i]);
} }
#if 0
/* Give warning if too many files were found (e.g., some not loaded): */ /* Give warning if too many files were found (e.g., some not loaded): */
if (num_font_styles == MAX_FONTS) if (num_font_styles == MAX_FONTS)
{ {
fprintf(stderr, fprintf(stderr,
"\nWarning: Reached maximum fonts (%d) which can be loaded.\n\n", "\nWarning: Reached maximum fonts (%d) which can be loaded.\n\n",
MAX_FONTS); MAX_FONTS);
} }
#endif
} }