Always echo to stderr if cannot TTF_OpenFont a TTF
This commit is contained in:
parent
b0e5051d14
commit
8d9ddebcd1
1 changed files with 11 additions and 14 deletions
25
src/fonts.c
25
src/fonts.c
|
|
@ -270,6 +270,7 @@ void TuxPaint_Font_CloseFont(TuxPaint_Font * tpf)
|
||||||
|
|
||||||
TuxPaint_Font *TuxPaint_Font_OpenFont(const char *pangodesc, const char *ttffilename, int size)
|
TuxPaint_Font *TuxPaint_Font_OpenFont(const char *pangodesc, const char *ttffilename, int size)
|
||||||
{
|
{
|
||||||
|
TTF_Font *ttf_font;
|
||||||
TuxPaint_Font *tpf = NULL;
|
TuxPaint_Font *tpf = NULL;
|
||||||
int i;
|
int i;
|
||||||
|
|
||||||
|
|
@ -336,9 +337,16 @@ TuxPaint_Font *TuxPaint_Font_OpenFont(const char *pangodesc, const char *ttffile
|
||||||
return NULL; /* bail on known problematic font types that cause TTF_OpenFont to crash */
|
return NULL; /* bail on known problematic font types that cause TTF_OpenFont to crash */
|
||||||
}
|
}
|
||||||
|
|
||||||
|
ttf_font = TTF_OpenFont(ttffilename, size);
|
||||||
|
|
||||||
|
if (ttf_font == NULL) {
|
||||||
|
fprintf(stderr, "Cannot open TTF font '%s' (size %d)\n", ttffilename, size);
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
tpf = (TuxPaint_Font *) malloc(sizeof(TuxPaint_Font));
|
tpf = (TuxPaint_Font *) malloc(sizeof(TuxPaint_Font));
|
||||||
tpf->typ = FONT_TYPE_TTF;
|
tpf->typ = FONT_TYPE_TTF;
|
||||||
tpf->ttf_font = TTF_OpenFont(ttffilename, size);
|
tpf->ttf_font = ttf_font;
|
||||||
tpf->desc = strdup(ttffilename);
|
tpf->desc = strdup(ttffilename);
|
||||||
|
|
||||||
#ifdef DEBUG
|
#ifdef DEBUG
|
||||||
|
|
@ -346,21 +354,10 @@ TuxPaint_Font *TuxPaint_Font_OpenFont(const char *pangodesc, const char *ttffile
|
||||||
fflush(stdout);
|
fflush(stdout);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
if (tpf->ttf_font == NULL)
|
|
||||||
{
|
|
||||||
#ifdef DEBUG
|
#ifdef DEBUG
|
||||||
printf("Failed to load %s: %s\n", ttffilename, SDL_GetError());
|
printf("Succeeded loading %s\n", ttffilename);
|
||||||
#endif
|
#endif
|
||||||
free(tpf);
|
tpf->height = TTF_FontHeight(tpf->ttf_font);
|
||||||
tpf = NULL;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
#ifdef DEBUG
|
|
||||||
printf("Succeeded loading %s\n", ttffilename);
|
|
||||||
#endif
|
|
||||||
tpf->height = TTF_FontHeight(tpf->ttf_font);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#ifdef DEBUG
|
#ifdef DEBUG
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue