mirror of
https://github.com/libretro/RetroArch
synced 2025-02-28 22:13:51 +00:00
freetype.c: fix some memory corruption issues.
This commit is contained in:
parent
7dcb57f22d
commit
150a0138d5
@ -95,7 +95,7 @@ static unsigned font_renderer_update_atlas(ft_font_renderer_t *handle, FT_ULong
|
|||||||
uint8_t *dst = NULL;
|
uint8_t *dst = NULL;
|
||||||
struct font_glyph *glyph = NULL;
|
struct font_glyph *glyph = NULL;
|
||||||
|
|
||||||
if(charcode > 0x10000)
|
if(charcode > 0xFFFF)
|
||||||
return 0;
|
return 0;
|
||||||
if(handle->uc_to_id[charcode])
|
if(handle->uc_to_id[charcode])
|
||||||
return handle->uc_to_id[charcode];
|
return handle->uc_to_id[charcode];
|
||||||
@ -153,7 +153,6 @@ static unsigned font_renderer_update_atlas(ft_font_renderer_t *handle, FT_ULong
|
|||||||
dst[c] = src[c];
|
dst[c] = src[c];
|
||||||
}
|
}
|
||||||
|
|
||||||
handle->usage_counter++;
|
|
||||||
return id;
|
return id;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -166,7 +165,7 @@ static const struct font_glyph *font_renderer_ft_get_glyph(
|
|||||||
if (!handle)
|
if (!handle)
|
||||||
return NULL;
|
return NULL;
|
||||||
|
|
||||||
if(code > 0x10000)
|
if(code > 0xFFFF)
|
||||||
return NULL;
|
return NULL;
|
||||||
|
|
||||||
id = handle->uc_to_id[code];
|
id = handle->uc_to_id[code];
|
||||||
@ -179,20 +178,35 @@ static const struct font_glyph *font_renderer_ft_get_glyph(
|
|||||||
return &handle->glyphs[id];
|
return &handle->glyphs[id];
|
||||||
}
|
}
|
||||||
|
|
||||||
static bool font_renderer_create_atlas(ft_font_renderer_t *handle)
|
static bool font_renderer_create_atlas(ft_font_renderer_t *handle, int max_glyph_width, int max_glyph_height)
|
||||||
{
|
{
|
||||||
unsigned i;
|
unsigned i, id;
|
||||||
|
handle->max_glyph_width = max_glyph_width;
|
||||||
|
handle->max_glyph_height = max_glyph_height;
|
||||||
|
handle->atlas.width = handle->max_glyph_width * FT_ATLAS_COLS;
|
||||||
|
handle->atlas.height = handle->max_glyph_height * FT_ATLAS_ROWS;
|
||||||
|
|
||||||
|
handle->atlas.buffer = (uint8_t*)
|
||||||
|
calloc(handle->atlas.width * handle->atlas.height, 1);
|
||||||
|
|
||||||
|
if (!handle->atlas.buffer)
|
||||||
|
return false;
|
||||||
|
|
||||||
|
|
||||||
|
handle->usage_counter = 1;
|
||||||
for (i = 0; i < 256; i++)
|
for (i = 0; i < 256; i++)
|
||||||
if(font_renderer_update_atlas(handle, i) < 0)
|
{
|
||||||
return false;
|
id = font_renderer_update_atlas(handle, i);
|
||||||
|
if(id)
|
||||||
|
handle->last_used[id] = handle->usage_counter++;
|
||||||
|
}
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
#include "locale.h"
|
|
||||||
static void *font_renderer_ft_init(const char *font_path, float font_size)
|
static void *font_renderer_ft_init(const char *font_path, float font_size)
|
||||||
{
|
{
|
||||||
|
int i;
|
||||||
FT_Error err;
|
FT_Error err;
|
||||||
|
|
||||||
ft_font_renderer_t *handle = (ft_font_renderer_t*)
|
ft_font_renderer_t *handle = (ft_font_renderer_t*)
|
||||||
@ -220,19 +234,8 @@ static void *font_renderer_ft_init(const char *font_path, float font_size)
|
|||||||
if (err)
|
if (err)
|
||||||
goto error;
|
goto error;
|
||||||
|
|
||||||
/* TODO: find a better way to determine onmax_glyph_width/height */
|
/* TODO: find a better way to determine nmax_glyph_width/height */
|
||||||
handle->max_glyph_width = font_size;
|
if (!font_renderer_create_atlas(handle, font_size, font_size))
|
||||||
handle->max_glyph_height = font_size;
|
|
||||||
handle->atlas.width = handle->max_glyph_width * 2 * FT_ATLAS_COLS;
|
|
||||||
handle->atlas.height = handle->max_glyph_height * 2 * FT_ATLAS_ROWS;
|
|
||||||
|
|
||||||
handle->atlas.buffer = (uint8_t*)
|
|
||||||
calloc(handle->atlas.width * handle->atlas.height, 1);
|
|
||||||
|
|
||||||
if (!handle->atlas.buffer)
|
|
||||||
goto error;
|
|
||||||
|
|
||||||
if (!font_renderer_create_atlas(handle))
|
|
||||||
goto error;
|
goto error;
|
||||||
|
|
||||||
return handle;
|
return handle;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user