From d82f8feef5bdadccb07f308b0382cd650250ba03 Mon Sep 17 00:00:00 2001 From: Jeffrey Pfau Date: Thu, 18 Aug 2016 10:06:30 -0700 Subject: [PATCH] PSP2: Allow UTF-8 filenames --- CHANGES | 1 + src/platform/psp2/gui-font.c | 12 ++++-------- src/util/string.c | 6 +++--- src/util/string.h | 1 + 4 files changed, 9 insertions(+), 11 deletions(-) diff --git a/CHANGES b/CHANGES index 273e87dd0..aa574d0a3 100644 --- a/CHANGES +++ b/CHANGES @@ -60,6 +60,7 @@ Misc: - GBA Savedata: Add realistic timing for EEPROM - GBA Video: Optimize mode 0 rendering - Qt: Remove default autofire mappings + - PSP2: Allow UTF-8 filenames 0.4.1: (2016-07-11) Bugfixes: diff --git a/src/platform/psp2/gui-font.c b/src/platform/psp2/gui-font.c index 73c6a0ac7..37c94be7b 100644 --- a/src/platform/psp2/gui-font.c +++ b/src/platform/psp2/gui-font.c @@ -41,10 +41,8 @@ unsigned GUIFontHeight(const struct GUIFont* font) { } unsigned GUIFontGlyphWidth(const struct GUIFont* font, uint32_t glyph) { - if (glyph > 0x7F) { - glyph = '?'; - } - char base[5] = { glyph }; + char base[5] = { 0 }; + toUtf8(glyph, 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) { - if (glyph > 0x7F) { - glyph = '?'; - } - char base[5] = { glyph }; + char base[5] = { 0 }; + toUtf8(glyph, base); vita2d_pgf_draw_text(font->pgf, x, y, color, FONT_SIZE, base); } diff --git a/src/util/string.c b/src/util/string.c index 0157d4403..438a1b683 100644 --- a/src/util/string.c +++ b/src/util/string.c @@ -80,7 +80,7 @@ uint32_t utf8Char(const char** unicode, size_t* length) { return byte; } uint32_t unichar; - static int tops[4] = { 0xC0, 0xE0, 0xF0, 0xF8 }; + static const int tops[4] = { 0xC0, 0xE0, 0xF0, 0xF8 }; size_t numBytes; for (numBytes = 0; numBytes < 3; ++numBytes) { if ((byte & tops[numBytes + 1]) == tops[numBytes]) { @@ -110,7 +110,7 @@ uint32_t utf8Char(const char** unicode, size_t* length) { return unichar; } -static size_t _toUtf8(uint32_t unichar, char* buffer) { +size_t toUtf8(uint32_t unichar, char* buffer) { if (unichar > 0x10FFFF) { unichar = 0xFFFD; } @@ -173,7 +173,7 @@ char* utf16to8(const uint16_t* utf16, size_t length) { break; } uint32_t unichar = utf16Char(&utf16, &length); - size_t bytes = _toUtf8(unichar, buffer); + size_t bytes = toUtf8(unichar, buffer); utf8Length += bytes; if (utf8Length < utf8TotalBytes) { memcpy(offset, buffer, bytes); diff --git a/src/util/string.h b/src/util/string.h index 9716cfbf6..44ee79a35 100644 --- a/src/util/string.h +++ b/src/util/string.h @@ -19,6 +19,7 @@ char* strdup(const char* str); 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); char* utf16to8(const uint16_t* utf16, size_t length); uint32_t utf8Char(const char** unicode, size_t* length);