Skip to content

Commit

Permalink
font driver: expose line height
Browse files Browse the repository at this point in the history
  • Loading branch information
natinusala committed Feb 17, 2019
1 parent dfcb1ef commit 631f9e6
Show file tree
Hide file tree
Showing 12 changed files with 130 additions and 3 deletions.
11 changes: 11 additions & 0 deletions gfx/drivers_font/ctr_font.c
Original file line number Diff line number Diff line change
Expand Up @@ -446,6 +446,16 @@ static const struct font_glyph* ctr_font_get_glyph(
return font->font_driver->get_glyph((void*)font->font_driver, code);
}

static int ctr_font_get_line_height(void *data)
{
ctr_font_t* font = (ctr_font_t*)data;

if (!font || !font->font_driver || !font->font_data)
return -1;

return font->font_driver->get_line_height(font->font_data);
}

font_renderer_t ctr_font =
{
ctr_font_init_font,
Expand All @@ -456,4 +466,5 @@ font_renderer_t ctr_font =
NULL, /* bind_block */
NULL, /* flush_block */
ctr_font_get_message_width,
ctr_font_get_line_height
};
11 changes: 11 additions & 0 deletions gfx/drivers_font/d3d10_font.c
Original file line number Diff line number Diff line change
Expand Up @@ -362,6 +362,16 @@ static const struct font_glyph* d3d10_font_get_glyph(void *data, uint32_t code)
return font->font_driver->get_glyph((void*)font->font_driver, code);
}

static int d3d10_font_get_line_height(void *data)
{
d3d10_font_t* font = (d3d10_font_t*)data;

if (!font || !font->font_driver || !font->font_data)
return -1;

return font->font_driver->get_line_height(font->font_data);
}

font_renderer_t d3d10_font = {
d3d10_font_init_font,
d3d10_font_free_font,
Expand All @@ -371,4 +381,5 @@ font_renderer_t d3d10_font = {
NULL, /* bind_block */
NULL, /* flush */
d3d10_font_get_message_width,
d3d10_font_get_line_height
};
11 changes: 11 additions & 0 deletions gfx/drivers_font/d3d11_font.c
Original file line number Diff line number Diff line change
Expand Up @@ -359,6 +359,16 @@ static const struct font_glyph* d3d11_font_get_glyph(void *data, uint32_t code)
return font->font_driver->get_glyph((void*)font->font_driver, code);
}

static int d3d11_font_get_line_height(void *data)
{
d3d11_font_t* font = (d3d11_font_t*)data;

if (!font || !font->font_driver || !font->font_data)
return -1;

return font->font_driver->get_line_height(font->font_data);
}

font_renderer_t d3d11_font = {
d3d11_font_init_font,
d3d11_font_free_font,
Expand All @@ -368,4 +378,5 @@ font_renderer_t d3d11_font = {
NULL, /* bind_block */
NULL, /* flush */
d3d11_font_get_message_width,
d3d11_font_get_line_height
};
11 changes: 11 additions & 0 deletions gfx/drivers_font/d3d12_font.c
Original file line number Diff line number Diff line change
Expand Up @@ -376,6 +376,16 @@ static const struct font_glyph* d3d12_font_get_glyph(
return font->font_driver->get_glyph((void*)font->font_driver, code);
}

static int d3d12_font_get_line_height(void *data)
{
d3d12_font_t* font = (d3d12_font_t*)data;

if (!font || !font->font_driver || !font->font_data)
return -1;

return font->font_driver->get_line_height(font->font_data);
}

font_renderer_t d3d12_font = {
d3d12_font_init_font,
d3d12_font_free_font,
Expand All @@ -385,4 +395,5 @@ font_renderer_t d3d12_font = {
NULL, /* bind_block */
NULL, /* flush */
d3d12_font_get_message_width,
d3d12_font_get_line_height
};
14 changes: 13 additions & 1 deletion gfx/drivers_font/gl1_raster_font.c
Original file line number Diff line number Diff line change
Expand Up @@ -560,6 +560,17 @@ static void gl1_raster_font_bind_block(void *data, void *userdata)
font->block = block;
}


static int gl1_get_line_height(void *data)
{
gl1_raster_t *font = (gl1_raster_t*)data;

if (!font || !font->font_driver || !font->font_data)
return -1;

return font->font_driver->get_line_height(font->font_data);
}

font_renderer_t gl1_raster_font = {
gl1_raster_font_init_font,
gl1_raster_font_free_font,
Expand All @@ -568,5 +579,6 @@ font_renderer_t gl1_raster_font = {
gl1_raster_font_get_glyph,
gl1_raster_font_bind_block,
gl1_raster_font_flush_block,
gl1_get_message_width
gl1_get_message_width,
gl1_get_line_height
};
13 changes: 12 additions & 1 deletion gfx/drivers_font/gl_raster_font.c
Original file line number Diff line number Diff line change
Expand Up @@ -549,6 +549,16 @@ static void gl_raster_font_bind_block(void *data, void *userdata)
font->block = block;
}

static int gl_get_line_height(void *data)
{
gl_raster_t *font = (gl_raster_t*)data;

if (!font || !font->font_driver || !font->font_data)
return -1;

return font->font_driver->get_line_height(font->font_data);
}

font_renderer_t gl_raster_font = {
gl_raster_font_init_font,
gl_raster_font_free_font,
Expand All @@ -557,5 +567,6 @@ font_renderer_t gl_raster_font = {
gl_raster_font_get_glyph,
gl_raster_font_bind_block,
gl_raster_font_flush_block,
gl_get_message_width
gl_get_message_width,
gl_get_line_height
};
10 changes: 10 additions & 0 deletions gfx/drivers_font/switch_font.c
Original file line number Diff line number Diff line change
Expand Up @@ -341,6 +341,15 @@ static void switch_font_bind_block(void *data, void *userdata)
(void)data;
}

static int switch_font_get_line_height(void *data)
{
switch_font_t *font = (switch_font_t *)data;
if (!font || !font->font_driver || !font->font_data)
return -1;

return font->font_driver->get_line_height(font->font_data);
}

font_renderer_t switch_font =
{
switch_font_init_font,
Expand All @@ -351,4 +360,5 @@ font_renderer_t switch_font =
switch_font_bind_block,
NULL, /* flush_block */
switch_font_get_message_width,
switch_font_get_line_height
};
11 changes: 11 additions & 0 deletions gfx/drivers_font/vita2d_font.c
Original file line number Diff line number Diff line change
Expand Up @@ -347,6 +347,16 @@ static const struct font_glyph *vita2d_font_get_glyph(
return font->font_driver->get_glyph((void*)font->font_driver, code);
}

static int vita2d_font_get_line_height(void *data)
{
vita_font_t *font = (vita_font_t*)data;

if (!font || !font->font_driver || !font->font_data)
return -1;

return font->font_driver->get_line_height(font->font_data);
}

font_renderer_t vita2d_vita_font = {
vita2d_font_init_font,
vita2d_font_free_font,
Expand All @@ -356,4 +366,5 @@ font_renderer_t vita2d_vita_font = {
NULL, /* bind_block */
NULL, /* flush */
vita2d_font_get_message_width,
vita2d_font_get_line_height
};
13 changes: 12 additions & 1 deletion gfx/drivers_font/vulkan_raster_font.c
Original file line number Diff line number Diff line change
Expand Up @@ -435,6 +435,16 @@ static const struct font_glyph *vulkan_raster_font_get_glyph(
return glyph;
}

static int vulkan_get_line_height(void *data)
{
vulkan_raster_t *font = (vulkan_raster_t*)data;

if (!font || !font->font_driver || !font->font_data)
return -1;

return font->font_driver->get_line_height(font->font_data);
}

font_renderer_t vulkan_raster_font = {
vulkan_raster_font_init_font,
vulkan_raster_font_free_font,
Expand All @@ -443,5 +453,6 @@ font_renderer_t vulkan_raster_font = {
vulkan_raster_font_get_glyph,
NULL, /* bind_block */
NULL, /* flush_block */
vulkan_get_message_width
vulkan_get_message_width,
vulkan_get_line_height
};
11 changes: 11 additions & 0 deletions gfx/drivers_font/wiiu_font.c
Original file line number Diff line number Diff line change
Expand Up @@ -374,6 +374,16 @@ static const struct font_glyph* wiiu_font_get_glyph(
return font->font_driver->get_glyph((void*)font->font_driver, code);
}

static int wiiu_font_get_line_height(void *data)
{
wiiu_font_t* font = (wiiu_font_t*)data;

if (!font || !font->font_driver || !font->font_data)
return -1;

return font->font_driver->get_line_height(font->font_data);
}

font_renderer_t wiiu_font =
{
wiiu_font_init_font,
Expand All @@ -384,4 +394,5 @@ font_renderer_t wiiu_font =
NULL, /* bind_block */
NULL, /* flush */
wiiu_font_get_message_width,
wiiu_font_get_line_height
};
14 changes: 14 additions & 0 deletions gfx/font_driver.c
Original file line number Diff line number Diff line change
Expand Up @@ -1043,6 +1043,20 @@ int font_driver_get_message_width(void *font_data,
return -1;
}

int font_driver_get_line_height(void *font_data, float scale)
{
font_data_t *font = (font_data_t*)(font_data ? font_data : video_font_driver);
int line_height;

/* First try the line height implementation */
if (font && font->renderer && font->renderer->get_line_height)
if ((line_height = font->renderer->get_line_height(font->renderer_data)) != -1)
return line_height * round(scale);

/* Else return an approximation (width of 'a') */
return font_driver_get_message_width(font_data, "a", 1, scale);
}

void font_driver_free(void *font_data)
{
font_data_t *font = (font_data_t*)font_data;
Expand Down
3 changes: 3 additions & 0 deletions gfx/font_driver.h
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,7 @@ typedef struct font_renderer
video_frame_info_t *video_info);

int (*get_message_width)(void *data, const char *msg, unsigned msg_len_full, float scale);
int (*get_line_height)(void* data);
} font_renderer_t;

typedef struct font_renderer_driver
Expand Down Expand Up @@ -156,6 +157,8 @@ void font_driver_init_osd(
enum font_driver_render_api api);
void font_driver_free_osd(void);

int font_driver_get_line_height(void *font_data, float scale);

extern font_renderer_t gl_raster_font;
extern font_renderer_t gl1_raster_font;
extern font_renderer_t libdbg_font;
Expand Down

0 comments on commit 631f9e6

Please sign in to comment.