The GRRLIB_LoadTTF function is now returning NULL if it fails to load the font.

This commit is contained in:
Crayon2000 2015-09-20 21:11:56 -04:00
parent 30c060518c
commit 080dd9b7fd
5 changed files with 30 additions and 23 deletions

View file

@ -81,7 +81,9 @@ GRRLIB_texImg* GRRLIB_LoadTextureFromFile(const char *filename) {
unsigned char *data;
// return NULL it load fails
if (GRRLIB_LoadFile(filename, &data) <= 0) return NULL;
if (GRRLIB_LoadFile(filename, &data) <= 0) {
return NULL;
}
// Convert to texture
tex = GRRLIB_LoadTexture(data);

View file

@ -370,8 +370,9 @@ GRRLIB_texImg* GRRLIB_LoadTextureJPGEx (const u8 *my_jpg, const int my_size) {
GRRLIB_texImg *my_texture = calloc(1, sizeof(GRRLIB_texImg));
unsigned int i;
if(my_texture == NULL)
if (my_texture == NULL) {
return NULL;
}
jpeg_create_decompress(&cinfo);
cinfo.err = jpeg_std_error(&jerr);

View file

@ -54,13 +54,15 @@ void GRRLIB_ExitTTF (void) {
* Load a TTF from a buffer.
* @param file_base Buffer with TTF data. You must not deallocate the memory before calling GRRLIB_FreeTTF.
* @param file_size Size of the TTF buffer.
* @return A handle to a given TTF font object.
* @return A handle to a given TTF font object or NULL if it fails to load the font.
* @see GRRLIB_FreeTTF
*/
GRRLIB_ttfFont* GRRLIB_LoadTTF (const u8* file_base, s32 file_size) {
FT_Face Face;
if (FT_New_Memory_Face(ftLibrary, file_base, file_size, 0, &Face)) {
return NULL;
}
GRRLIB_ttfFont* myFont = (GRRLIB_ttfFont*)malloc(sizeof(GRRLIB_ttfFont));
FT_New_Memory_Face(ftLibrary, file_base, file_size, 0, &Face);
myFont->kerning = FT_HAS_KERNING(Face);
/*
if (FT_Set_Pixel_Sizes(Face, 0, fontSize)) {
@ -76,7 +78,7 @@ GRRLIB_ttfFont* GRRLIB_LoadTTF (const u8* file_base, s32 file_size) {
* @param myFont A TTF.
*/
void GRRLIB_FreeTTF (GRRLIB_ttfFont *myFont) {
if(myFont) {
if (myFont != NULL) {
FT_Done_Face(myFont->face);
free(myFont);
myFont = NULL;
@ -93,8 +95,9 @@ void GRRLIB_FreeTTF (GRRLIB_ttfFont *myFont) {
* @param color Text color in RGBA format.
*/
void GRRLIB_PrintfTTF(int x, int y, GRRLIB_ttfFont *myFont, const char *string, unsigned int fontSize, const u32 color) {
if(myFont == NULL || string == NULL)
if (myFont == NULL || string == NULL) {
return;
}
size_t length = strlen(string) + 1;
wchar_t *utf32 = (wchar_t*)malloc(length * sizeof(wchar_t));
@ -119,8 +122,9 @@ void GRRLIB_PrintfTTF(int x, int y, GRRLIB_ttfFont *myFont, const char *string,
* @param color Text color in RGBA format.
*/
void GRRLIB_PrintfTTFW(int x, int y, GRRLIB_ttfFont *myFont, const wchar_t *utf32, unsigned int fontSize, const u32 color) {
if(myFont == NULL || utf32 == NULL)
if (myFont == NULL || utf32 == NULL) {
return;
}
FT_Face Face = (FT_Face)myFont->face;
int penX = 0;