RetroArch
font_driver.h
Go to the documentation of this file.
1 /* RetroArch - A frontend for libretro.
2  * Copyright (C) 2010-2014 - Hans-Kristian Arntzen
3  * Copyright (C) 2011-2017 - Daniel De Matteis
4  *
5  * RetroArch is free software: you can redistribute it and/or modify it under the terms
6  * of the GNU General Public License as published by the Free Software Found-
7  * ation, either version 3 of the License, or (at your option) any later version.
8  *
9  * RetroArch is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
10  * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
11  * PURPOSE. See the GNU General Public License for more details.
12  *
13  * You should have received a copy of the GNU General Public License along with RetroArch.
14  * If not, see <http://www.gnu.org/licenses/>.
15  */
16 
17 #ifndef __FONT_DRIVER_H__
18 #define __FONT_DRIVER_H__
19 
20 #include <stdint.h>
21 
22 #include <boolean.h>
23 #include <retro_common_api.h>
24 
25 #include "video_driver.h"
26 
28 
29 /* All coordinates and offsets are top-left oriented.
30  *
31  * This is a texture-atlas approach which allows text to
32  * be drawn in a single draw call.
33  *
34  * It is up to the code using this interface to actually
35  * generate proper vertex buffers and upload the atlas texture to GPU. */
36 
37 struct font_glyph
38 {
39  unsigned width;
40  unsigned height;
41 
42  /* Texel coordinate offset for top-left pixel of this glyph. */
43  unsigned atlas_offset_x;
44  unsigned atlas_offset_y;
45 
46  /* When drawing this glyph, apply an offset to
47  * current X/Y draw coordinate. */
50 
51  /* Advance X/Y draw coordinates after drawing this glyph. */
52  int advance_x;
53  int advance_y;
54 };
55 
56 struct font_atlas
57 {
58  uint8_t *buffer; /* Alpha channel. */
59  unsigned width;
60  unsigned height;
61  bool dirty;
62 };
63 
65 {
66  float x;
67  float y;
68  float scale;
69  /* Drop shadow color multiplier. */
70  float drop_mod;
71  /* Drop shadow offset.
72  * If both are 0, no drop shadow will be rendered. */
73  int drop_x, drop_y;
74  /* Drop shadow alpha */
75  float drop_alpha;
76  /* ABGR. Use the macros. */
80 };
81 
82 typedef struct font_renderer
83 {
84  void *(*init)(void *data, const char *font_path,
85  float font_size, bool is_threaded);
86  void (*free)(void *data, bool is_threaded);
89  void *data, const char *msg,
90  const struct font_params *params);
91  const char *ident;
92 
93  const struct font_glyph *(*get_glyph)(void *data, uint32_t code);
94  void (*bind_block)(void *data, void *block);
95  void (*flush)(unsigned width, unsigned height, void *data,
97 
98  int (*get_message_width)(void *data, const char *msg, unsigned msg_len_full, float scale);
100 
101 typedef struct font_renderer_driver
102 {
103  void *(*init)(const char *font_path, float font_size);
104 
105  struct font_atlas *(*get_atlas)(void *data);
106 
107  /* Returns NULL if no glyph for this code is found. */
108  const struct font_glyph *(*get_glyph)(void *data, uint32_t code);
109 
110  void (*free)(void *data);
111 
112  const char *(*get_default_font)(void);
113 
114  const char *ident;
115 
116  int (*get_line_height)(void* data);
118 
119 typedef struct
120 {
123  float size;
124 } font_data_t;
125 
126 /* font_path can be NULL for default font. */
128  const font_renderer_driver_t **drv,
129  void **handle,
130  const char *font_path, unsigned font_size);
131 
133  void *font_data, const char *msg, const struct font_params *params);
134 
135 void font_driver_bind_block(void *font_data, void *block);
136 
137 int font_driver_get_message_width(void *font_data, const char *msg, unsigned len, float scale);
138 
139 void font_driver_flush(unsigned width, unsigned height, void *font_data,
141 
142 void font_driver_free(void *font_data);
143 
145  void *video_data,
146  const char *font_path,
147  float font_size,
148  bool threading_hint,
149  bool is_threaded,
151 
153  void *video_data,
154  bool threading_hint,
155  bool is_threaded,
157 void font_driver_free_osd(void);
158 
177 
183 
185 
186 #endif
font_renderer_driver_t coretext_font_renderer
Definition: coretext.c:350
void font_driver_init_osd(void *video_data, bool threading_hint, bool is_threaded, enum font_driver_render_api api)
Definition: font_driver.c:1027
font_renderer_driver_t stb_font_renderer
Definition: stb.c:235
font_data_t * font_driver_init_first(void *video_data, const char *font_path, float font_size, bool threading_hint, bool is_threaded, enum font_driver_render_api api)
Definition: font_driver.c:993
void(* flush)(unsigned width, unsigned height, void *data, video_frame_info_t *video_info)
Definition: font_driver.h:95
float scale
Definition: font_driver.h:68
#define RETRO_BEGIN_DECLS
Definition: retro_common_api.h:41
font_renderer_t d3d10_font
Definition: d3d10_font.c:365
unsigned atlas_offset_x
Definition: font_driver.h:43
font_renderer_t metal_raster_font
Definition: metal_raster_font.m:542
GLenum const GLfloat * params
Definition: glext.h:6297
int font_renderer_create_default(const font_renderer_driver_t **drv, void **handle, const char *font_path, unsigned font_size)
Definition: font_driver.c:49
int drop_x
Definition: font_driver.h:73
font_renderer_t gl_raster_font
Definition: gl_raster_font.c:556
text_alignment
Definition: video_defines.h:103
font_renderer_t vulkan_raster_font
Definition: vulkan_raster_font.c:439
GLenum GLsizei len
Definition: glext.h:7389
float size
Definition: font_driver.h:123
uint8_t * buffer
Definition: font_driver.h:58
font_renderer_t d3d_xbox360_font
Definition: xdk360_fonts.cpp:676
static const float font_size
Definition: config.def.h:434
const portMappingElt code
Definition: portlistingparse.c:17
static tesseract::TessBaseAPI * api
Definition: tess_get_text.cpp:7
GLenum GLenum GLenum GLenum GLenum scale
Definition: glext.h:9939
int draw_offset_y
Definition: font_driver.h:49
int advance_y
Definition: font_driver.h:53
unsigned atlas_offset_y
Definition: font_driver.h:44
typedef void(__stdcall *PFN_DESTRUCTION_CALLBACK)(void *pData)
void(* render_msg)(video_frame_info_t *video_info, void *data, const char *msg, const struct font_params *params)
Definition: font_driver.h:87
font_renderer_t d3d12_font
Definition: d3d12_font.c:379
unsigned height
Definition: font_driver.h:40
font_renderer_t wiiu_font
Definition: wiiu_font.c:380
font_renderer_t switch_font
Definition: switch_font.c:340
float x
Definition: font_driver.h:66
GLsizei GLsizei GLenum GLenum const GLvoid * data
Definition: glext.h:6303
bool dirty
Definition: font_driver.h:61
unsigned width
Definition: font_driver.h:59
font_renderer_t sixel_font
Definition: sixel_font.c:130
void font_driver_bind_block(void *font_data, void *block)
Definition: font_driver.c:945
uint32_t color
Definition: font_driver.h:77
Definition: video_driver.h:405
float drop_mod
Definition: font_driver.h:70
font_renderer_t libdbg_font
Definition: ps_libdbgfont.c:103
int draw_offset_x
Definition: font_driver.h:48
font_renderer_t caca_font
Definition: caca_font.c:132
unsigned width
Definition: font_driver.h:39
void font_driver_free(void *font_data)
Definition: font_driver.c:971
void(* bind_block)(void *data, void *block)
Definition: font_driver.h:94
float drop_alpha
Definition: font_driver.h:75
static const unsigned char msg[]
Definition: ccm.c:375
Definition: video_driver.h:332
int font_driver_get_message_width(void *font_data, const char *msg, unsigned len, float scale)
Definition: font_driver.c:962
void font_driver_render_msg(video_frame_info_t *video_info, void *font_data, const char *msg, const struct font_params *params)
Definition: font_driver.c:920
Definition: font_driver.h:101
struct font_renderer_driver font_renderer_driver_t
void font_driver_flush(unsigned width, unsigned height, void *font_data, video_frame_info_t *video_info)
Definition: font_driver.c:953
int(* get_line_height)(void *data)
Definition: font_driver.h:116
void(* free)(void *data)
Definition: font_driver.h:110
font_renderer_driver_t freetype_font_renderer
Definition: freetype.c:334
#define RETRO_END_DECLS
Definition: retro_common_api.h:42
static int block
Definition: psp2.c:31
font_renderer_driver_t bitmap_font_renderer
Definition: bitmapfont.c:148
float y
Definition: font_driver.h:67
font_renderer_t d3d_xdk1_font
Definition: xdk1_xfonts.c:112
enum text_alignment text_align
Definition: font_driver.h:79
unsigned height
Definition: font_driver.h:60
Definition: font_driver.h:56
GLint GLint GLsizei width
Definition: glext.h:6293
int drop_y
Definition: font_driver.h:73
font_renderer_driver_t stb_unicode_font_renderer
Definition: stb_unicode.c:314
font_driver_render_api
Definition: video_defines.h:82
void(* free)(void *data, bool is_threaded)
Definition: font_driver.h:86
font_renderer_t vga_font
Definition: vga_font.c:129
font_renderer_t vita2d_vita_font
Definition: vita2d_font.c:350
bool full_screen
Definition: font_driver.h:78
Definition: font_driver.h:82
font_renderer_t d3d_win32_font
Definition: d3d_w32_font.c:225
font_renderer_t d3d11_font
Definition: d3d11_font.c:362
font_renderer_t ctr_font
Definition: ctr_font.c:450
Definition: font_driver.h:37
const char * ident
Definition: font_driver.h:91
struct font_renderer font_renderer_t
font_renderer_t gdi_font
Definition: gdi_font.c:208
void font_driver_free_osd(void)
Definition: font_driver.c:1045
const char * ident
Definition: font_driver.h:114
unsigned char uint8_t
Definition: stdint.h:124
unsigned int uint32_t
Definition: stdint.h:126
const font_renderer_t * renderer
Definition: font_driver.h:121
int advance_x
Definition: font_driver.h:52
void * renderer_data
Definition: font_driver.h:122
GLint GLint GLsizei GLsizei height
Definition: glext.h:6293
Definition: font_driver.h:119
int(* get_message_width)(void *data, const char *msg, unsigned msg_len_full, float scale)
Definition: font_driver.h:98
Definition: font_driver.h:64