mirror of https://github.com/mgba-emu/mgba.git
GUI: Properly support Unicode filenames
This commit is contained in:
parent
d357b93285
commit
04a81d2ec5
|
@ -26,9 +26,9 @@ void GUIFontPrint(const struct GUIFont* font, int x, int y, enum GUITextAlignmen
|
||||||
default:
|
default:
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
size_t i;
|
size_t len = strlen(text);
|
||||||
for (i = 0; text[i]; ++i) {
|
while (len) {
|
||||||
char c = text[i];
|
uint32_t c = utf8Char(&text, &len);
|
||||||
GUIFontDrawGlyph(font, x, y, color, c);
|
GUIFontDrawGlyph(font, x, y, color, c);
|
||||||
x += GUIFontGlyphWidth(font, c);
|
x += GUIFontGlyphWidth(font, c);
|
||||||
}
|
}
|
||||||
|
|
|
@ -39,7 +39,7 @@ char* strnrstr(const char* restrict haystack, const char* restrict needle, size_
|
||||||
return last;
|
return last;
|
||||||
}
|
}
|
||||||
|
|
||||||
static uint32_t _utf16Char(const uint16_t** unicode, size_t* length) {
|
uint32_t utf16Char(const uint16_t** unicode, size_t* length) {
|
||||||
if (*length < 2) {
|
if (*length < 2) {
|
||||||
*length = 0;
|
*length = 0;
|
||||||
return 0;
|
return 0;
|
||||||
|
@ -69,7 +69,7 @@ static uint32_t _utf16Char(const uint16_t** unicode, size_t* length) {
|
||||||
return (highSurrogate << 10) + lowSurrogate + 0x10000;
|
return (highSurrogate << 10) + lowSurrogate + 0x10000;
|
||||||
}
|
}
|
||||||
|
|
||||||
static uint32_t _utf8Char(const char** unicode, size_t* length) {
|
uint32_t utf8Char(const char** unicode, size_t* length) {
|
||||||
if (*length == 0) {
|
if (*length == 0) {
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
@ -150,8 +150,8 @@ int utfcmp(const uint16_t* utf16, const char* utf8, size_t utf16Length, size_t u
|
||||||
if (char1 > char2) {
|
if (char1 > char2) {
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
char1 = _utf16Char(&utf16, &utf16Length);
|
char1 = utf16Char(&utf16, &utf16Length);
|
||||||
char2 = _utf8Char(&utf8, &utf8Length);
|
char2 = utf8Char(&utf8, &utf8Length);
|
||||||
}
|
}
|
||||||
if (utf16Length == 0 && utf8Length > 0) {
|
if (utf16Length == 0 && utf8Length > 0) {
|
||||||
return -1;
|
return -1;
|
||||||
|
@ -172,7 +172,7 @@ char* utf16to8(const uint16_t* utf16, size_t length) {
|
||||||
if (length == 0) {
|
if (length == 0) {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
uint32_t unichar = _utf16Char(&utf16, &length);
|
uint32_t unichar = utf16Char(&utf16, &length);
|
||||||
size_t bytes = _toUtf8(unichar, buffer);
|
size_t bytes = _toUtf8(unichar, buffer);
|
||||||
utf8Length += bytes;
|
utf8Length += bytes;
|
||||||
if (utf8Length < utf8TotalBytes) {
|
if (utf8Length < utf8TotalBytes) {
|
||||||
|
|
|
@ -21,6 +21,8 @@ char* strnrstr(const char* restrict s1, const char* restrict s2, size_t len);
|
||||||
|
|
||||||
int utfcmp(const uint16_t* utf16, const char* utf8, size_t utf16Length, size_t utf8Length);
|
int utfcmp(const uint16_t* utf16, const char* utf8, size_t utf16Length, size_t utf8Length);
|
||||||
char* utf16to8(const uint16_t* utf16, size_t length);
|
char* utf16to8(const uint16_t* utf16, size_t length);
|
||||||
|
uint32_t utf8Char(const char** unicode, size_t* length);
|
||||||
|
uint32_t utf16Char(const uint16_t** unicode, size_t* length);
|
||||||
|
|
||||||
int hexDigit(char digit);
|
int hexDigit(char digit);
|
||||||
const char* hex32(const char* line, uint32_t* out);
|
const char* hex32(const char* line, uint32_t* out);
|
||||||
|
|
Loading…
Reference in New Issue