(drivers_font) Cut down on unnecessary strlen calls within a for loop

- precompute once for function duration
This commit is contained in:
twinaphex 2020-06-24 20:52:39 +02:00
parent 198df77c29
commit 3e9d0b8758
17 changed files with 121 additions and 66 deletions

View File

@ -89,6 +89,7 @@ static void caca_render_msg(
settings_t *settings = config_get_ptr(); settings_t *settings = config_get_ptr();
float video_msg_pos_x = settings->floats.video_msg_pos_x; float video_msg_pos_x = settings->floats.video_msg_pos_x;
float video_msg_pos_y = settings->floats.video_msg_pos_y; float video_msg_pos_y = settings->floats.video_msg_pos_y;
size_t _msg_len = strlen(msg);
if (!font || string_is_empty(msg)) if (!font || string_is_empty(msg))
return; return;
@ -119,10 +120,10 @@ static void caca_render_msg(
switch (align) switch (align)
{ {
case TEXT_ALIGN_RIGHT: case TEXT_ALIGN_RIGHT:
newX = (x * width * scale) - strlen(msg); newX = (x * width * scale) - _msg_len;
break; break;
case TEXT_ALIGN_CENTER: case TEXT_ALIGN_CENTER:
newX = (x * width * scale) - (strlen(msg) / 2); newX = (x * width * scale) - (_msg_len / 2);
break; break;
case TEXT_ALIGN_LEFT: case TEXT_ALIGN_LEFT:
default: default:

View File

@ -312,9 +312,10 @@ static void ctr_font_render_message(
const unsigned int color, float pos_x, float pos_y, const unsigned int color, float pos_x, float pos_y,
unsigned width, unsigned height, unsigned text_align) unsigned width, unsigned height, unsigned text_align)
{ {
float line_height;
struct font_line_metrics *line_metrics = NULL; struct font_line_metrics *line_metrics = NULL;
int lines = 0; int lines = 0;
float line_height; size_t _msg_len = strlen(msg);
if (!msg || !*msg) if (!msg || !*msg)
return; return;
@ -323,7 +324,7 @@ static void ctr_font_render_message(
if (!font->font_driver->get_line_metrics || if (!font->font_driver->get_line_metrics ||
!font->font_driver->get_line_metrics(font->font_data, &line_metrics)) !font->font_driver->get_line_metrics(font->font_data, &line_metrics))
{ {
ctr_font_render_line(ctr, font, msg, strlen(msg), ctr_font_render_line(ctr, font, msg, (unsigned)_msg_len,
scale, color, pos_x, pos_y, scale, color, pos_x, pos_y,
width, height, text_align); width, height, text_align);
return; return;
@ -347,7 +348,7 @@ static void ctr_font_render_message(
} }
else else
{ {
unsigned msg_len = strlen(msg); unsigned msg_len = (unsigned)_msg_len;
ctr_font_render_line(ctr, font, msg, msg_len, ctr_font_render_line(ctr, font, msg, msg_len,
scale, color, pos_x, pos_y - (float)lines * line_height, scale, color, pos_x, pos_y - (float)lines * line_height,
width, height, text_align); width, height, text_align);

View File

@ -237,19 +237,22 @@ static void d3d10_font_render_message(
unsigned height, unsigned height,
unsigned text_align) unsigned text_align)
{ {
float line_height;
struct font_line_metrics *line_metrics = NULL; struct font_line_metrics *line_metrics = NULL;
int lines = 0; int lines = 0;
float line_height; size_t _msg_len = 0;
if (!msg || !*msg) if (!msg || !*msg)
return; return;
_msg_len = strlen(msg);
/* If font line metrics are not supported just draw as usual */ /* If font line metrics are not supported just draw as usual */
if (!font->font_driver->get_line_metrics || if (!font->font_driver->get_line_metrics ||
!font->font_driver->get_line_metrics(font->font_data, &line_metrics)) !font->font_driver->get_line_metrics(font->font_data, &line_metrics))
{ {
d3d10_font_render_line(d3d10, d3d10_font_render_line(d3d10,
font, msg, strlen(msg), scale, color, pos_x, pos_y, font, msg, (unsigned)_msg_len, scale, color, pos_x, pos_y,
width, height, text_align); width, height, text_align);
return; return;
} }
@ -273,7 +276,7 @@ static void d3d10_font_render_message(
} }
else else
{ {
unsigned msg_len = strlen(msg); unsigned msg_len = (unsigned)_msg_len;
d3d10_font_render_line(d3d10, d3d10_font_render_line(d3d10,
font, msg, msg_len, scale, color, pos_x, font, msg, msg_len, scale, color, pos_x,
pos_y - (float)lines * line_height, pos_y - (float)lines * line_height,

View File

@ -234,19 +234,22 @@ static void d3d11_font_render_message(
unsigned height, unsigned height,
unsigned text_align) unsigned text_align)
{ {
float line_height;
struct font_line_metrics *line_metrics = NULL; struct font_line_metrics *line_metrics = NULL;
int lines = 0; int lines = 0;
float line_height; size_t _msg_len = 0;
if (!msg || !*msg) if (!msg || !*msg)
return; return;
_msg_len = strlen(msg);
/* If font line metrics are not supported just draw as usual */ /* If font line metrics are not supported just draw as usual */
if (!font->font_driver->get_line_metrics || if (!font->font_driver->get_line_metrics ||
!font->font_driver->get_line_metrics(font->font_data, &line_metrics)) !font->font_driver->get_line_metrics(font->font_data, &line_metrics))
{ {
d3d11_font_render_line(d3d11, d3d11_font_render_line(d3d11,
font, msg, strlen(msg), scale, color, pos_x, pos_y, font, msg, (unsigned)_msg_len, scale, color, pos_x, pos_y,
width, height, text_align); width, height, text_align);
return; return;
} }
@ -270,7 +273,7 @@ static void d3d11_font_render_message(
} }
else else
{ {
unsigned msg_len = strlen(msg); unsigned msg_len = (unsigned)_msg_len;
d3d11_font_render_line(d3d11, d3d11_font_render_line(d3d11,
font, msg, msg_len, scale, color, pos_x, font, msg, msg_len, scale, color, pos_x,
pos_y - (float)lines * line_height, pos_y - (float)lines * line_height,

View File

@ -248,19 +248,22 @@ static void d3d12_font_render_message(
unsigned height, unsigned height,
unsigned text_align) unsigned text_align)
{ {
float line_height;
struct font_line_metrics *line_metrics = NULL; struct font_line_metrics *line_metrics = NULL;
int lines = 0; int lines = 0;
float line_height; size_t _msg_len = 0;
if (!msg || !*msg) if (!msg || !*msg)
return; return;
_msg_len = strlen(msg);
/* If font line metrics are not supported just draw as usual */ /* If font line metrics are not supported just draw as usual */
if (!font->font_driver->get_line_metrics || if (!font->font_driver->get_line_metrics ||
!font->font_driver->get_line_metrics(font->font_data, &line_metrics)) !font->font_driver->get_line_metrics(font->font_data, &line_metrics))
{ {
d3d12_font_render_line(d3d12, d3d12_font_render_line(d3d12,
font, msg, strlen(msg), font, msg, _msg_len,
scale, color, pos_x, pos_y, width, height, text_align); scale, color, pos_x, pos_y, width, height, text_align);
return; return;
} }
@ -283,7 +286,7 @@ static void d3d12_font_render_message(
} }
else else
{ {
unsigned msg_len = strlen(msg); unsigned msg_len = (unsigned)_msg_len;
d3d12_font_render_line(d3d12, d3d12_font_render_line(d3d12,
font, msg, msg_len, scale, color, pos_x, font, msg, msg_len, scale, color, pos_x,
pos_y - (float)lines * line_height, width, height, text_align); pos_y - (float)lines * line_height, width, height, text_align);

View File

@ -120,7 +120,7 @@ static int d3dfonts_w32_get_message_width(void* data, const char* msg,
return 0; return 0;
d3d9x_font_draw_text(d3dfonts->font, NULL, (void*)msg, d3d9x_font_draw_text(d3dfonts->font, NULL, (void*)msg,
msg_len? msg_len : -1, &box, DT_CALCRECT, 0); msg_len ? msg_len : -1, &box, DT_CALCRECT, 0);
return box.right - box.left; return box.right - box.left;
} }

View File

@ -90,12 +90,13 @@ static void gdi_render_msg(
const struct font_params *params) const struct font_params *params)
{ {
float x, y, scale, drop_mod, drop_alpha; float x, y, scale, drop_mod, drop_alpha;
int drop_x, drop_y, msg_strlen; int drop_x, drop_y;
unsigned i; unsigned i;
unsigned newX, newY, newDropX, newDropY; unsigned newX, newY, newDropX, newDropY;
unsigned align; unsigned align;
unsigned red, green, blue; unsigned red, green, blue;
unsigned drop_red, drop_green, drop_blue; unsigned drop_red, drop_green, drop_blue;
size_t _msg_len = 0;
gdi_t *gdi = (gdi_t*)userdata; gdi_t *gdi = (gdi_t*)userdata;
gdi_raster_t *font = (gdi_raster_t*)data; gdi_raster_t *font = (gdi_raster_t*)data;
unsigned width = gdi->video_width; unsigned width = gdi->video_width;
@ -142,9 +143,9 @@ static void gdi_render_msg(
blue = video_msg_color_b * 255.0f; blue = video_msg_color_b * 255.0f;
} }
msg_strlen = strlen(msg); _msg_len = strlen(msg);
GetTextExtentPoint32(font->gdi->memDC, msg, msg_strlen, &textSize); GetTextExtentPoint32(font->gdi->memDC, msg, (int)_msg_len, &textSize);
switch (align) switch (align)
{ {
@ -166,21 +167,21 @@ static void gdi_render_msg(
break; break;
} }
newY = height - (y * height * scale) - textSize.cy; newY = height - (y * height * scale) - textSize.cy;
newDropY = height - (drop_y * height * scale) - textSize.cy; newDropY = height - (drop_y * height * scale) - textSize.cy;
font->gdi->bmp_old = (HBITMAP)SelectObject(font->gdi->memDC, font->gdi->bmp); font->gdi->bmp_old = (HBITMAP)SelectObject(font->gdi->memDC, font->gdi->bmp);
SetBkMode(font->gdi->memDC, TRANSPARENT); SetBkMode(font->gdi->memDC, TRANSPARENT);
msg_list = string_split(msg, "\n"); msg_list = string_split(msg, "\n");
if (drop_x || drop_y) if (drop_x || drop_y)
{ {
float dark_alpha = drop_alpha; float dark_alpha = drop_alpha;
drop_red = red * drop_mod * dark_alpha; drop_red = red * drop_mod * dark_alpha;
drop_green = green * drop_mod * dark_alpha; drop_green = green * drop_mod * dark_alpha;
drop_blue = blue * drop_mod * dark_alpha; drop_blue = blue * drop_mod * dark_alpha;
SetTextColor(font->gdi->memDC, RGB(drop_red, drop_green, drop_blue)); SetTextColor(font->gdi->memDC, RGB(drop_red, drop_green, drop_blue));

View File

@ -382,16 +382,22 @@ static void gl1_raster_font_render_message(
const GLfloat color[4], GLfloat pos_x, GLfloat pos_y, const GLfloat color[4], GLfloat pos_x, GLfloat pos_y,
unsigned text_align) unsigned text_align)
{ {
float line_height;
struct font_line_metrics *line_metrics = NULL; struct font_line_metrics *line_metrics = NULL;
int lines = 0; int lines = 0;
float line_height; size_t _msg_len = 0;
if (!msg || !*msg)
return;
_msg_len = strlen(msg);
/* If font line metrics are not supported just draw as usual */ /* If font line metrics are not supported just draw as usual */
if (!font->font_driver->get_line_metrics || if (!font->font_driver->get_line_metrics ||
!font->font_driver->get_line_metrics(font->font_data, &line_metrics)) !font->font_driver->get_line_metrics(font->font_data, &line_metrics))
{ {
gl1_raster_font_render_line(font, gl1_raster_font_render_line(font,
msg, (unsigned)strlen(msg), scale, color, pos_x, msg, (unsigned)_msg_len, scale, color, pos_x,
pos_y, text_align); pos_y, text_align);
return; return;
} }
@ -402,7 +408,7 @@ static void gl1_raster_font_render_message(
{ {
const char *delim = strchr(msg, '\n'); const char *delim = strchr(msg, '\n');
unsigned msg_len = delim unsigned msg_len = delim
? (unsigned)(delim - msg) : (unsigned)strlen(msg); ? (unsigned)(delim - msg) : (unsigned)_msg_len;
/* Draw the line */ /* Draw the line */
gl1_raster_font_render_line(font, gl1_raster_font_render_line(font,

View File

@ -293,16 +293,22 @@ static void gl_core_raster_font_render_message(
const GLfloat color[4], GLfloat pos_x, GLfloat pos_y, const GLfloat color[4], GLfloat pos_x, GLfloat pos_y,
unsigned text_align) unsigned text_align)
{ {
float line_height;
struct font_line_metrics *line_metrics = NULL; struct font_line_metrics *line_metrics = NULL;
int lines = 0; int lines = 0;
float line_height; size_t _msg_len = 0;
if (!msg || !*msg)
return;
_msg_len = strlen(msg);
/* If font line metrics are not supported just draw as usual */ /* If font line metrics are not supported just draw as usual */
if (!font->font_driver->get_line_metrics || if (!font->font_driver->get_line_metrics ||
!font->font_driver->get_line_metrics(font->font_data, &line_metrics)) !font->font_driver->get_line_metrics(font->font_data, &line_metrics))
{ {
gl_core_raster_font_render_line(font, gl_core_raster_font_render_line(font,
msg, (unsigned)strlen(msg), scale, color, pos_x, msg, _msg_len, scale, color, pos_x,
pos_y, text_align); pos_y, text_align);
return; return;
} }
@ -313,7 +319,7 @@ static void gl_core_raster_font_render_message(
{ {
const char *delim = strchr(msg, '\n'); const char *delim = strchr(msg, '\n');
unsigned msg_len = delim unsigned msg_len = delim
? (unsigned)(delim - msg) : (unsigned)strlen(msg); ? (unsigned)(delim - msg) : _msg_len;
/* Draw the line */ /* Draw the line */
gl_core_raster_font_render_line(font, gl_core_raster_font_render_line(font,

View File

@ -362,16 +362,22 @@ static void gl_raster_font_render_message(
const GLfloat color[4], GLfloat pos_x, GLfloat pos_y, const GLfloat color[4], GLfloat pos_x, GLfloat pos_y,
unsigned text_align) unsigned text_align)
{ {
float line_height;
struct font_line_metrics *line_metrics = NULL; struct font_line_metrics *line_metrics = NULL;
int lines = 0; int lines = 0;
float line_height; size_t _msg_len = 0;
if (!msg || !*msg)
return;
_msg_len = strlen(msg);
/* If font line metrics are not supported just draw as usual */ /* If font line metrics are not supported just draw as usual */
if (!font->font_driver->get_line_metrics || if (!font->font_driver->get_line_metrics ||
!font->font_driver->get_line_metrics(font->font_data, &line_metrics)) !font->font_driver->get_line_metrics(font->font_data, &line_metrics))
{ {
gl_raster_font_render_line(font, gl_raster_font_render_line(font,
msg, (unsigned)strlen(msg), scale, color, pos_x, msg, (unsigned)_msg_len, scale, color, pos_x,
pos_y, text_align); pos_y, text_align);
return; return;
} }
@ -382,7 +388,7 @@ static void gl_raster_font_render_message(
{ {
const char *delim = strchr(msg, '\n'); const char *delim = strchr(msg, '\n');
unsigned msg_len = delim unsigned msg_len = delim
? (unsigned)(delim - msg) : (unsigned)strlen(msg); ? (unsigned)(delim - msg) : (unsigned)_msg_len;
/* Draw the line */ /* Draw the line */
gl_raster_font_render_line(font, gl_raster_font_render_line(font,

View File

@ -350,18 +350,25 @@ static INLINE void write_quad6(SpriteVertex *pv,
posY:(float)posY posY:(float)posY
aligned:(unsigned)aligned aligned:(unsigned)aligned
{ {
float line_height;
int lines = 0;
struct font_line_metrics *line_metrics = NULL; struct font_line_metrics *line_metrics = NULL;
size_t _msg_len = 0;
if (!msg || !*msg)
return;
_msg_len = strlen(msg);
/* If font line metrics are not supported just draw as usual */ /* If font line metrics are not supported just draw as usual */
if (!_font_driver->get_line_metrics || if (!_font_driver->get_line_metrics ||
!_font_driver->get_line_metrics(_font_data, &line_metrics)) !_font_driver->get_line_metrics(_font_data, &line_metrics))
{ {
[self _renderLine:msg length:strlen(msg) scale:scale color:color posX:posX posY:posY aligned:aligned]; [self _renderLine:msg length:(unsigned)_msg_len scale:scale color:color posX:posX posY:posY aligned:aligned];
return; return;
} }
int lines = 0; line_height = line_metrics->height * scale / height;
float line_height = line_metrics->height * scale / height;
for (;;) for (;;)
{ {
@ -383,7 +390,7 @@ static INLINE void write_quad6(SpriteVertex *pv,
} }
else else
{ {
NSUInteger msg_len = strlen(msg); NSUInteger msg_len = (NSUInteger)_msg_len;
[self _renderLine:msg [self _renderLine:msg
length:msg_len length:msg_len
scale:scale scale:scale

View File

@ -83,17 +83,20 @@ static void sixel_render_msg(
{ {
float x, y, scale; float x, y, scale;
unsigned width, height; unsigned width, height;
unsigned newX, newY; unsigned new_x, new_y;
unsigned align; unsigned align;
sixel_raster_t *font = (sixel_raster_t*)data; sixel_raster_t *font = (sixel_raster_t*)data;
const struct font_params *params = (const struct font_params*)_params; const struct font_params *params = (const struct font_params*)_params;
settings_t *settings = config_get_ptr(); settings_t *settings = config_get_ptr();
float video_msg_pos_x = settings->floats.video_msg_pos_x; float video_msg_pos_x = settings->floats.video_msg_pos_x;
float video_msg_pos_y = settings->floats.video_msg_pos_y; float video_msg_pos_y = settings->floats.video_msg_pos_y;
size_t _msg_len = 0;
if (!font || string_is_empty(msg)) if (!font || string_is_empty(msg))
return; return;
_msg_len = strlen(msg);
if (params) if (params)
{ {
x = params->x; x = params->x;
@ -114,19 +117,19 @@ static void sixel_render_msg(
width = font->sixel->screen_width; width = font->sixel->screen_width;
height = font->sixel->screen_height; height = font->sixel->screen_height;
newY = height - (y * height * scale); new_y = height - (y * height * scale);
switch (align) switch (align)
{ {
case TEXT_ALIGN_RIGHT: case TEXT_ALIGN_RIGHT:
newX = (x * width * scale) - strlen(msg); new_x = (x * width * scale) - _msg_len;
break; break;
case TEXT_ALIGN_CENTER: case TEXT_ALIGN_CENTER:
newX = (x * width * scale) - (strlen(msg) / 2); new_x = (x * width * scale) - (_msg_len / 2);
break; break;
case TEXT_ALIGN_LEFT: case TEXT_ALIGN_LEFT:
default: default:
newX = x * width * scale; new_x = x * width * scale;
break; break;
} }

View File

@ -193,22 +193,24 @@ static void switch_font_render_message(
const unsigned int color, float pos_x, float pos_y, const unsigned int color, float pos_x, float pos_y,
unsigned text_align) unsigned text_align)
{ {
float line_height;
struct font_line_metrics *line_metrics = NULL; struct font_line_metrics *line_metrics = NULL;
int lines = 0; int lines = 0;
float line_height; size_t _msg_len = 0;
if (!msg || !*msg) if (!msg || !*msg)
return; return;
_msg_len = strlen(msg);
/* If font line metrics are not supported just draw as usual */ /* If font line metrics are not supported just draw as usual */
if (!font->font_driver->get_line_metrics || if (!font->font_driver->get_line_metrics ||
!font->font_driver->get_line_metrics(font->font_data, &line_metrics)) !font->font_driver->get_line_metrics(font->font_data, &line_metrics))
{ {
int msgLen = strlen(msg); if (_msg_len <= AVG_GLPYH_LIMIT)
if (msgLen <= AVG_GLPYH_LIMIT)
{ {
if (sw) if (sw)
switch_font_render_line(sw, font, msg, strlen(msg), switch_font_render_line(sw, font, msg, (unsigned)_msg_len,
scale, color, pos_x, pos_y, text_align); scale, color, pos_x, pos_y, text_align);
} }
return; return;
@ -235,11 +237,10 @@ static void switch_font_render_message(
} }
else else
{ {
unsigned msg_len = strlen(msg); if (_msg_len <= AVG_GLPYH_LIMIT)
if (msg_len <= AVG_GLPYH_LIMIT)
{ {
if (sw) if (sw)
switch_font_render_line(sw, font, msg, msg_len, switch_font_render_line(sw, font, msg, (unsigned)_msg_len,
scale, color, pos_x, pos_y - (float)lines * line_height, scale, color, pos_x, pos_y - (float)lines * line_height,
text_align); text_align);
} }

View File

@ -89,10 +89,13 @@ static void vga_render_msg(
settings_t *settings = config_get_ptr(); settings_t *settings = config_get_ptr();
float video_msg_pos_x = settings->floats.video_msg_pos_x; float video_msg_pos_x = settings->floats.video_msg_pos_x;
float video_msg_pos_y = settings->floats.video_msg_pos_y; float video_msg_pos_y = settings->floats.video_msg_pos_y;
size_t _msg_len = 0;
if (!font || string_is_empty(msg)) if (!font || string_is_empty(msg))
return; return;
_msg_len = strlen(msg);
if (params) if (params)
{ {
x = params->x; x = params->x;
@ -121,10 +124,10 @@ static void vga_render_msg(
new_x = x * width * scale; new_x = x * width * scale;
break; break;
case TEXT_ALIGN_RIGHT: case TEXT_ALIGN_RIGHT:
new_x = (x * width * scale) - strlen(msg); new_x = (x * width * scale) - _msg_len;
break; break;
case TEXT_ALIGN_CENTER: case TEXT_ALIGN_CENTER:
new_x = (x * width * scale) - (strlen(msg) / 2); new_x = (x * width * scale) - (_msg_len / 2);
break; break;
default: default:
break; break;

View File

@ -225,18 +225,21 @@ static void vita2d_font_render_message(
const unsigned int color, float pos_x, float pos_y, const unsigned int color, float pos_x, float pos_y,
unsigned width, unsigned height, unsigned text_align) unsigned width, unsigned height, unsigned text_align)
{ {
float line_height;
struct font_line_metrics *line_metrics = NULL; struct font_line_metrics *line_metrics = NULL;
int lines = 0; int lines = 0;
float line_height; size_t _msg_len = 0;
if (!msg || !*msg) if (!msg || !*msg)
return; return;
_msg_len = strlen(msg);
/* If font line metrics are not supported just draw as usual */ /* If font line metrics are not supported just draw as usual */
if (!font->font_driver->get_line_metrics || if (!font->font_driver->get_line_metrics ||
!font->font_driver->get_line_metrics(font->font_data, &line_metrics)) !font->font_driver->get_line_metrics(font->font_data, &line_metrics))
{ {
vita2d_font_render_line(font, msg, strlen(msg), vita2d_font_render_line(font, msg, (unsigned)_msg_len,
scale, color, pos_x, pos_y, width, height, text_align); scale, color, pos_x, pos_y, width, height, text_align);
return; return;
} }
@ -246,7 +249,7 @@ static void vita2d_font_render_message(
for (;;) for (;;)
{ {
const char *delim = strchr(msg, '\n'); const char *delim = strchr(msg, '\n');
unsigned msg_len = (delim) ? (delim - msg) : strlen(msg); unsigned msg_len = (delim) ? (delim - msg) : (unsigned)_msg_len;
vita2d_font_render_line(font, msg, msg_len, vita2d_font_render_line(font, msg, msg_len,
scale, color, pos_x, pos_y - (float)lines * line_height, scale, color, pos_x, pos_y - (float)lines * line_height,

View File

@ -233,19 +233,22 @@ static void vulkan_raster_font_render_message(
const float color[4], float pos_x, float pos_y, const float color[4], float pos_x, float pos_y,
unsigned text_align) unsigned text_align)
{ {
float line_height;
struct font_line_metrics *line_metrics = NULL; struct font_line_metrics *line_metrics = NULL;
int lines = 0; int lines = 0;
float line_height; size_t _msg_len = 0;
if (!msg || !*msg || !font->vk) if (!msg || !*msg || !font->vk)
return; return;
_msg_len = strlen(msg);
/* If font line metrics are not supported just draw as usual */ /* If font line metrics are not supported just draw as usual */
if (!font->font_driver->get_line_metrics || if (!font->font_driver->get_line_metrics ||
!font->font_driver->get_line_metrics(font->font_data, &line_metrics)) !font->font_driver->get_line_metrics(font->font_data, &line_metrics))
{ {
if (font->vk) if (font->vk)
vulkan_raster_font_render_line(font, msg, strlen(msg), vulkan_raster_font_render_line(font, msg, (unsigned)_msg_len,
scale, color, pos_x, pos_y, text_align); scale, color, pos_x, pos_y, text_align);
return; return;
} }
@ -269,7 +272,7 @@ static void vulkan_raster_font_render_message(
} }
else else
{ {
unsigned msg_len = strlen(msg); unsigned msg_len = _msg_len;
if (font->vk) if (font->vk)
vulkan_raster_font_render_line(font, msg, msg_len, vulkan_raster_font_render_line(font, msg, msg_len,
scale, color, pos_x, pos_y - (float)lines * line_height, scale, color, pos_x, pos_y - (float)lines * line_height,

View File

@ -109,7 +109,7 @@ static void wiiu_font_free_font(void* data, bool is_threaded)
} }
static int wiiu_font_get_message_width(void* data, const char* msg, static int wiiu_font_get_message_width(void* data, const char* msg,
unsigned msg_len, float scale) unsigned msg_len, float scale)
{ {
wiiu_font_t* font = (wiiu_font_t*)data; wiiu_font_t* font = (wiiu_font_t*)data;
@ -150,7 +150,9 @@ static void wiiu_font_render_line(
float pos_y, float pos_y,
unsigned width, unsigned height, unsigned text_align) unsigned width, unsigned height, unsigned text_align)
{ {
int count;
unsigned i; unsigned i;
sprite_vertex_t *v = NULL;
int x = roundf(pos_x * width); int x = roundf(pos_x * width);
int y = roundf((1.0 - pos_y) * height); int y = roundf((1.0 - pos_y) * height);
@ -169,7 +171,7 @@ static void wiiu_font_render_line(
break; break;
} }
sprite_vertex_t* v = wiiu->vertex_cache.v + wiiu->vertex_cache.current; v = wiiu->vertex_cache.v + wiiu->vertex_cache.current;
for (i = 0; i < msg_len; i++) for (i = 0; i < msg_len; i++)
{ {
@ -207,7 +209,7 @@ static void wiiu_font_render_line(
y += glyph->advance_y * scale; y += glyph->advance_y * scale;
} }
int count = v - wiiu->vertex_cache.v - wiiu->vertex_cache.current; count = v - wiiu->vertex_cache.v - wiiu->vertex_cache.current;
if (!count) if (!count)
return; return;
@ -241,18 +243,21 @@ static void wiiu_font_render_message(
const unsigned int color, float pos_x, float pos_y, const unsigned int color, float pos_x, float pos_y,
unsigned width, unsigned height, unsigned text_align) unsigned width, unsigned height, unsigned text_align)
{ {
float line_height;
struct font_line_metrics *line_metrics = NULL; struct font_line_metrics *line_metrics = NULL;
int lines = 0; int lines = 0;
float line_height; size_t _msg_len = 0;
if (!msg || !*msg) if (!msg || !*msg)
return; return;
_msg_len = strlen(msg);
/* If font line metrics are not supported just draw as usual */ /* If font line metrics are not supported just draw as usual */
if (!font->font_driver->get_line_metrics || if (!font->font_driver->get_line_metrics ||
!font->font_driver->get_line_metrics(font->font_data, &line_metrics)) !font->font_driver->get_line_metrics(font->font_data, &line_metrics))
{ {
wiiu_font_render_line(wiiu, font, msg, strlen(msg), wiiu_font_render_line(wiiu, font, msg, (unsigned)_msg_len,
scale, color, pos_x, pos_y, scale, color, pos_x, pos_y,
width, height, text_align); width, height, text_align);
return; return;
@ -276,7 +281,7 @@ static void wiiu_font_render_message(
} }
else else
{ {
unsigned msg_len = strlen(msg); unsigned msg_len = (unsigned)_msg_len;
wiiu_font_render_line(wiiu, font, msg, msg_len, wiiu_font_render_line(wiiu, font, msg, msg_len,
scale, color, pos_x, pos_y - (float)lines * line_height, scale, color, pos_x, pos_y - (float)lines * line_height,
width, height, text_align); width, height, text_align);