From 56d427df653f217357487a21894e31e1a763d569 Mon Sep 17 00:00:00 2001 From: twinaphex Date: Fri, 21 Oct 2016 19:12:06 +0200 Subject: [PATCH] C89_BUILD fixes --- gfx/drivers_font_renderer/freetype.c | 44 ++++++++++++++++------------ menu/drivers/xmb.c | 18 ++++++------ 2 files changed, 34 insertions(+), 28 deletions(-) diff --git a/gfx/drivers_font_renderer/freetype.c b/gfx/drivers_font_renderer/freetype.c index f198ef8996..83caa0a9fe 100644 --- a/gfx/drivers_font_renderer/freetype.c +++ b/gfx/drivers_font_renderer/freetype.c @@ -90,19 +90,23 @@ static unsigned font_renderer_get_slot(ft_font_renderer_t *handle) static unsigned font_renderer_update_atlas(ft_font_renderer_t *handle, FT_ULong charcode) { + unsigned id, offset_x, offset_y; FT_GlyphSlot slot; + uint8_t *dst = NULL; + struct font_glyph *glyph = NULL; if(charcode > 0x10000) return 0; if(handle->uc_to_id[charcode]) return handle->uc_to_id[charcode]; - unsigned id = font_renderer_get_slot(handle); - handle->id_to_uc[id] = charcode; + id = font_renderer_get_slot(handle); + handle->id_to_uc[id] = charcode; handle->uc_to_id[charcode] = id; - handle->atlas.dirty = true; + handle->atlas.dirty = true; + + glyph = &handle->glyphs[id]; - struct font_glyph *glyph = &handle->glyphs[id]; memset(glyph, 0, sizeof(*glyph)) ; if (FT_Load_Char(handle->face, charcode, FT_LOAD_RENDER)) @@ -112,18 +116,18 @@ static unsigned font_renderer_update_atlas(ft_font_renderer_t *handle, FT_ULong slot = handle->face->glyph; /* Some glyphs can be blank. */ + glyph->width = slot->bitmap.width; + glyph->height = slot->bitmap.rows; - glyph->width = slot->bitmap.width; - glyph->height = slot->bitmap.rows; + glyph->advance_x = slot->advance.x >> 6; + glyph->advance_y = slot->advance.y >> 6; + glyph->draw_offset_x = slot->bitmap_left; + glyph->draw_offset_y = -slot->bitmap_top; - glyph->advance_x = slot->advance.x >> 6; - glyph->advance_y = slot->advance.y >> 6; - glyph->draw_offset_x = slot->bitmap_left; - glyph->draw_offset_y = -slot->bitmap_top; - - uint8_t *dst = NULL; - unsigned offset_x = (id % FT_ATLAS_COLS) * handle->max_glyph_width; - unsigned offset_y = (id / FT_ATLAS_COLS) * handle->max_glyph_height; + offset_x = (id % FT_ATLAS_COLS) + * handle->max_glyph_width; + offset_y = (id / FT_ATLAS_COLS) + * handle->max_glyph_height; handle->glyphs[id].atlas_offset_x = offset_x; handle->glyphs[id].atlas_offset_y = offset_y; @@ -149,14 +153,16 @@ static unsigned font_renderer_update_atlas(ft_font_renderer_t *handle, FT_ULong static const struct font_glyph *font_renderer_ft_get_glyph( void *data, uint32_t code) { + unsigned id; ft_font_renderer_t *handle = (ft_font_renderer_t*)data; + if (!handle) return NULL; if(code > 0x10000) return NULL; - unsigned id = handle->uc_to_id[code]; + id = handle->uc_to_id[code]; if(!id) id = font_renderer_update_atlas(handle, (FT_ULong)code); @@ -208,12 +214,12 @@ static void *font_renderer_ft_init(const char *font_path, float font_size) goto error; /* TODO: find a better way to determine onmax_glyph_width/height */ - handle->max_glyph_width = font_size; + handle->max_glyph_width = 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.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*) + handle->atlas.buffer = (uint8_t*) calloc(handle->atlas.width * handle->atlas.height, 1); if (!handle->atlas.buffer) diff --git a/menu/drivers/xmb.c b/menu/drivers/xmb.c index 0633a4819d..f369b319c3 100644 --- a/menu/drivers/xmb.c +++ b/menu/drivers/xmb.c @@ -1767,25 +1767,25 @@ char* word_wrap (char* buffer, char* string, int line_width) { while(i < strlen( string ) ) { - // copy string until the end of the line is reached + /* copy string until the end of the line is reached */ for ( counter = 1; counter <= line_width; counter++ ) { - // check if end of string reached + /* check if end of string reached */ if ( i == strlen( string ) ) { buffer[ i ] = 0; return buffer; } + buffer[ i ] = string[ i ]; - // check for newlines embedded in the original input - // and reset the index + + /* check for newlines embedded in the original input + * and reset the index */ if ( buffer[ i ] == '\n' ) - { counter = 1; - } i++; } - // check for whitespace + /* check for whitespace */ if ( isspace( string[ i ] ) ) { buffer[i] = '\n'; @@ -1793,13 +1793,13 @@ char* word_wrap (char* buffer, char* string, int line_width) { } else { - // check for nearest whitespace back in string + /* check for nearest whitespace back in string */ for ( k = i; k > 0; k--) { if ( isspace( string[ k ] ) ) { buffer[ k ] = '\n'; - // set string index back to character after this one + /* set string index back to character after this one */ i = k + 1; break; }