add unicode-aware option for word_wrap (only needed for xmb)

This commit is contained in:
Brad Parker 2017-08-06 03:32:04 -04:00
parent 99a8d2ec86
commit 6b369775cf
4 changed files with 24 additions and 9 deletions

View File

@ -87,7 +87,7 @@ char *string_trim_whitespace_right(char *const s);
/* Remove leading and trailing whitespaces */
char *string_trim_whitespace(char *const s);
char *word_wrap(char* buffer, const char *string, int line_width);
char *word_wrap(char* buffer, const char *string, int line_width, bool unicode);
RETRO_END_DECLS

View File

@ -24,6 +24,7 @@
#include <ctype.h>
#include <string/stdstring.h>
#include <encodings/utf.h>
char *string_to_upper(char *s)
{
@ -144,7 +145,7 @@ char *string_trim_whitespace(char *const s)
return s;
}
char *word_wrap(char* buffer, const char *string, int line_width)
char *word_wrap(char* buffer, const char *string, int line_width, bool unicode)
{
unsigned i = 0;
unsigned len = (unsigned)strlen(string);
@ -156,20 +157,34 @@ char *word_wrap(char* buffer, const char *string, int line_width)
/* copy string until the end of the line is reached */
for (counter = 1; counter <= (unsigned)line_width; counter++)
{
const char *character;
unsigned char_len;
unsigned j = i;
character = utf8skip(&string[i], 1);
char_len = character - &string[i];
/* check if end of string reached */
if (i == strlen(string))
if (i == len)
{
buffer[i] = 0;
return buffer;
}
buffer[i] = string[i];
if (!unicode)
counter += char_len - 1;
do
{
buffer[i] = string[i];
char_len--;
i++;
} while(char_len);
/* check for newlines embedded in the original input
* and reset the index */
if (buffer[i] == '\n')
if (buffer[j] == '\n')
counter = 1;
i++;
}
/* check for whitespace */

View File

@ -562,7 +562,7 @@ static void mui_compute_entries_box(mui_handle_t* mui, int width)
if (menu_entry_get_sublabel(i, sublabel_str, sizeof(sublabel_str)))
{
word_wrap(sublabel_str, sublabel_str, (int)(usable_width / mui->glyph_width2));
word_wrap(sublabel_str, sublabel_str, (int)(usable_width / mui->glyph_width2), false);
lines = mui_count_lines(sublabel_str);
}
@ -715,7 +715,7 @@ static void mui_render_label_value(mui_handle_t *mui, mui_node_t *node,
if (menu_entry_get_sublabel(i, sublabel_str, sizeof(sublabel_str)))
{
word_wrap(sublabel_str, sublabel_str, (int)(usable_width / mui->glyph_width2));
word_wrap(sublabel_str, sublabel_str, (int)(usable_width / mui->glyph_width2), false);
menu_display_draw_text(mui->font2, sublabel_str,
mui->margin,

View File

@ -2328,7 +2328,7 @@ static void xmb_draw_items(
label_offset = - xmb->margins.label.top;
word_wrap(entry_sublabel, entry.sublabel, 50);
word_wrap(entry_sublabel, entry.sublabel, 50, true);
xmb_draw_text(menu_disp_info, xmb, entry_sublabel,
node->x + xmb->margins.screen.left +