mirror of
https://github.com/GRRLIB/GRRLIB.git
synced 2024-11-22 15:02:20 +00:00
The GRRLIB_LoadTTF function is now returning NULL if it fails to load the font.
This commit is contained in:
parent
30c060518c
commit
080dd9b7fd
5 changed files with 30 additions and 23 deletions
|
@ -81,7 +81,9 @@ GRRLIB_texImg* GRRLIB_LoadTextureFromFile(const char *filename) {
|
||||||
unsigned char *data;
|
unsigned char *data;
|
||||||
|
|
||||||
// return NULL it load fails
|
// return NULL it load fails
|
||||||
if (GRRLIB_LoadFile(filename, &data) <= 0) return NULL;
|
if (GRRLIB_LoadFile(filename, &data) <= 0) {
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
// Convert to texture
|
// Convert to texture
|
||||||
tex = GRRLIB_LoadTexture(data);
|
tex = GRRLIB_LoadTexture(data);
|
||||||
|
|
|
@ -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));
|
GRRLIB_texImg *my_texture = calloc(1, sizeof(GRRLIB_texImg));
|
||||||
unsigned int i;
|
unsigned int i;
|
||||||
|
|
||||||
if(my_texture == NULL)
|
if (my_texture == NULL) {
|
||||||
return NULL;
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
jpeg_create_decompress(&cinfo);
|
jpeg_create_decompress(&cinfo);
|
||||||
cinfo.err = jpeg_std_error(&jerr);
|
cinfo.err = jpeg_std_error(&jerr);
|
||||||
|
|
|
@ -54,13 +54,15 @@ void GRRLIB_ExitTTF (void) {
|
||||||
* Load a TTF from a buffer.
|
* 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_base Buffer with TTF data. You must not deallocate the memory before calling GRRLIB_FreeTTF.
|
||||||
* @param file_size Size of the TTF buffer.
|
* @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
|
* @see GRRLIB_FreeTTF
|
||||||
*/
|
*/
|
||||||
GRRLIB_ttfFont* GRRLIB_LoadTTF (const u8* file_base, s32 file_size) {
|
GRRLIB_ttfFont* GRRLIB_LoadTTF (const u8* file_base, s32 file_size) {
|
||||||
FT_Face Face;
|
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));
|
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);
|
myFont->kerning = FT_HAS_KERNING(Face);
|
||||||
/*
|
/*
|
||||||
if (FT_Set_Pixel_Sizes(Face, 0, fontSize)) {
|
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.
|
* @param myFont A TTF.
|
||||||
*/
|
*/
|
||||||
void GRRLIB_FreeTTF (GRRLIB_ttfFont *myFont) {
|
void GRRLIB_FreeTTF (GRRLIB_ttfFont *myFont) {
|
||||||
if(myFont) {
|
if (myFont != NULL) {
|
||||||
FT_Done_Face(myFont->face);
|
FT_Done_Face(myFont->face);
|
||||||
free(myFont);
|
free(myFont);
|
||||||
myFont = NULL;
|
myFont = NULL;
|
||||||
|
@ -93,8 +95,9 @@ void GRRLIB_FreeTTF (GRRLIB_ttfFont *myFont) {
|
||||||
* @param color Text color in RGBA format.
|
* @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) {
|
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;
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
size_t length = strlen(string) + 1;
|
size_t length = strlen(string) + 1;
|
||||||
wchar_t *utf32 = (wchar_t*)malloc(length * sizeof(wchar_t));
|
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.
|
* @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) {
|
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;
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
FT_Face Face = (FT_Face)myFont->face;
|
FT_Face Face = (FT_Face)myFont->face;
|
||||||
int penX = 0;
|
int penX = 0;
|
||||||
|
|
Loading…
Reference in a new issue