1
0
mirror of https://github.com/libretro/RetroArch synced 2025-02-15 00:40:06 +00:00

(Freetype) Use FT_New_Memory_Face instead of FT_New_Face to load

font from memory - first read it from file to memory beforehand -
this solves an asset extraction issue when selecting 'Update Assets' -
apparently FT_New_Face keeps an open file handle to the font file which
prevents it from being overwritten/deleted while the program is still
running.
TODO/FIXME - move file loading code out of the font renderer init function
and move it higher level
This commit is contained in:
libretroadmin 2022-06-26 20:38:46 +02:00
parent 367dfd6e71
commit 128753c81d

@ -277,7 +277,7 @@ static void *font_renderer_ft_init(const char *font_path, float font_size)
if (!OSGetSharedData(SHARED_FONT_DEFAULT, 0, &font_data, &font_size))
goto error;
err = FT_New_Memory_Face(handle->lib, font_data, font_size, 0, &handle->face);
err = FT_New_Memory_Face(handle->lib, (const FT_Byte*)font_data, (FT_Long)font_size, (FT_Long)0, &handle->face);
}
else
#elif defined(HAVE_FONTCONFIG_SUPPORT)
@ -285,6 +285,8 @@ static void *font_renderer_ft_init(const char *font_path, float font_size)
if (!*font_path || strstr(font_path, "fallback"))
{
FcValue locale_boxed;
uint8_t* font_data = NULL;
int64_t font_size = 0;
FcPattern *found = NULL;
FcConfig* config = FcInitLoadConfigAndFonts();
FcResult result = FcResultNoMatch;
@ -319,10 +321,11 @@ static void *font_renderer_ft_init(const char *font_path, float font_size)
goto error;
if (FcPatternGetInteger(found, FC_INDEX, 0, &face_index) != FcResultMatch)
goto error;
if (!filestream_read_file((const char*)_font_path, (void**)&font_data, &font_size))
goto error;
/* Initialize font renderer */
err = FT_New_Face(handle->lib, (const char*)_font_path,
face_index, &handle->face);
err = FT_New_Memory_Face(handle->lib, (const FT_Byte*)font_data, (FT_Long)font_size, (FT_Long)face_index, &handle->face);
/* free up fontconfig internal structures */
FcPatternDestroy(pattern);
@ -333,9 +336,13 @@ static void *font_renderer_ft_init(const char *font_path, float font_size)
else
#endif
{
uint8_t* font_data = NULL;
int64_t font_size = 0;
if (!path_is_valid(font_path))
goto error;
err = FT_New_Face(handle->lib, font_path, 0, &handle->face);
if (!filestream_read_file(font_path, (void**)&font_data, &font_size))
goto error;
err = FT_New_Memory_Face(handle->lib, (const FT_Byte*)font_data, (FT_Long)font_size, (FT_Long)0, &handle->face);
}
if (err)