(Font drivers) Uniformity in naming conventions
This commit is contained in:
parent
aab64da1be
commit
cf12a5e7e7
|
@ -36,7 +36,7 @@ typedef struct
|
|||
caca_t *caca;
|
||||
} caca_raster_t;
|
||||
|
||||
static void *caca_init_font(void *data,
|
||||
static void *caca_font_init(void *data,
|
||||
const char *font_path, float font_size,
|
||||
bool is_threaded)
|
||||
{
|
||||
|
@ -58,13 +58,9 @@ static void *caca_init_font(void *data,
|
|||
return font;
|
||||
}
|
||||
|
||||
static void caca_render_free_font(void *data, bool is_threaded)
|
||||
{
|
||||
(void)data;
|
||||
(void)is_threaded;
|
||||
}
|
||||
static void caca_font_free(void *data, bool is_threaded) { }
|
||||
|
||||
static int caca_get_message_width(void *data, const char *msg,
|
||||
static int caca_font_get_message_width(void *data, const char *msg,
|
||||
unsigned msg_len, float scale)
|
||||
{
|
||||
return 0;
|
||||
|
@ -76,7 +72,7 @@ static const struct font_glyph *caca_font_get_glyph(
|
|||
return NULL;
|
||||
}
|
||||
|
||||
static void caca_render_msg(
|
||||
static void caca_font_render_msg(
|
||||
void *userdata,
|
||||
void *data, const char *msg,
|
||||
const struct font_params *params)
|
||||
|
@ -136,13 +132,13 @@ static void caca_render_msg(
|
|||
}
|
||||
|
||||
font_renderer_t caca_font = {
|
||||
caca_init_font,
|
||||
caca_render_free_font,
|
||||
caca_render_msg,
|
||||
caca_font_init,
|
||||
caca_font_free,
|
||||
caca_font_render_msg,
|
||||
"caca font",
|
||||
caca_font_get_glyph, /* get_glyph */
|
||||
caca_font_get_glyph,
|
||||
NULL, /* bind_block */
|
||||
NULL, /* flush */
|
||||
caca_get_message_width, /* get_message_width */
|
||||
caca_font_get_message_width,
|
||||
NULL /* get_line_metrics */
|
||||
};
|
||||
|
|
|
@ -40,7 +40,7 @@ typedef struct
|
|||
void* font_data;
|
||||
} ctr_font_t;
|
||||
|
||||
static void* ctr_font_init_font(void* data, const char* font_path,
|
||||
static void* ctr_font_init(void* data, const char* font_path,
|
||||
float font_size, bool is_threaded)
|
||||
{
|
||||
const struct font_atlas* atlas = NULL;
|
||||
|
@ -101,7 +101,7 @@ static void* ctr_font_init_font(void* data, const char* font_path,
|
|||
return font;
|
||||
}
|
||||
|
||||
static void ctr_font_free_font(void* data, bool is_threaded)
|
||||
static void ctr_font_free(void* data, bool is_threaded)
|
||||
{
|
||||
ctr_font_t* font = (ctr_font_t*)data;
|
||||
|
||||
|
@ -433,15 +433,15 @@ static bool ctr_font_get_line_metrics(void* data, struct font_line_metrics **met
|
|||
ctr_font_t* font = (ctr_font_t*)data;
|
||||
if (font && font->font_driver && font->font_data)
|
||||
return font->font_driver->get_line_metrics(font->font_data, metrics);
|
||||
return -1;
|
||||
return false;
|
||||
}
|
||||
|
||||
font_renderer_t ctr_font =
|
||||
{
|
||||
ctr_font_init_font,
|
||||
ctr_font_free_font,
|
||||
ctr_font_init,
|
||||
ctr_font_free,
|
||||
ctr_font_render_msg,
|
||||
"ctrfont",
|
||||
"ctr_font",
|
||||
ctr_font_get_glyph,
|
||||
NULL, /* bind_block */
|
||||
NULL, /* flush_block */
|
||||
|
|
|
@ -35,8 +35,8 @@ typedef struct
|
|||
struct font_atlas* atlas;
|
||||
} d3d10_font_t;
|
||||
|
||||
static void*
|
||||
d3d10_font_init_font(void* data, const char* font_path, float font_size, bool is_threaded)
|
||||
static void *d3d10_font_init(void* data, const char* font_path,
|
||||
float font_size, bool is_threaded)
|
||||
{
|
||||
d3d10_video_t* d3d10 = (d3d10_video_t*)data;
|
||||
d3d10_font_t* font = (d3d10_font_t*)calloc(1, sizeof(*font));
|
||||
|
@ -69,7 +69,7 @@ d3d10_font_init_font(void* data, const char* font_path, float font_size, bool is
|
|||
return font;
|
||||
}
|
||||
|
||||
static void d3d10_font_free_font(void* data, bool is_threaded)
|
||||
static void d3d10_font_free(void* data, bool is_threaded)
|
||||
{
|
||||
d3d10_font_t* font = (d3d10_font_t*)data;
|
||||
|
||||
|
@ -377,12 +377,12 @@ static bool d3d10_font_get_line_metrics(void* data, struct font_line_metrics **m
|
|||
d3d10_font_t* font = (d3d10_font_t*)data;
|
||||
if (font && font->font_driver && font->font_data)
|
||||
return font->font_driver->get_line_metrics(font->font_data, metrics);
|
||||
return -1;
|
||||
return false;
|
||||
}
|
||||
|
||||
font_renderer_t d3d10_font = {
|
||||
d3d10_font_init_font,
|
||||
d3d10_font_free_font,
|
||||
d3d10_font_init,
|
||||
d3d10_font_free,
|
||||
d3d10_font_render_msg,
|
||||
"d3d10font",
|
||||
d3d10_font_get_glyph,
|
||||
|
|
|
@ -34,8 +34,8 @@ typedef struct
|
|||
struct font_atlas* atlas;
|
||||
} d3d11_font_t;
|
||||
|
||||
static void*
|
||||
d3d11_font_init_font(void* data, const char* font_path, float font_size, bool is_threaded)
|
||||
static void * d3d11_font_init(void* data, const char* font_path,
|
||||
float font_size, bool is_threaded)
|
||||
{
|
||||
d3d11_video_t* d3d11 = (d3d11_video_t*)data;
|
||||
d3d11_font_t* font = (d3d11_font_t*)calloc(1, sizeof(*font));
|
||||
|
@ -67,7 +67,7 @@ d3d11_font_init_font(void* data, const char* font_path, float font_size, bool is
|
|||
return font;
|
||||
}
|
||||
|
||||
static void d3d11_font_free_font(void* data, bool is_threaded)
|
||||
static void d3d11_font_free(void* data, bool is_threaded)
|
||||
{
|
||||
d3d11_font_t* font = (d3d11_font_t*)data;
|
||||
|
||||
|
@ -380,14 +380,14 @@ static bool d3d11_font_get_line_metrics(void* data, struct font_line_metrics **m
|
|||
d3d11_font_t* font = (d3d11_font_t*)data;
|
||||
if (font && font->font_driver && font->font_data)
|
||||
return font->font_driver->get_line_metrics(font->font_data, metrics);
|
||||
return -1;
|
||||
return false;
|
||||
}
|
||||
|
||||
font_renderer_t d3d11_font = {
|
||||
d3d11_font_init_font,
|
||||
d3d11_font_free_font,
|
||||
d3d11_font_init,
|
||||
d3d11_font_free,
|
||||
d3d11_font_render_msg,
|
||||
"d3d11font",
|
||||
"d3d11_font",
|
||||
d3d11_font_get_glyph,
|
||||
NULL, /* bind_block */
|
||||
NULL, /* flush */
|
||||
|
|
|
@ -34,8 +34,7 @@ typedef struct
|
|||
struct font_atlas* atlas;
|
||||
} d3d12_font_t;
|
||||
|
||||
static void*
|
||||
d3d12_font_init_font(void* data, const char* font_path,
|
||||
static void * d3d12_font_init(void* data, const char* font_path,
|
||||
float font_size, bool is_threaded)
|
||||
{
|
||||
d3d12_video_t* d3d12 = (d3d12_video_t*)data;
|
||||
|
@ -70,7 +69,7 @@ d3d12_font_init_font(void* data, const char* font_path,
|
|||
return font;
|
||||
}
|
||||
|
||||
static void d3d12_font_free_font(void* data, bool is_threaded)
|
||||
static void d3d12_font_free(void* data, bool is_threaded)
|
||||
{
|
||||
d3d12_font_t* font = (d3d12_font_t*)data;
|
||||
|
||||
|
@ -383,14 +382,14 @@ static bool d3d12_font_get_line_metrics(void* data, struct font_line_metrics **m
|
|||
d3d12_font_t* font = (d3d12_font_t*)data;
|
||||
if (font && font->font_driver && font->font_data)
|
||||
return font->font_driver->get_line_metrics(font->font_data, metrics);
|
||||
return -1;
|
||||
return false;
|
||||
}
|
||||
|
||||
font_renderer_t d3d12_font = {
|
||||
d3d12_font_init_font,
|
||||
d3d12_font_free_font,
|
||||
d3d12_font_init,
|
||||
d3d12_font_free,
|
||||
d3d12_font_render_msg,
|
||||
"d3d12font",
|
||||
"d3d12_font",
|
||||
d3d12_font_get_glyph,
|
||||
NULL, /* bind_block */
|
||||
NULL, /* flush */
|
||||
|
|
|
@ -52,7 +52,7 @@ typedef struct
|
|||
uint32_t ascent;
|
||||
} d3dfonts_t;
|
||||
|
||||
static void *d3dfonts_w32_init_font(void *video_data,
|
||||
static void *d3d_win32_font_init(void *video_data,
|
||||
const char *font_path, float font_size,
|
||||
bool is_threaded)
|
||||
{
|
||||
|
@ -97,7 +97,7 @@ error:
|
|||
return NULL;
|
||||
}
|
||||
|
||||
static void d3dfonts_w32_free_font(void *data, bool is_threaded)
|
||||
static void d3d_win32_font_free(void *data, bool is_threaded)
|
||||
{
|
||||
d3dfonts_t *d3dfonts = (d3dfonts_t*)data;
|
||||
|
||||
|
@ -110,7 +110,7 @@ static void d3dfonts_w32_free_font(void *data, bool is_threaded)
|
|||
free(d3dfonts);
|
||||
}
|
||||
|
||||
static int d3dfonts_w32_get_message_width(void* data, const char* msg,
|
||||
static int d3d_win32_font_get_message_width(void* data, const char* msg,
|
||||
unsigned msg_len, float scale)
|
||||
{
|
||||
RECT box = {0,0,0,0};
|
||||
|
@ -125,7 +125,7 @@ static int d3dfonts_w32_get_message_width(void* data, const char* msg,
|
|||
return box.right - box.left;
|
||||
}
|
||||
|
||||
static void d3dfonts_w32_render_msg(
|
||||
static void d3d_win32_font_render_msg(
|
||||
void *userdata,
|
||||
void *data, const char *msg,
|
||||
const struct font_params *params)
|
||||
|
@ -229,13 +229,13 @@ static void d3dfonts_w32_render_msg(
|
|||
}
|
||||
|
||||
font_renderer_t d3d_win32_font = {
|
||||
d3dfonts_w32_init_font,
|
||||
d3dfonts_w32_free_font,
|
||||
d3dfonts_w32_render_msg,
|
||||
"d3dxfont",
|
||||
d3d_win32_font_init,
|
||||
d3d_win32_font_free,
|
||||
d3d_win32_font_render_msg,
|
||||
"d3d_win32_font",
|
||||
NULL, /* get_glyph */
|
||||
NULL, /* bind_block */
|
||||
NULL, /* flush */
|
||||
d3dfonts_w32_get_message_width,
|
||||
d3d_win32_font_get_message_width,
|
||||
NULL /* get_line_metrics */
|
||||
};
|
||||
|
|
|
@ -42,7 +42,7 @@ typedef struct
|
|||
gdi_t *gdi;
|
||||
} gdi_raster_t;
|
||||
|
||||
static void *gdi_init_font(void *data,
|
||||
static void *gdi_font_init(void *data,
|
||||
const char *font_path, float font_size,
|
||||
bool is_threaded)
|
||||
{
|
||||
|
@ -64,25 +64,9 @@ static void *gdi_init_font(void *data,
|
|||
return font;
|
||||
}
|
||||
|
||||
static void gdi_render_free_font(void *data, bool is_threaded)
|
||||
{
|
||||
(void)data;
|
||||
(void)is_threaded;
|
||||
}
|
||||
static void gdi_font_free(void *data, bool is_threaded) { }
|
||||
|
||||
static int gdi_get_message_width(void *data, const char *msg,
|
||||
unsigned msg_len, float scale)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
static const struct font_glyph *gdi_font_get_glyph(
|
||||
void *data, uint32_t code)
|
||||
{
|
||||
return NULL;
|
||||
}
|
||||
|
||||
static void gdi_render_msg(
|
||||
static void gdi_font_render_msg(
|
||||
void *userdata,
|
||||
void *data,
|
||||
const char *msg,
|
||||
|
@ -205,13 +189,13 @@ static void gdi_render_msg(
|
|||
}
|
||||
|
||||
font_renderer_t gdi_font = {
|
||||
gdi_init_font,
|
||||
gdi_render_free_font,
|
||||
gdi_render_msg,
|
||||
"gdi font",
|
||||
gdi_font_get_glyph, /* get_glyph */
|
||||
gdi_font_init,
|
||||
gdi_font_free,
|
||||
gdi_font_render_msg,
|
||||
"gdi_font",
|
||||
NULL, /* get_glyph */
|
||||
NULL, /* bind_block */
|
||||
NULL, /* flush */
|
||||
gdi_get_message_width, /* get_message_width */
|
||||
NULL, /* get_message_width */
|
||||
NULL /* get_line_metrics */
|
||||
};
|
||||
|
|
|
@ -56,7 +56,7 @@ typedef struct
|
|||
video_font_raster_block_t *block;
|
||||
} gl1_raster_t;
|
||||
|
||||
static void gl1_raster_font_free_font(void *data,
|
||||
static void gl1_raster_font_free(void *data,
|
||||
bool is_threaded)
|
||||
{
|
||||
gl1_raster_t *font = (gl1_raster_t*)data;
|
||||
|
@ -157,7 +157,7 @@ static bool gl1_raster_font_upload_atlas(gl1_raster_t *font)
|
|||
return true;
|
||||
}
|
||||
|
||||
static void *gl1_raster_font_init_font(void *data,
|
||||
static void *gl1_raster_font_init(void *data,
|
||||
const char *font_path, float font_size,
|
||||
bool is_threaded)
|
||||
{
|
||||
|
@ -205,13 +205,13 @@ static void *gl1_raster_font_init_font(void *data,
|
|||
return font;
|
||||
|
||||
error:
|
||||
gl1_raster_font_free_font(font, is_threaded);
|
||||
gl1_raster_font_free(font, is_threaded);
|
||||
font = NULL;
|
||||
|
||||
return NULL;
|
||||
}
|
||||
|
||||
static int gl1_get_message_width(void *data, const char *msg,
|
||||
static int gl1_raster_font_get_message_width(void *data, const char *msg,
|
||||
unsigned msg_len, float scale)
|
||||
{
|
||||
const struct font_glyph* glyph_q = NULL;
|
||||
|
@ -327,10 +327,10 @@ static void gl1_raster_font_render_line(
|
|||
switch (text_align)
|
||||
{
|
||||
case TEXT_ALIGN_RIGHT:
|
||||
x -= gl1_get_message_width(font, msg, msg_len, scale);
|
||||
x -= gl1_raster_font_get_message_width(font, msg, msg_len, scale);
|
||||
break;
|
||||
case TEXT_ALIGN_CENTER:
|
||||
x -= gl1_get_message_width(font, msg, msg_len, scale) / 2.0;
|
||||
x -= gl1_raster_font_get_message_width(font, msg, msg_len, scale) / 2.0;
|
||||
break;
|
||||
}
|
||||
|
||||
|
@ -582,22 +582,22 @@ static void gl1_raster_font_bind_block(void *data, void *userdata)
|
|||
font->block = block;
|
||||
}
|
||||
|
||||
static bool gl1_get_line_metrics(void* data, struct font_line_metrics **metrics)
|
||||
static bool gl1_raster_font_get_line_metrics(void* data, struct font_line_metrics **metrics)
|
||||
{
|
||||
gl1_raster_t *font = (gl1_raster_t*)data;
|
||||
if (font && font->font_driver && font->font_data)
|
||||
return font->font_driver->get_line_metrics(font->font_data, metrics);
|
||||
return -1;
|
||||
return false;
|
||||
}
|
||||
|
||||
font_renderer_t gl1_raster_font = {
|
||||
gl1_raster_font_init_font,
|
||||
gl1_raster_font_free_font,
|
||||
gl1_raster_font_init,
|
||||
gl1_raster_font_free,
|
||||
gl1_raster_font_render_msg,
|
||||
"GL1 raster",
|
||||
"gl1_raster_font",
|
||||
gl1_raster_font_get_glyph,
|
||||
gl1_raster_font_bind_block,
|
||||
gl1_raster_font_flush_block,
|
||||
gl1_get_message_width,
|
||||
gl1_get_line_metrics
|
||||
gl1_raster_font_get_message_width,
|
||||
gl1_raster_font_get_line_metrics
|
||||
};
|
||||
|
|
|
@ -55,7 +55,7 @@ typedef struct
|
|||
video_font_raster_block_t *block;
|
||||
} gl2_raster_t;
|
||||
|
||||
static void gl2_raster_font_free_font(void *data,
|
||||
static void gl2_raster_font_free(void *data,
|
||||
bool is_threaded)
|
||||
{
|
||||
gl2_raster_t *font = (gl2_raster_t*)data;
|
||||
|
@ -178,7 +178,7 @@ static bool gl2_raster_font_upload_atlas(gl2_raster_t *font)
|
|||
return true;
|
||||
}
|
||||
|
||||
static void *gl2_raster_font_init_font(void *data,
|
||||
static void *gl2_raster_font_init(void *data,
|
||||
const char *font_path, float font_size,
|
||||
bool is_threaded)
|
||||
{
|
||||
|
@ -224,13 +224,13 @@ static void *gl2_raster_font_init_font(void *data,
|
|||
return font;
|
||||
|
||||
error:
|
||||
gl2_raster_font_free_font(font, is_threaded);
|
||||
gl2_raster_font_free(font, is_threaded);
|
||||
font = NULL;
|
||||
|
||||
return NULL;
|
||||
}
|
||||
|
||||
static int gl2_get_message_width(void *data, const char *msg,
|
||||
static int gl2_raster_font_get_message_width(void *data, const char *msg,
|
||||
unsigned msg_len, float scale)
|
||||
{
|
||||
const struct font_glyph* glyph_q = NULL;
|
||||
|
@ -308,10 +308,10 @@ static void gl2_raster_font_render_line(
|
|||
switch (text_align)
|
||||
{
|
||||
case TEXT_ALIGN_RIGHT:
|
||||
x -= gl2_get_message_width(font, msg, msg_len, scale);
|
||||
x -= gl2_raster_font_get_message_width(font, msg, msg_len, scale);
|
||||
break;
|
||||
case TEXT_ALIGN_CENTER:
|
||||
x -= gl2_get_message_width(font, msg, msg_len, scale) / 2.0;
|
||||
x -= gl2_raster_font_get_message_width(font, msg, msg_len, scale) / 2.0;
|
||||
break;
|
||||
}
|
||||
|
||||
|
@ -567,22 +567,22 @@ static void gl2_raster_font_bind_block(void *data, void *userdata)
|
|||
font->block = block;
|
||||
}
|
||||
|
||||
static bool gl2_get_line_metrics(void* data, struct font_line_metrics **metrics)
|
||||
static bool gl2_raster_font_get_line_metrics(void* data, struct font_line_metrics **metrics)
|
||||
{
|
||||
gl2_raster_t *font = (gl2_raster_t*)data;
|
||||
if (font && font->font_driver && font->font_data)
|
||||
return font->font_driver->get_line_metrics(font->font_data, metrics);
|
||||
return -1;
|
||||
return false;
|
||||
}
|
||||
|
||||
font_renderer_t gl2_raster_font = {
|
||||
gl2_raster_font_init_font,
|
||||
gl2_raster_font_free_font,
|
||||
gl2_raster_font_init,
|
||||
gl2_raster_font_free,
|
||||
gl2_raster_font_render_msg,
|
||||
"GL2 raster",
|
||||
"gl2_raster_font",
|
||||
gl2_raster_font_get_glyph,
|
||||
gl2_raster_font_bind_block,
|
||||
gl2_raster_font_flush_block,
|
||||
gl2_get_message_width,
|
||||
gl2_get_line_metrics
|
||||
gl2_raster_font_get_message_width,
|
||||
gl2_raster_font_get_line_metrics
|
||||
};
|
||||
|
|
|
@ -52,7 +52,7 @@ typedef struct
|
|||
video_font_raster_block_t *block;
|
||||
} gl3_raster_t;
|
||||
|
||||
static void gl3_raster_font_free_font(void *data,
|
||||
static void gl3_raster_font_free(void *data,
|
||||
bool is_threaded)
|
||||
{
|
||||
gl3_raster_t *font = (gl3_raster_t*)data;
|
||||
|
@ -96,7 +96,7 @@ static bool gl3_raster_font_upload_atlas(gl3_raster_t *font)
|
|||
return true;
|
||||
}
|
||||
|
||||
static void *gl3_raster_font_init_font(void *data,
|
||||
static void *gl3_raster_font_init(void *data,
|
||||
const char *font_path, float font_size,
|
||||
bool is_threaded)
|
||||
{
|
||||
|
@ -132,11 +132,11 @@ static void *gl3_raster_font_init_font(void *data,
|
|||
return font;
|
||||
|
||||
error:
|
||||
gl3_raster_font_free_font(font, is_threaded);
|
||||
gl3_raster_font_free(font, is_threaded);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
static int gl3_get_message_width(void *data, const char *msg,
|
||||
static int gl3_raster_font_get_message_width(void *data, const char *msg,
|
||||
unsigned msg_len, float scale)
|
||||
{
|
||||
const struct font_glyph* glyph_q = NULL;
|
||||
|
@ -232,10 +232,10 @@ static void gl3_raster_font_render_line(
|
|||
switch (text_align)
|
||||
{
|
||||
case TEXT_ALIGN_RIGHT:
|
||||
x -= gl3_get_message_width(font, msg, msg_len, scale);
|
||||
x -= gl3_raster_font_get_message_width(font, msg, msg_len, scale);
|
||||
break;
|
||||
case TEXT_ALIGN_CENTER:
|
||||
x -= gl3_get_message_width(font, msg, msg_len, scale) / 2.0;
|
||||
x -= gl3_raster_font_get_message_width(font, msg, msg_len, scale) / 2.0;
|
||||
break;
|
||||
}
|
||||
|
||||
|
@ -479,22 +479,22 @@ static void gl3_raster_font_bind_block(void *data, void *userdata)
|
|||
font->block = block;
|
||||
}
|
||||
|
||||
static bool gl3_get_line_metrics(void* data, struct font_line_metrics **metrics)
|
||||
static bool gl3_raster_font_get_line_metrics(void* data, struct font_line_metrics **metrics)
|
||||
{
|
||||
gl3_raster_t *font = (gl3_raster_t*)data;
|
||||
if (font && font->font_driver && font->font_data)
|
||||
return font->font_driver->get_line_metrics(font->font_data, metrics);
|
||||
return -1;
|
||||
return false;
|
||||
}
|
||||
|
||||
font_renderer_t gl3_raster_font = {
|
||||
gl3_raster_font_init_font,
|
||||
gl3_raster_font_free_font,
|
||||
gl3_raster_font_init,
|
||||
gl3_raster_font_free,
|
||||
gl3_raster_font_render_msg,
|
||||
"GLCore raster",
|
||||
"gl3_raster_font",
|
||||
gl3_raster_font_get_glyph,
|
||||
gl3_raster_font_bind_block,
|
||||
gl3_raster_font_flush_block,
|
||||
gl3_get_message_width,
|
||||
gl3_get_line_metrics
|
||||
gl3_raster_font_get_message_width,
|
||||
gl3_raster_font_get_line_metrics
|
||||
};
|
||||
|
|
|
@ -505,9 +505,7 @@ static INLINE void write_quad6(SpriteVertex *pv,
|
|||
|
||||
@end
|
||||
|
||||
static void metal_raster_font_free_font(void *data, bool is_threaded);
|
||||
|
||||
static void *metal_raster_font_init_font(void *data,
|
||||
static void *metal_raster_font_init(void *data,
|
||||
const char *font_path, float font_size,
|
||||
bool is_threaded)
|
||||
{
|
||||
|
@ -519,7 +517,7 @@ static void *metal_raster_font_init_font(void *data,
|
|||
return (__bridge_retained void *)r;
|
||||
}
|
||||
|
||||
static void metal_raster_font_free_font(void *data, bool is_threaded)
|
||||
static void metal_raster_font_free(void *data, bool is_threaded)
|
||||
{
|
||||
MetalRaster *r = (__bridge_transfer MetalRaster *)data;
|
||||
|
||||
|
@ -527,8 +525,8 @@ static void metal_raster_font_free_font(void *data, bool is_threaded)
|
|||
r = nil;
|
||||
}
|
||||
|
||||
static int metal_get_message_width(void *data, const char *msg,
|
||||
unsigned msg_len, float scale)
|
||||
static int metal_raster_font_get_message_width(void *data, const char *msg,
|
||||
unsigned msg_len, float scale)
|
||||
{
|
||||
MetalRaster *r = (__bridge MetalRaster *)data;
|
||||
return [r getWidthForMessage:msg length:msg_len scale:scale];
|
||||
|
@ -555,13 +553,13 @@ static const struct font_glyph *metal_raster_font_get_glyph(
|
|||
}
|
||||
|
||||
font_renderer_t metal_raster_font = {
|
||||
.init = metal_raster_font_init_font,
|
||||
.free = metal_raster_font_free_font,
|
||||
.render_msg = metal_raster_font_render_msg,
|
||||
.ident = "Metal raster",
|
||||
.get_glyph = metal_raster_font_get_glyph,
|
||||
metal_raster_font_init,
|
||||
metal_raster_font_free,
|
||||
metal_raster_font_render_msg,
|
||||
"metal_raster",
|
||||
metal_raster_font_get_glyph,
|
||||
NULL, /* bind_block */
|
||||
NULL, /* flush_block */
|
||||
.get_message_width = metal_get_message_width,
|
||||
metal_raster_font_get_message_width,
|
||||
NULL /* get_line_metrics */
|
||||
};
|
||||
|
|
|
@ -36,7 +36,7 @@ typedef struct
|
|||
void* font_data;
|
||||
} ps2_font_t;
|
||||
|
||||
static void* ps2_font_init_font(void* data, const char* font_path,
|
||||
static void* ps2_font_init(void* data, const char* font_path,
|
||||
float font_size, bool is_threaded)
|
||||
{
|
||||
const struct font_atlas* atlas = NULL;
|
||||
|
@ -80,7 +80,7 @@ static void* ps2_font_init_font(void* data, const char* font_path,
|
|||
return font;
|
||||
}
|
||||
|
||||
static void ps2_font_free_font(void* data, bool is_threaded)
|
||||
static void ps2_font_free(void* data, bool is_threaded)
|
||||
{
|
||||
ps2_font_t* font = (ps2_font_t*)data;
|
||||
|
||||
|
@ -369,14 +369,14 @@ static bool ps2_font_get_line_metrics(void* data, struct font_line_metrics **met
|
|||
ps2_font_t* font = (ps2_font_t*)data;
|
||||
if (font && font->font_driver && font->font_data)
|
||||
return font->font_driver->get_line_metrics(font->font_data, metrics);
|
||||
return -1;
|
||||
return false;
|
||||
}
|
||||
|
||||
font_renderer_t ps2_font = {
|
||||
ps2_font_init_font,
|
||||
ps2_font_free_font,
|
||||
ps2_font_init,
|
||||
ps2_font_free,
|
||||
ps2_font_render_msg,
|
||||
"PS2 font",
|
||||
"ps2_font",
|
||||
ps2_font_get_glyph,
|
||||
NULL, /* bind_block */
|
||||
NULL, /* flush */
|
||||
|
|
|
@ -65,7 +65,7 @@ typedef struct
|
|||
video_font_raster_block_t *block;
|
||||
} rsx_font_t;
|
||||
|
||||
static void rsx_font_free_font(void *data,
|
||||
static void rsx_font_free(void *data,
|
||||
bool is_threaded)
|
||||
{
|
||||
rsx_font_t *font = (rsx_font_t*)data;
|
||||
|
@ -131,7 +131,7 @@ static bool rsx_font_upload_atlas(rsx_font_t *font)
|
|||
return true;
|
||||
}
|
||||
|
||||
static void *rsx_font_init_font(void *data,
|
||||
static void *rsx_font_init(void *data,
|
||||
const char *font_path, float font_size,
|
||||
bool is_threaded)
|
||||
{
|
||||
|
@ -195,7 +195,7 @@ static void *rsx_font_init_font(void *data,
|
|||
return font;
|
||||
|
||||
error:
|
||||
rsx_font_free_font(font, is_threaded);
|
||||
rsx_font_free(font, is_threaded);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
|
@ -554,14 +554,14 @@ static bool rsx_font_get_line_metrics(void* data, struct font_line_metrics **met
|
|||
rsx_font_t *font = (rsx_font_t*)data;
|
||||
if (font && font->font_driver && font->font_data)
|
||||
return font->font_driver->get_line_metrics(font->font_data, metrics);
|
||||
return -1;
|
||||
return false;
|
||||
}
|
||||
|
||||
font_renderer_t rsx_font = {
|
||||
rsx_font_init_font,
|
||||
rsx_font_free_font,
|
||||
rsx_font_init,
|
||||
rsx_font_free,
|
||||
rsx_font_render_msg,
|
||||
"rsxfont",
|
||||
"rsx_font",
|
||||
rsx_font_get_glyph,
|
||||
rsx_font_bind_block,
|
||||
rsx_font_flush_block,
|
||||
|
|
|
@ -35,7 +35,7 @@ typedef struct
|
|||
sixel_t *sixel;
|
||||
} sixel_raster_t;
|
||||
|
||||
static void *sixel_init_font(void *data,
|
||||
static void *sixel_font_init(void *data,
|
||||
const char *font_path, float font_size,
|
||||
bool is_threaded)
|
||||
{
|
||||
|
@ -57,30 +57,20 @@ static void *sixel_init_font(void *data,
|
|||
return font;
|
||||
}
|
||||
|
||||
static void sixel_render_free_font(void *data, bool is_threaded)
|
||||
{
|
||||
(void)data;
|
||||
(void)is_threaded;
|
||||
}
|
||||
|
||||
static int sixel_get_message_width(void *data, const char *msg,
|
||||
unsigned msg_len, float scale)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
static void sixel_font_free(void *data, bool is_threaded) { }
|
||||
static int sixel_font_get_message_width(void *data, const char *msg,
|
||||
unsigned msg_len, float scale) { return 0; }
|
||||
static const struct font_glyph *sixel_font_get_glyph(
|
||||
void *data, uint32_t code)
|
||||
{
|
||||
return NULL;
|
||||
}
|
||||
void *data, uint32_t code) { return NULL; }
|
||||
|
||||
static void sixel_render_msg(
|
||||
static void sixel_font_render_msg(
|
||||
void *userdata,
|
||||
void *data,
|
||||
const char *msg,
|
||||
const struct font_params *_params)
|
||||
{
|
||||
/* TODO/FIXME: add text drawing support */
|
||||
#if 0
|
||||
float x, y, scale;
|
||||
unsigned width, height, new_x, new_y, align;
|
||||
sixel_raster_t *font = (sixel_raster_t*)data;
|
||||
|
@ -127,18 +117,17 @@ static void sixel_render_msg(
|
|||
new_x = x * width * scale;
|
||||
break;
|
||||
}
|
||||
|
||||
/* FIXME: add text drawing support */
|
||||
#endif
|
||||
}
|
||||
|
||||
font_renderer_t sixel_font = {
|
||||
sixel_init_font,
|
||||
sixel_render_free_font,
|
||||
sixel_render_msg,
|
||||
"sixel font",
|
||||
sixel_font_get_glyph, /* get_glyph */
|
||||
sixel_font_init,
|
||||
sixel_font_free,
|
||||
sixel_font_render_msg,
|
||||
"sixel_font",
|
||||
sixel_font_get_glyph,
|
||||
NULL, /* bind_block */
|
||||
NULL, /* flush */
|
||||
sixel_get_message_width, /* get_message_width */
|
||||
sixel_font_get_message_width,
|
||||
NULL /* get_line_metrics */
|
||||
};
|
||||
|
|
|
@ -40,7 +40,7 @@ typedef struct
|
|||
void *font_data;
|
||||
} switch_font_t;
|
||||
|
||||
static void *switch_font_init_font(void *data, const char *font_path,
|
||||
static void *switch_font_init(void *data, const char *font_path,
|
||||
float font_size, bool is_threaded)
|
||||
{
|
||||
switch_font_t *font = (switch_font_t *)calloc(1, sizeof(switch_font_t));
|
||||
|
@ -61,7 +61,7 @@ static void *switch_font_init_font(void *data, const char *font_path,
|
|||
return font;
|
||||
}
|
||||
|
||||
static void switch_font_free_font(void *data, bool is_threaded)
|
||||
static void switch_font_free(void *data, bool is_threaded)
|
||||
{
|
||||
switch_font_t *font = (switch_font_t *)data;
|
||||
|
||||
|
@ -301,15 +301,15 @@ static bool switch_font_get_line_metrics(void* data, struct font_line_metrics **
|
|||
switch_font_t *font = (switch_font_t *)data;
|
||||
if (font && font->font_driver && font->font_data)
|
||||
return font->font_driver->get_line_metrics(font->font_data, metrics);
|
||||
return -1;
|
||||
return false;
|
||||
}
|
||||
|
||||
font_renderer_t switch_font =
|
||||
{
|
||||
switch_font_init_font,
|
||||
switch_font_free_font,
|
||||
switch_font_init,
|
||||
switch_font_free,
|
||||
switch_font_render_msg,
|
||||
"switchfont",
|
||||
"switch_font",
|
||||
switch_font_get_glyph,
|
||||
NULL, /* bind_block */
|
||||
NULL, /* flush_block */
|
||||
|
|
|
@ -34,7 +34,7 @@ typedef struct
|
|||
vga_t *vga;
|
||||
} vga_raster_t;
|
||||
|
||||
static void *vga_init_font(void *data,
|
||||
static void *vga_font_init(void *data,
|
||||
const char *font_path, float font_size,
|
||||
bool is_threaded)
|
||||
{
|
||||
|
@ -58,25 +58,13 @@ static void *vga_init_font(void *data,
|
|||
return font;
|
||||
}
|
||||
|
||||
static void vga_render_free_font(void *data, bool is_threaded)
|
||||
{
|
||||
(void)data;
|
||||
(void)is_threaded;
|
||||
}
|
||||
|
||||
static int vga_get_message_width(void *data, const char *msg,
|
||||
unsigned msg_len, float scale)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
static void vga_font_render_free(void *data, bool is_threaded) { }
|
||||
static int vga_font_get_message_width(void *data, const char *msg,
|
||||
unsigned msg_len, float scale) { return 0; }
|
||||
static const struct font_glyph *vga_font_get_glyph(
|
||||
void *data, uint32_t code)
|
||||
{
|
||||
return NULL;
|
||||
}
|
||||
void *data, uint32_t code) { return NULL; }
|
||||
|
||||
static void vga_render_msg(
|
||||
static void vga_font_render_msg(
|
||||
void *userdata,
|
||||
void *data, const char *msg,
|
||||
const struct font_params *params)
|
||||
|
@ -85,7 +73,7 @@ static void vga_render_msg(
|
|||
unsigned width, height;
|
||||
unsigned new_x, new_y;
|
||||
unsigned align;
|
||||
vga_raster_t *font = (vga_raster_t*)data;
|
||||
vga_raster_t *font = (vga_raster_t*)data;
|
||||
|
||||
if (!font || string_is_empty(msg))
|
||||
return;
|
||||
|
@ -134,13 +122,13 @@ static void vga_render_msg(
|
|||
}
|
||||
|
||||
font_renderer_t vga_font = {
|
||||
vga_init_font,
|
||||
vga_render_free_font,
|
||||
vga_render_msg,
|
||||
"vga font",
|
||||
vga_font_get_glyph, /* get_glyph */
|
||||
NULL, /* bind_block */
|
||||
NULL, /* flush */
|
||||
vga_get_message_width, /* get_message_width */
|
||||
NULL /* get_line_metrics */
|
||||
vga_font_init,
|
||||
vga_font_render_free,
|
||||
vga_font_render_msg,
|
||||
"vga_font",
|
||||
vga_font_get_glyph, /* get_glyph */
|
||||
NULL, /* bind_block */
|
||||
NULL, /* flush */
|
||||
vga_font_get_message_width, /* get_message_width */
|
||||
NULL /* get_line_metrics */
|
||||
};
|
||||
|
|
|
@ -34,7 +34,7 @@ typedef struct
|
|||
struct font_atlas *atlas;
|
||||
} vita_font_t;
|
||||
|
||||
static void *vita2d_font_init_font(void *data,
|
||||
static void *vita2d_font_init(void *data,
|
||||
const char *font_path, float font_size,
|
||||
bool is_threaded)
|
||||
{
|
||||
|
@ -91,7 +91,7 @@ error:
|
|||
return NULL;
|
||||
}
|
||||
|
||||
static void vita2d_font_free_font(void *data, bool is_threaded)
|
||||
static void vita2d_font_free(void *data, bool is_threaded)
|
||||
{
|
||||
vita_font_t *font = (vita_font_t*)data;
|
||||
if (!font)
|
||||
|
@ -355,14 +355,14 @@ static bool vita2d_font_get_line_metrics(void* data, struct font_line_metrics **
|
|||
vita_font_t *font = (vita_font_t*)data;
|
||||
if (font && font->font_driver && font->font_data)
|
||||
return font->font_driver->get_line_metrics(font->font_data, metrics);
|
||||
return -1;
|
||||
return false;
|
||||
}
|
||||
|
||||
font_renderer_t vita2d_vita_font = {
|
||||
vita2d_font_init_font,
|
||||
vita2d_font_free_font,
|
||||
vita2d_font_init,
|
||||
vita2d_font_free,
|
||||
vita2d_font_render_msg,
|
||||
"vita2dfont",
|
||||
"vita2d_font",
|
||||
vita2d_font_get_glyph,
|
||||
NULL, /* bind_block */
|
||||
NULL, /* flush */
|
||||
|
|
|
@ -39,7 +39,7 @@ typedef struct
|
|||
bool needs_update;
|
||||
} vulkan_raster_t;
|
||||
|
||||
static INLINE void vulkan_raster_font_update_glyph(
|
||||
static INLINE void vulkan_font_update_glyph(
|
||||
vulkan_raster_t *font, const struct font_glyph *glyph)
|
||||
{
|
||||
unsigned row;
|
||||
|
@ -51,7 +51,7 @@ static INLINE void vulkan_raster_font_update_glyph(
|
|||
}
|
||||
}
|
||||
|
||||
static void vulkan_raster_font_free_font(void *data, bool is_threaded)
|
||||
static void vulkan_font_free(void *data, bool is_threaded)
|
||||
{
|
||||
vulkan_raster_t *font = (vulkan_raster_t*)data;
|
||||
if (!font)
|
||||
|
@ -69,7 +69,7 @@ static void vulkan_raster_font_free_font(void *data, bool is_threaded)
|
|||
free(font);
|
||||
}
|
||||
|
||||
static void *vulkan_raster_font_init_font(void *data,
|
||||
static void *vulkan_font_init(void *data,
|
||||
const char *font_path, float font_size,
|
||||
bool is_threaded)
|
||||
{
|
||||
|
@ -138,7 +138,7 @@ static int vulkan_get_message_width(void *data, const char *msg,
|
|||
|
||||
if (font->atlas->dirty)
|
||||
{
|
||||
vulkan_raster_font_update_glyph(font, glyph);
|
||||
vulkan_font_update_glyph(font, glyph);
|
||||
font->atlas->dirty = false;
|
||||
font->needs_update = true;
|
||||
}
|
||||
|
@ -148,7 +148,7 @@ static int vulkan_get_message_width(void *data, const char *msg,
|
|||
return delta_x * scale;
|
||||
}
|
||||
|
||||
static void vulkan_raster_font_render_line(
|
||||
static void vulkan_font_render_line(
|
||||
vulkan_raster_t *font, const char *msg, unsigned msg_len,
|
||||
float scale, const float color[4], float pos_x,
|
||||
float pos_y, unsigned text_align)
|
||||
|
@ -197,7 +197,7 @@ static void vulkan_raster_font_render_line(
|
|||
|
||||
if (font->atlas->dirty)
|
||||
{
|
||||
vulkan_raster_font_update_glyph(font, glyph);
|
||||
vulkan_font_update_glyph(font, glyph);
|
||||
font->atlas->dirty = false;
|
||||
font->needs_update = true;
|
||||
}
|
||||
|
@ -233,7 +233,7 @@ static void vulkan_raster_font_render_line(
|
|||
}
|
||||
}
|
||||
|
||||
static void vulkan_raster_font_render_message(
|
||||
static void vulkan_font_render_message(
|
||||
vulkan_raster_t *font, const char *msg, float scale,
|
||||
const float color[4], float pos_x, float pos_y,
|
||||
unsigned text_align)
|
||||
|
@ -249,7 +249,7 @@ static void vulkan_raster_font_render_message(
|
|||
if (!font->font_driver->get_line_metrics ||
|
||||
!font->font_driver->get_line_metrics(font->font_data, &line_metrics))
|
||||
{
|
||||
vulkan_raster_font_render_line(font, msg, strlen(msg),
|
||||
vulkan_font_render_line(font, msg, strlen(msg),
|
||||
scale, color, pos_x, pos_y, text_align);
|
||||
return;
|
||||
}
|
||||
|
@ -263,7 +263,7 @@ static void vulkan_raster_font_render_message(
|
|||
? (unsigned)(delim - msg) : (unsigned)strlen(msg);
|
||||
|
||||
/* Draw the line */
|
||||
vulkan_raster_font_render_line(font, msg, msg_len,
|
||||
vulkan_font_render_line(font, msg, msg_len,
|
||||
scale, color, pos_x, pos_y - (float)lines * line_height,
|
||||
text_align);
|
||||
|
||||
|
@ -275,7 +275,7 @@ static void vulkan_raster_font_render_message(
|
|||
}
|
||||
}
|
||||
|
||||
static void vulkan_raster_font_flush(vulkan_raster_t *font)
|
||||
static void vulkan_font_flush(vulkan_raster_t *font)
|
||||
{
|
||||
struct vk_draw_triangles call;
|
||||
|
||||
|
@ -350,7 +350,7 @@ static void vulkan_raster_font_flush(vulkan_raster_t *font)
|
|||
vulkan_draw_triangles(font->vk, &call);
|
||||
}
|
||||
|
||||
static void vulkan_raster_font_render_msg(
|
||||
static void vulkan_font_render_msg(
|
||||
void *userdata,
|
||||
void *data,
|
||||
const char *msg,
|
||||
|
@ -440,17 +440,17 @@ static void vulkan_raster_font_render_msg(
|
|||
color_dark[2] = color[2] * drop_mod;
|
||||
color_dark[3] = color[3] * drop_alpha;
|
||||
|
||||
vulkan_raster_font_render_message(font, msg, scale, color_dark,
|
||||
vulkan_font_render_message(font, msg, scale, color_dark,
|
||||
x + scale * drop_x / vk->vp.width, y +
|
||||
scale * drop_y / vk->vp.height, text_align);
|
||||
}
|
||||
|
||||
vulkan_raster_font_render_message(font, msg, scale,
|
||||
vulkan_font_render_message(font, msg, scale,
|
||||
color, x, y, text_align);
|
||||
vulkan_raster_font_flush(font);
|
||||
vulkan_font_flush(font);
|
||||
}
|
||||
|
||||
static const struct font_glyph *vulkan_raster_font_get_glyph(
|
||||
static const struct font_glyph *vulkan_font_get_glyph(
|
||||
void *data, uint32_t code)
|
||||
{
|
||||
const struct font_glyph* glyph;
|
||||
|
@ -463,7 +463,7 @@ static const struct font_glyph *vulkan_raster_font_get_glyph(
|
|||
|
||||
if (glyph && font->atlas->dirty)
|
||||
{
|
||||
vulkan_raster_font_update_glyph(font, glyph);
|
||||
vulkan_font_update_glyph(font, glyph);
|
||||
font->atlas->dirty = false;
|
||||
font->needs_update = true;
|
||||
}
|
||||
|
@ -476,15 +476,15 @@ static bool vulkan_get_line_metrics(void* data,
|
|||
vulkan_raster_t *font = (vulkan_raster_t*)data;
|
||||
if (font && font->font_driver && font->font_data)
|
||||
return font->font_driver->get_line_metrics(font->font_data, metrics);
|
||||
return -1;
|
||||
return false;
|
||||
}
|
||||
|
||||
font_renderer_t vulkan_raster_font = {
|
||||
vulkan_raster_font_init_font,
|
||||
vulkan_raster_font_free_font,
|
||||
vulkan_raster_font_render_msg,
|
||||
"Vulkan raster",
|
||||
vulkan_raster_font_get_glyph,
|
||||
vulkan_font_init,
|
||||
vulkan_font_free,
|
||||
vulkan_font_render_msg,
|
||||
"vulkan_font",
|
||||
vulkan_font_get_glyph,
|
||||
NULL, /* bind_block */
|
||||
NULL, /* flush_block */
|
||||
vulkan_get_message_width,
|
||||
|
|
|
@ -38,7 +38,7 @@ typedef struct
|
|||
struct font_atlas* atlas;
|
||||
} wiiu_font_t;
|
||||
|
||||
static void* wiiu_font_init_font(void* data, const char* font_path,
|
||||
static void* wiiu_font_init(void* data, const char* font_path,
|
||||
float font_size, bool is_threaded)
|
||||
{
|
||||
uint32_t i;
|
||||
|
@ -93,7 +93,7 @@ static void* wiiu_font_init_font(void* data, const char* font_path,
|
|||
return font;
|
||||
}
|
||||
|
||||
static void wiiu_font_free_font(void* data, bool is_threaded)
|
||||
static void wiiu_font_free(void* data, bool is_threaded)
|
||||
{
|
||||
wiiu_font_t* font = (wiiu_font_t*)data;
|
||||
|
||||
|
@ -379,15 +379,15 @@ static bool wiiu_font_get_line_metrics(void* data, struct font_line_metrics **me
|
|||
wiiu_font_t* font = (wiiu_font_t*)data;
|
||||
if (font && font->font_driver && font->font_data)
|
||||
return font->font_driver->get_line_metrics(font->font_data, metrics);
|
||||
return -1;
|
||||
return false;
|
||||
}
|
||||
|
||||
font_renderer_t wiiu_font =
|
||||
{
|
||||
wiiu_font_init_font,
|
||||
wiiu_font_free_font,
|
||||
wiiu_font_init,
|
||||
wiiu_font_free,
|
||||
wiiu_font_render_msg,
|
||||
"wiiufont",
|
||||
"wiiu_font",
|
||||
wiiu_font_get_glyph,
|
||||
NULL, /* bind_block */
|
||||
NULL, /* flush */
|
||||
|
|
|
@ -33,7 +33,7 @@ typedef struct
|
|||
D3DSurface *surf;
|
||||
} xfonts_t;
|
||||
|
||||
static void *xfonts_init_font(void *video_data,
|
||||
static void *xfonts_init(void *video_data,
|
||||
const char *font_path, float font_size,
|
||||
bool is_threaded)
|
||||
{
|
||||
|
@ -63,7 +63,7 @@ static void *xfonts_init_font(void *video_data,
|
|||
return xfont;
|
||||
}
|
||||
|
||||
static void xfonts_free_font(void *data, bool is_threaded)
|
||||
static void xfonts_free(void *data, bool is_threaded)
|
||||
{
|
||||
xfonts_t *font = (xfonts_t*)data;
|
||||
|
||||
|
@ -119,8 +119,8 @@ static void xfonts_render_msg(
|
|||
}
|
||||
|
||||
font_renderer_t d3d_xdk1_font = {
|
||||
xfonts_init_font,
|
||||
xfonts_free_font,
|
||||
xfonts_init,
|
||||
xfonts_free,
|
||||
xfonts_render_msg,
|
||||
"xfonts",
|
||||
NULL, /* get_glyph */
|
||||
|
|
|
@ -41,6 +41,90 @@ typedef struct bm_renderer
|
|||
struct font_line_metrics line_metrics;
|
||||
} bm_renderer_t;
|
||||
|
||||
/* Generates a boolean LUT:
|
||||
* lut[num_glyphs][glyph_width * glyph_height]
|
||||
* LUT value is 'true' if glyph pixel has a
|
||||
* non-zero value.
|
||||
* Returned object must be freed using
|
||||
* bitmapfont_free_lut().
|
||||
* Returns NULL in the event of an error. */
|
||||
bitmapfont_lut_t *bitmapfont_get_lut(void)
|
||||
{
|
||||
bitmapfont_lut_t *font = NULL;
|
||||
size_t symbol_index;
|
||||
size_t i, j;
|
||||
|
||||
/* Initialise font struct */
|
||||
font = (bitmapfont_lut_t*)calloc(1, sizeof(bitmapfont_lut_t));
|
||||
if (!font)
|
||||
goto error;
|
||||
|
||||
font->glyph_min = 0;
|
||||
font->glyph_max = BMP_ATLAS_SIZE - 1;
|
||||
|
||||
/* Note: Need to use a calloc() here, otherwise
|
||||
* we'll get undefined behaviour when calling
|
||||
* bitmapfont_free_lut() if the following loop fails */
|
||||
font->lut = (bool**)calloc(1, BMP_ATLAS_SIZE * sizeof(bool*));
|
||||
if (!font->lut)
|
||||
goto error;
|
||||
|
||||
/* Loop over all possible characters */
|
||||
for (symbol_index = 0; symbol_index < BMP_ATLAS_SIZE; symbol_index++)
|
||||
{
|
||||
/* Allocate memory for current symbol */
|
||||
font->lut[symbol_index] = (bool*)malloc(FONT_WIDTH *
|
||||
FONT_HEIGHT * sizeof(bool));
|
||||
if (!font->lut[symbol_index])
|
||||
goto error;
|
||||
|
||||
for (j = 0; j < FONT_HEIGHT; j++)
|
||||
{
|
||||
for (i = 0; i < FONT_WIDTH; i++)
|
||||
{
|
||||
uint8_t rem = 1 << ((i + j * FONT_WIDTH) & 7);
|
||||
unsigned offset = (i + j * FONT_WIDTH) >> 3;
|
||||
|
||||
/* LUT value is 'true' if specified glyph
|
||||
* position contains a pixel */
|
||||
font->lut[symbol_index][i + (j * FONT_WIDTH)] =
|
||||
(bitmap_bin[FONT_OFFSET(symbol_index) + offset] & rem) > 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return font;
|
||||
|
||||
error:
|
||||
if (font)
|
||||
bitmapfont_free_lut(font);
|
||||
|
||||
return NULL;
|
||||
}
|
||||
|
||||
void bitmapfont_free_lut(bitmapfont_lut_t *font)
|
||||
{
|
||||
if (!font)
|
||||
return;
|
||||
|
||||
if (font->lut)
|
||||
{
|
||||
size_t num_glyphs = (font->glyph_max - font->glyph_min) + 1;
|
||||
size_t i;
|
||||
|
||||
for (i = 0; i < num_glyphs; i++)
|
||||
{
|
||||
if (font->lut[i])
|
||||
free(font->lut[i]);
|
||||
font->lut[i] = NULL;
|
||||
}
|
||||
|
||||
free(font->lut);
|
||||
}
|
||||
|
||||
free(font);
|
||||
}
|
||||
|
||||
static struct font_atlas *font_renderer_bmp_get_atlas(void *data)
|
||||
{
|
||||
bm_renderer_t *handle = (bm_renderer_t*)data;
|
||||
|
@ -163,90 +247,6 @@ font_renderer_driver_t bitmap_font_renderer = {
|
|||
font_renderer_bmp_get_glyph,
|
||||
font_renderer_bmp_free,
|
||||
font_renderer_bmp_get_default_font,
|
||||
"bitmap",
|
||||
"font_renderer_bmp",
|
||||
font_renderer_bmp_get_line_metrics
|
||||
};
|
||||
|
||||
/* Generates a boolean LUT:
|
||||
* lut[num_glyphs][glyph_width * glyph_height]
|
||||
* LUT value is 'true' if glyph pixel has a
|
||||
* non-zero value.
|
||||
* Returned object must be freed using
|
||||
* bitmapfont_free_lut().
|
||||
* Returns NULL in the event of an error. */
|
||||
bitmapfont_lut_t *bitmapfont_get_lut(void)
|
||||
{
|
||||
bitmapfont_lut_t *font = NULL;
|
||||
size_t symbol_index;
|
||||
size_t i, j;
|
||||
|
||||
/* Initialise font struct */
|
||||
font = (bitmapfont_lut_t*)calloc(1, sizeof(bitmapfont_lut_t));
|
||||
if (!font)
|
||||
goto error;
|
||||
|
||||
font->glyph_min = 0;
|
||||
font->glyph_max = BMP_ATLAS_SIZE - 1;
|
||||
|
||||
/* Note: Need to use a calloc() here, otherwise
|
||||
* we'll get undefined behaviour when calling
|
||||
* bitmapfont_free_lut() if the following loop fails */
|
||||
font->lut = (bool**)calloc(1, BMP_ATLAS_SIZE * sizeof(bool*));
|
||||
if (!font->lut)
|
||||
goto error;
|
||||
|
||||
/* Loop over all possible characters */
|
||||
for (symbol_index = 0; symbol_index < BMP_ATLAS_SIZE; symbol_index++)
|
||||
{
|
||||
/* Allocate memory for current symbol */
|
||||
font->lut[symbol_index] = (bool*)malloc(FONT_WIDTH *
|
||||
FONT_HEIGHT * sizeof(bool));
|
||||
if (!font->lut[symbol_index])
|
||||
goto error;
|
||||
|
||||
for (j = 0; j < FONT_HEIGHT; j++)
|
||||
{
|
||||
for (i = 0; i < FONT_WIDTH; i++)
|
||||
{
|
||||
uint8_t rem = 1 << ((i + j * FONT_WIDTH) & 7);
|
||||
unsigned offset = (i + j * FONT_WIDTH) >> 3;
|
||||
|
||||
/* LUT value is 'true' if specified glyph
|
||||
* position contains a pixel */
|
||||
font->lut[symbol_index][i + (j * FONT_WIDTH)] =
|
||||
(bitmap_bin[FONT_OFFSET(symbol_index) + offset] & rem) > 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return font;
|
||||
|
||||
error:
|
||||
if (font)
|
||||
bitmapfont_free_lut(font);
|
||||
|
||||
return NULL;
|
||||
}
|
||||
|
||||
void bitmapfont_free_lut(bitmapfont_lut_t *font)
|
||||
{
|
||||
if (!font)
|
||||
return;
|
||||
|
||||
if (font->lut)
|
||||
{
|
||||
size_t num_glyphs = (font->glyph_max - font->glyph_min) + 1;
|
||||
size_t i;
|
||||
|
||||
for (i = 0; i < num_glyphs; i++)
|
||||
{
|
||||
if (font->lut[i])
|
||||
free(font->lut[i]);
|
||||
font->lut[i] = NULL;
|
||||
}
|
||||
|
||||
free(font->lut);
|
||||
}
|
||||
|
||||
free(font);
|
||||
}
|
||||
|
|
|
@ -205,4 +205,3 @@ error:
|
|||
|
||||
return NULL;
|
||||
}
|
||||
|
||||
|
|
|
@ -369,6 +369,6 @@ font_renderer_driver_t coretext_font_renderer = {
|
|||
font_renderer_ct_get_glyph,
|
||||
font_renderer_ct_free,
|
||||
font_renderer_ct_get_default_font,
|
||||
"coretext",
|
||||
"font_renderer_ct",
|
||||
font_renderer_ct_get_line_metrics
|
||||
};
|
||||
|
|
|
@ -429,6 +429,6 @@ font_renderer_driver_t freetype_font_renderer = {
|
|||
font_renderer_ft_get_glyph,
|
||||
font_renderer_ft_free,
|
||||
font_renderer_ft_get_default_font,
|
||||
"freetype",
|
||||
"font_renderer_ft",
|
||||
font_renderer_ft_get_line_metrics
|
||||
};
|
||||
|
|
|
@ -252,6 +252,6 @@ font_renderer_driver_t stb_font_renderer = {
|
|||
font_renderer_stb_get_glyph,
|
||||
font_renderer_stb_free,
|
||||
font_renderer_stb_get_default_font,
|
||||
"stb",
|
||||
"font_renderer_stb",
|
||||
font_renderer_stb_get_line_metrics
|
||||
};
|
||||
|
|
|
@ -358,6 +358,6 @@ font_renderer_driver_t stb_unicode_font_renderer = {
|
|||
font_renderer_stb_unicode_get_glyph,
|
||||
font_renderer_stb_unicode_free,
|
||||
font_renderer_stb_unicode_get_default_font,
|
||||
"stb-unicode",
|
||||
"font_renderer_stb_unicode",
|
||||
font_renderer_stb_unicode_get_line_metrics
|
||||
};
|
||||
|
|
Loading…
Reference in New Issue