PSP2: Allow UTF-8 filenames

This commit is contained in:
Jeffrey Pfau 2016-08-18 10:06:30 -07:00
parent 57c1275890
commit d82f8feef5
4 changed files with 9 additions and 11 deletions

View File

@ -60,6 +60,7 @@ Misc:
- GBA Savedata: Add realistic timing for EEPROM - GBA Savedata: Add realistic timing for EEPROM
- GBA Video: Optimize mode 0 rendering - GBA Video: Optimize mode 0 rendering
- Qt: Remove default autofire mappings - Qt: Remove default autofire mappings
- PSP2: Allow UTF-8 filenames
0.4.1: (2016-07-11) 0.4.1: (2016-07-11)
Bugfixes: Bugfixes:

View File

@ -41,10 +41,8 @@ unsigned GUIFontHeight(const struct GUIFont* font) {
} }
unsigned GUIFontGlyphWidth(const struct GUIFont* font, uint32_t glyph) { unsigned GUIFontGlyphWidth(const struct GUIFont* font, uint32_t glyph) {
if (glyph > 0x7F) { char base[5] = { 0 };
glyph = '?'; toUtf8(glyph, base);
}
char base[5] = { glyph };
return vita2d_pgf_text_width(font->pgf, FONT_SIZE, base); return vita2d_pgf_text_width(font->pgf, FONT_SIZE, base);
} }
@ -68,10 +66,8 @@ void GUIFontIconMetrics(const struct GUIFont* font, enum GUIIcon icon, unsigned*
} }
void GUIFontDrawGlyph(const struct GUIFont* font, int x, int y, uint32_t color, uint32_t glyph) { void GUIFontDrawGlyph(const struct GUIFont* font, int x, int y, uint32_t color, uint32_t glyph) {
if (glyph > 0x7F) { char base[5] = { 0 };
glyph = '?'; toUtf8(glyph, base);
}
char base[5] = { glyph };
vita2d_pgf_draw_text(font->pgf, x, y, color, FONT_SIZE, base); vita2d_pgf_draw_text(font->pgf, x, y, color, FONT_SIZE, base);
} }

View File

@ -80,7 +80,7 @@ uint32_t utf8Char(const char** unicode, size_t* length) {
return byte; return byte;
} }
uint32_t unichar; uint32_t unichar;
static int tops[4] = { 0xC0, 0xE0, 0xF0, 0xF8 }; static const int tops[4] = { 0xC0, 0xE0, 0xF0, 0xF8 };
size_t numBytes; size_t numBytes;
for (numBytes = 0; numBytes < 3; ++numBytes) { for (numBytes = 0; numBytes < 3; ++numBytes) {
if ((byte & tops[numBytes + 1]) == tops[numBytes]) { if ((byte & tops[numBytes + 1]) == tops[numBytes]) {
@ -110,7 +110,7 @@ uint32_t utf8Char(const char** unicode, size_t* length) {
return unichar; return unichar;
} }
static size_t _toUtf8(uint32_t unichar, char* buffer) { size_t toUtf8(uint32_t unichar, char* buffer) {
if (unichar > 0x10FFFF) { if (unichar > 0x10FFFF) {
unichar = 0xFFFD; unichar = 0xFFFD;
} }
@ -173,7 +173,7 @@ char* utf16to8(const uint16_t* utf16, size_t length) {
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) {
memcpy(offset, buffer, bytes); memcpy(offset, buffer, bytes);

View File

@ -19,6 +19,7 @@ char* strdup(const char* str);
char* strnrstr(const char* restrict s1, const char* restrict s2, size_t len); char* strnrstr(const char* restrict s1, const char* restrict s2, size_t len);
size_t toUtf8(uint32_t unichar, char* buffer);
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 utf8Char(const char** unicode, size_t* length);