1
0
mirror of https://github.com/libretro/RetroArch synced 2024-07-05 09:48:42 +00:00

undo previous new files and use existing encoding_utf header

This commit is contained in:
Brad Parker 2016-08-23 19:16:18 -04:00
parent 80d4626908
commit 30e99927d2
9 changed files with 50 additions and 118 deletions

View File

@ -220,8 +220,7 @@ OBJ += frontend/frontend.o \
record/drivers/record_null.o \
libretro-common/features/features_cpu.o \
performance_counters.o \
verbosity.o \
libretro-common/string/utf8_util.o
verbosity.o
ifeq ($(HAVE_LANGEXTRA), 1)
DEFINES += -DHAVE_LANGEXTRA

View File

@ -17,7 +17,7 @@
#include "../common/gl_common.h"
#include "../font_driver.h"
#include "../video_shader_driver.h"
#include <string/utf8_util.h>
#include <encodings/utf.h>
/* TODO: Move viewport side effects to the caller: it's a source of bugs. */
@ -36,14 +36,6 @@
#define MAX_MSG_LEN_CHUNK 64
#ifdef HAVE_UTF8
#define string_walk utf8_walk
#define string_len utf8_strlen
#else
#define string_walk utf8_walkbyte
#define string_len strlen
#endif
typedef struct
{
gl_t *gl;
@ -307,7 +299,7 @@ static void gl_raster_font_render_line(
{
int off_x, off_y, tex_x, tex_y, width, height;
const struct font_glyph *glyph =
font->font_driver->get_glyph(font->font_data, string_walk(&msg));
font->font_driver->get_glyph(font->font_data, utf8_walk(&msg));
if (!glyph) /* Do something smarter here ... */
glyph = font->font_driver->get_glyph(font->font_data, '?');
@ -369,7 +361,7 @@ static void gl_raster_font_render_message(
/* If the font height is not supported just draw as usual */
if (!font->font_driver->get_line_height)
{
gl_raster_font_render_line(font, msg, string_len(msg),
gl_raster_font_render_line(font, msg, utf8len(msg),
scale, color, pos_x, pos_y, text_align);
return;
}
@ -393,7 +385,7 @@ static void gl_raster_font_render_message(
}
else
{
unsigned msg_len = string_len(msg);
unsigned msg_len = utf8len(msg);
gl_raster_font_render_line(font, msg, msg_len, scale, color, pos_x,
pos_y - (float)lines*line_height, text_align);
break;

View File

@ -208,3 +208,31 @@ size_t utf8len(const char *string)
return strlen(string);
#endif
}
uint8_t utf8_walkbyte(const char **string)
{
return *((*string)++);
}
/* Does not validate the input, returns garbage if it's not UTF-8. */
uint32_t utf8_walk(const char **string)
{
uint8_t first = utf8_walkbyte(string);
uint32_t ret;
if (first<128)
return first;
ret = 0;
ret = (ret<<6) | (utf8_walkbyte(string) & 0x3F);
if (first >= 0xE0)
ret = (ret<<6) | (utf8_walkbyte(string) & 0x3F);
if (first >= 0xF0)
ret = (ret<<6) | (utf8_walkbyte(string) & 0x3F);
if (first >= 0xF0)
return ret | (first&31)<<18;
if (first >= 0xE0)
return ret | (first&15)<<12;
return ret | (first&7)<<6;
}

View File

@ -40,4 +40,8 @@ size_t utf8cpy(char *d, size_t d_len, const char *s, size_t chars);
const char *utf8skip(const char *str, size_t chars);
uint8_t utf8_walkbyte(const char **string);
uint32_t utf8_walk(const char **string);
#endif

View File

@ -1,32 +0,0 @@
/* Copyright (C) 2010-2016 The RetroArch team
*
* ---------------------------------------------------------------------------------------
* The following license statement only applies to this file (utf8_util.h).
* ---------------------------------------------------------------------------------------
*
* Permission is hereby granted, free of charge,
* to any person obtaining a copy of this software and associated documentation files (the "Software"),
* to deal in the Software without restriction, including without limitation the rights to
* use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software,
* and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
* INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
* WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/
#ifndef __LIBRETRO_SDK_UTF8_UTIL_H__
#define __LIBRETRO_SDK_UTF8_UTIL_H__
#include <stdint.h>
unsigned utf8_strlen(const char *string);
uint8_t utf8_walkbyte(const char **string);
uint32_t utf8_walk(const char **string);
#endif

View File

@ -1,39 +0,0 @@
#include <string/utf8_util.h>
uint32_t utf8_strlen(const char *s)
{
int i = 0, j = 0;
while (s[i]) {
if ((s[i] & 0xc0) != 0x80) j++;
i++;
}
return j;
}
uint8_t utf8_walkbyte(const char **string)
{
return *((*string)++);
}
/* Does not validate the input, returns garbage if it's not UTF-8. */
uint32_t utf8_walk(const char **string)
{
uint8_t first = utf8_walkbyte(string);
uint32_t ret;
if (first<128)
return first;
ret = 0;
ret = (ret<<6) | (utf8_walkbyte(string) & 0x3F);
if (first >= 0xE0)
ret = (ret<<6) | (utf8_walkbyte(string) & 0x3F);
if (first >= 0xF0)
ret = (ret<<6) | (utf8_walkbyte(string) & 0x3F);
if (first >= 0xF0)
return ret | (first&31)<<18;
if (first >= 0xE0)
return ret | (first&15)<<12;
return ret | (first&7)<<6;
}

View File

@ -27,7 +27,7 @@
#include <gfx/math/matrix_4x4.h>
#include <string/stdstring.h>
#include <lists/string_list.h>
#include <string/utf8_util.h>
#include <encodings/utf.h>
#include "menu_generic.h"
@ -47,12 +47,6 @@
#include "../../file_path_special.h"
#ifdef HAVE_UTF8
#define string_len utf8_strlen
#else
#define string_len strlen
#endif
enum
{
MUI_TEXTURE_POINTER = 0,
@ -407,7 +401,7 @@ static void mui_render_messagebox(mui_handle_t *mui,
for (i = 0; i < list->size; i++)
{
const char *msg = list->elems[i].data;
int len = string_len(msg);
int len = utf8len(msg);
if (len > longest)
{
longest = len;
@ -530,7 +524,7 @@ static void mui_render_label_value(mui_handle_t *mui,
menu_animation_ctx_ticker_t ticker;
char label_str[PATH_MAX_LENGTH] = {0};
char value_str[PATH_MAX_LENGTH] = {0};
int value_len = string_len(value);
int value_len = utf8len(value);
int ticker_limit = 0;
uintptr_t texture_switch = 0;
bool do_draw_text = false;
@ -1183,7 +1177,7 @@ static void mui_frame(void *data)
snprintf(title_buf_msg, sizeof(title_buf), "%s (%s)",
title_buf, title_msg);
value_len = string_len(title_buf);
value_len = utf8len(title_buf);
ticker_limit = (usable_width / mui->glyph_width) - (value_len + 2);
ticker.s = title_buf_msg_tmp;

View File

@ -28,7 +28,7 @@
#include <file/file_path.h>
#include <retro_inline.h>
#include <string/stdstring.h>
#include <string/utf8_util.h>
#include <encodings/utf.h>
#include "menu_generic.h"
@ -46,14 +46,6 @@
#define RGUI_TERM_WIDTH(width) (((width - RGUI_TERM_START_X(width) - RGUI_TERM_START_X(width)) / (FONT_WIDTH_STRIDE)))
#define RGUI_TERM_HEIGHT(width, height) (((height - RGUI_TERM_START_Y(height) - RGUI_TERM_START_X(width)) / (FONT_HEIGHT_STRIDE)) - 1)
#ifdef HAVE_UTF8
#define string_walk utf8_walk
#define string_len utf8_strlen
#else
#define string_walk utf8_walkbyte
#define string_len strlen
#endif
typedef struct
{
bool force_redraw;
@ -185,7 +177,7 @@ static void blit_line(int x, int y,
while (!string_is_empty(message))
{
const uint8_t *font_fb = menu_display_get_font_framebuffer();
uint32_t symbol = string_walk(&message);
uint32_t symbol = utf8_walk(&message);
for (j = 0; j < FONT_HEIGHT; j++)
{
@ -322,7 +314,7 @@ static void rgui_render_messagebox(const char *message)
{
unsigned line_width;
char *msg = list->elems[i].data;
unsigned msglen = string_len(msg);
unsigned msglen = utf8len(msg);
if (msglen > RGUI_TERM_WIDTH(fb_width))
{
@ -357,7 +349,7 @@ static void rgui_render_messagebox(const char *message)
for (i = 0; i < list->size; i++)
{
const char *msg = list->elems[i].data;
int offset_x = FONT_WIDTH_STRIDE * (glyphs_width - string_len(msg)) / 2;
int offset_x = FONT_WIDTH_STRIDE * (glyphs_width - utf8len(msg)) / 2;
int offset_y = FONT_HEIGHT_STRIDE * i;
blit_line(x + 8 + offset_x, y + 8 + offset_y, msg, color);
@ -527,7 +519,7 @@ static void rgui_render(void *data)
blit_line(
RGUI_TERM_START_X(fb_width) + (RGUI_TERM_WIDTH(fb_width)
- string_len(title_buf)) * FONT_WIDTH_STRIDE / 2,
- utf8len(title_buf)) * FONT_WIDTH_STRIDE / 2,
RGUI_TERM_START_X(fb_width),
title_buf, TITLE_COLOR(settings));
@ -602,8 +594,8 @@ static void rgui_render(void *data)
snprintf(message, sizeof(message), "%c %-*.*s %-*s",
entry_selected ? '>' : ' ',
(int)(RGUI_TERM_WIDTH(fb_width) - (entry_spacing + 1 + 2) - utf8len(entry_title_buf) + string_len(entry_title_buf)),
(int)(RGUI_TERM_WIDTH(fb_width) - (entry_spacing + 1 + 2) - utf8len(entry_title_buf) + string_len(entry_title_buf)),
(int)(RGUI_TERM_WIDTH(fb_width) - (entry_spacing + 1 + 2) - utf8len(entry_title_buf) + strlen(entry_title_buf)),
(int)(RGUI_TERM_WIDTH(fb_width) - (entry_spacing + 1 + 2) - utf8len(entry_title_buf) + strlen(entry_title_buf)),
entry_title_buf,
entry_spacing,
type_str_buf);

View File

@ -27,7 +27,7 @@
#include <string/stdstring.h>
#include <lists/string_list.h>
#include <gfx/math/matrix_4x4.h>
#include <string/utf8_util.h>
#include <encodings/utf.h>
#include "menu_generic.h"
@ -57,12 +57,6 @@
#define XMB_DELAY 10
#endif
#ifdef HAVE_UTF8
#define string_len utf8_strlen
#else
#define string_len strlen
#endif
typedef struct
{
float alpha;
@ -708,7 +702,7 @@ static void xmb_render_messagebox_internal(
for (i = 0; i < list->size; i++)
{
const char *msg = list->elems[i].data;
int len = string_len(msg);
int len = utf8len(msg);
if (len > longest)
{
longest = len;