(Font drivers) Simplifications

This commit is contained in:
twinaphex 2020-06-24 21:27:47 +02:00
parent 9cb4d924cb
commit 67898f5d12
9 changed files with 93 additions and 157 deletions

View File

@ -334,26 +334,19 @@ static void ctr_font_render_message(
for (;;)
{
const char* delim = strchr(msg, '\n');
unsigned msg_len = delim ?
(unsigned)(delim - msg) : strlen(msg);
/* Draw the line */
if (delim)
{
unsigned msg_len = delim - msg;
ctr_font_render_line(ctr, font, msg, msg_len,
scale, color, pos_x, pos_y - (float)lines * line_height,
width, height, text_align);
if (!delim)
break;
msg += msg_len + 1;
lines++;
}
else
{
unsigned msg_len = strlen(msg);
ctr_font_render_line(ctr, font, msg, msg_len,
scale, color, pos_x, pos_y - (float)lines * line_height,
width, height, text_align);
break;
}
}
}
static void ctr_font_render_msg(

View File

@ -259,28 +259,21 @@ static void d3d10_font_render_message(
for (;;)
{
const char* delim = strchr(msg, '\n');
unsigned msg_len = delim ?
(unsigned)(delim - msg) : strlen(msg);
/* Draw the line */
if (delim)
{
unsigned msg_len = delim - msg;
d3d10_font_render_line(d3d10,
font, msg, msg_len, scale, color, pos_x,
pos_y - (float)lines * line_height,
width, height, text_align);
if (!delim)
break;
msg += msg_len + 1;
lines++;
}
else
{
unsigned msg_len = strlen(msg);
d3d10_font_render_line(d3d10,
font, msg, msg_len, scale, color, pos_x,
pos_y - (float)lines * line_height,
width, height, text_align);
break;
}
}
}
static void d3d10_font_render_msg(

View File

@ -256,28 +256,21 @@ static void d3d11_font_render_message(
for (;;)
{
const char* delim = strchr(msg, '\n');
unsigned msg_len = delim ?
(unsigned)(delim - msg) : strlen(msg);
/* Draw the line */
if (delim)
{
unsigned msg_len = delim - msg;
d3d11_font_render_line(d3d11,
font, msg, msg_len, scale, color, pos_x,
pos_y - (float)lines * line_height,
width, height, text_align);
if (!delim)
break;
msg += msg_len + 1;
lines++;
}
else
{
unsigned msg_len = strlen(msg);
d3d11_font_render_line(d3d11,
font, msg, msg_len, scale, color, pos_x,
pos_y - (float)lines * line_height,
width, height, text_align);
break;
}
}
}
static void d3d11_font_render_msg(

View File

@ -270,26 +270,20 @@ static void d3d12_font_render_message(
for (;;)
{
const char* delim = strchr(msg, '\n');
unsigned msg_len = delim ?
(unsigned)(delim - msg) : strlen(msg);
/* Draw the line */
if (delim)
{
unsigned msg_len = delim - msg;
d3d12_font_render_line(d3d12,
font, msg, msg_len, scale, color, pos_x,
pos_y - (float)lines * line_height, width, height, text_align);
if (!delim)
break;
msg += msg_len + 1;
lines++;
}
else
{
unsigned msg_len = strlen(msg);
d3d12_font_render_line(d3d12,
font, msg, msg_len, scale, color, pos_x,
pos_y - (float)lines * line_height, width, height, text_align);
break;
}
}
}
static void d3d12_font_render_msg(

View File

@ -366,11 +366,10 @@ static INLINE void write_quad6(SpriteVertex *pv,
for (;;)
{
const char *delim = strchr(msg, '\n');
NSUInteger msg_len = delim ?
(unsigned)(delim - msg) : strlen(msg);
/* Draw the line */
if (delim)
{
NSUInteger msg_len = delim - msg;
[self _renderLine:msg
length:msg_len
scale:scale
@ -378,22 +377,13 @@ static INLINE void write_quad6(SpriteVertex *pv,
posX:posX
posY:posY - (float)lines * line_height
aligned:aligned];
if (!delim)
break;
msg += msg_len + 1;
lines++;
}
else
{
NSUInteger msg_len = strlen(msg);
[self _renderLine:msg
length:msg_len
scale:scale
color:color
posX:posX
posY:posY - (float)lines * line_height
aligned:aligned];
break;
}
}
}
- (void)renderMessage:(const char *)msg

View File

@ -197,7 +197,7 @@ static void switch_font_render_message(
int lines = 0;
float line_height;
if (!msg || !*msg)
if (!msg || !*msg || !sw)
return;
/* If font line metrics are not supported just draw as usual */
@ -218,34 +218,21 @@ static void switch_font_render_message(
for (;;)
{
const char *delim = strchr(msg, '\n');
unsigned msg_len = delim ?
(unsigned)(delim - msg) : strlen(msg);
/* Draw the line */
if (delim)
{
unsigned msg_len = delim - msg;
if (msg_len <= AVG_GLPYH_LIMIT)
{
if (sw)
switch_font_render_line(sw, font, msg, msg_len,
scale, color, pos_x, pos_y - (float)lines * line_height,
text_align);
}
if (!delim)
break;
msg += msg_len + 1;
lines++;
}
else
{
unsigned msg_len = strlen(msg);
if (msg_len <= AVG_GLPYH_LIMIT)
{
if (sw)
switch_font_render_line(sw, font, msg, msg_len,
scale, color, pos_x, pos_y - (float)lines * line_height,
text_align);
}
break;
}
}
}
static void switch_font_render_msg(

View File

@ -246,13 +246,14 @@ static void vita2d_font_render_message(
for (;;)
{
const char *delim = strchr(msg, '\n');
unsigned msg_len = (delim) ? (delim - msg) : strlen(msg);
unsigned msg_len = (delim) ?
(unsigned)(delim - msg) : strlen(msg);
/* Draw the line */
vita2d_font_render_line(font, msg, msg_len,
scale, color, pos_x, pos_y - (float)lines * line_height,
width, height, text_align);
/* Draw the line */
if (!delim)
break;

View File

@ -244,7 +244,6 @@ 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))
{
if (font->vk)
vulkan_raster_font_render_line(font, msg, strlen(msg),
scale, color, pos_x, pos_y, text_align);
return;
@ -255,28 +254,20 @@ static void vulkan_raster_font_render_message(
for (;;)
{
const char *delim = strchr(msg, '\n');
unsigned msg_len = delim
? (unsigned)(delim - msg) : (unsigned)strlen(msg);
/* Draw the line */
if (delim)
{
unsigned msg_len = delim - msg;
if (font->vk)
vulkan_raster_font_render_line(font, msg, msg_len,
scale, color, pos_x, pos_y - (float)lines * line_height,
text_align);
if (!delim)
break;
msg += msg_len + 1;
lines++;
}
else
{
unsigned msg_len = strlen(msg);
if (font->vk)
vulkan_raster_font_render_line(font, msg, msg_len,
scale, color, pos_x, pos_y - (float)lines * line_height,
text_align);
break;
}
}
}
static void vulkan_raster_font_flush(vulkan_raster_t *font)

View File

@ -263,26 +263,20 @@ static void wiiu_font_render_message(
for (;;)
{
const char* delim = strchr(msg, '\n');
unsigned msg_len = delim ?
(unsigned)(delim - msg) : strlen(msg);
/* Draw the line */
if (delim)
{
unsigned msg_len = delim - msg;
wiiu_font_render_line(wiiu, font, msg, msg_len,
scale, color, pos_x, pos_y - (float)lines * line_height,
width, height, text_align);
if (!delim)
break;
msg += msg_len + 1;
lines++;
}
else
{
unsigned msg_len = strlen(msg);
wiiu_font_render_line(wiiu, font, msg, msg_len,
scale, color, pos_x, pos_y - (float)lines * line_height,
width, height, text_align);
break;
}
}
}
static void wiiu_font_render_msg(