diff --git a/fonts/jp.ttf b/fonts/jp.ttf new file mode 100644 index 0000000..39ff91b Binary files /dev/null and b/fonts/jp.ttf differ diff --git a/fonts/ko.ttf b/fonts/ko.ttf new file mode 100644 index 0000000..bcfadd8 Binary files /dev/null and b/fonts/ko.ttf differ diff --git a/readme.txt b/readme.txt index 157e03b..5920165 100644 --- a/readme.txt +++ b/readme.txt @@ -38,6 +38,12 @@ https://github.com/dborth/vbagx/releases |0Oื๘oท UPDATE HISTORY ทo๘ืO0| `จ•จจจจจ จจจจจจจจจจจจจจจจ จจจจจจจจจจจจจจจ จจจจจจจจจจจจจจจจจจจจ จจจจจจจจจจจจจ' +[2.3.9] + +* Added ability to load external fonts and activated Japanese/Korean + translations. Simply put the ko.ttf or jp.ttf in the app directory +* Added ability to change preview image source with + button (thanks Zalo!) + [2.3.8 - January 4, 2019] * Restored changes lost from 2.3.0 core upgrade (GameCube virtual memory, diff --git a/source/fileop.cpp b/source/fileop.cpp index 2e8610a..2e46ef6 100644 --- a/source/fileop.cpp +++ b/source/fileop.cpp @@ -34,9 +34,14 @@ #include "filebrowser.h" #include "gui/gui.h" +#ifdef HW_RVL + #include "mem2.h" +#endif + #define THREAD_SLEEP 100 unsigned char *savebuffer = NULL; +u8 *ext_font_ttf = NULL; static mutex_t bufferLock = LWP_MUTEX_NULL; FILE * file; // file pointer - the only one we should ever use! bool unmountRequired[7] = { false, false, false, false, false, false, false }; @@ -854,6 +859,43 @@ size_t LoadFile(char * filepath, bool silent) return LoadFile((char *)savebuffer, filepath, 0, SAVEBUFFERSIZE, silent); } +#ifdef HW_RVL +size_t LoadFont(char * filepath) +{ + FILE *file = fopen (filepath, "rb"); + + if(!file) { + ErrorPrompt("Font file not found!"); + return 0; + } + + fseeko(file,0,SEEK_END); + size_t loadSize = ftello(file); + + if(loadSize == 0) { + ErrorPrompt("Error loading font!"); + return 0; + } + + if(ext_font_ttf) { + mem2_free(ext_font_ttf); + } + + ext_font_ttf = (u8 *)mem2_malloc(loadSize); + + if(!ext_font_ttf) { + ErrorPrompt("Font file is too large!"); + fclose(file); + return 0; + } + + fseeko(file,0,SEEK_SET); + fread (ext_font_ttf, 1, loadSize, file); + fclose(file); + return loadSize; +} +#endif + /**************************************************************************** * SaveFile * Write buffer to file diff --git a/source/fileop.h b/source/fileop.h index 0bed018..a103bb3 100644 --- a/source/fileop.h +++ b/source/fileop.h @@ -36,10 +36,12 @@ void FreeSaveBuffer(); size_t LoadFile(char * rbuffer, char *filepath, size_t length, size_t buffersize, bool silent); size_t LoadFile(char * filepath, bool silent); size_t LoadSzFile(char * filepath, unsigned char * rbuffer); +size_t LoadFont(char *filepath); size_t SaveFile(char * buffer, char *filepath, size_t datasize, bool silent); size_t SaveFile(char * filepath, size_t datasize, bool silent); extern unsigned char *savebuffer; +extern u8 *ext_font_ttf; extern FILE * file; extern bool unmountRequired[]; extern bool isMounted[]; diff --git a/source/menu.cpp b/source/menu.cpp index fd4e858..3de0cb4 100644 --- a/source/menu.cpp +++ b/source/menu.cpp @@ -35,6 +35,7 @@ #include "gamesettings.h" #include "gui/gui.h" #include "utils/gettext.h" +#include "utils/FreeTypeGX.h" #define THREAD_SLEEP 100 @@ -111,7 +112,7 @@ HaltGui() usleep(THREAD_SLEEP); } -void ResetText() +static void ResetText() { LoadLanguage(); @@ -119,6 +120,58 @@ void ResetText() mainWindow->ResetText(); } +static int currentLanguage = -1; + +void ChangeLanguage() { + if(currentLanguage == GCSettings.language) { + return; + } + + if(GCSettings.language == LANG_JAPANESE || GCSettings.language == LANG_KOREAN) { +#ifdef HW_RVL + char filepath[MAXPATHLEN]; + + switch(GCSettings.language) { + case LANG_KOREAN: + sprintf(filepath, "%s/ko.ttf", appPath); + break; + case LANG_JAPANESE: + sprintf(filepath, "%s/jp.ttf", appPath); + break; + } + + size_t fontSize = LoadFont(filepath); + + if(fontSize > 0) { + HaltGui(); + DeinitFreeType(); + InitFreeType((u8*)ext_font_ttf, fontSize); + } + else { + GCSettings.language = currentLanguage; + } +#else + GCSettings.language = currentLanguage; + ErrorPrompt("Unsupported language!"); +#endif + } +#ifdef HW_RVL + else { + if(ext_font_ttf != NULL) { + HaltGui(); + DeinitFreeType(); + mem2_free(ext_font_ttf); + ext_font_ttf = NULL; + InitFreeType((u8*)font_ttf, font_ttf_size); + } + } +#endif + HaltGui(); + ResetText(); + currentLanguage = GCSettings.language; + ResumeGui(); +} + /**************************************************************************** * WindowPrompt * @@ -3649,6 +3702,7 @@ static int MenuSettingsMenu() int i = 0; bool firstRun = true; OptionList options; + currentLanguage = GCSettings.language; sprintf(options.name[i++], "Exit Action"); sprintf(options.name[i++], "Wiimote Orientation"); @@ -3736,9 +3790,7 @@ static int MenuSettingsMenu() GCSettings.language = LANG_JAPANESE; if(GCSettings.language == LANG_SIMP_CHINESE) - GCSettings.language = LANG_PORTUGUESE; - else if(GCSettings.language == LANG_JAPANESE) - GCSettings.language = LANG_ENGLISH; + GCSettings.language = LANG_KOREAN; break; case 6: GCSettings.PreviewImage++; @@ -3832,11 +3884,11 @@ static int MenuSettingsMenu() menu = MENU_SETTINGS; } } + ChangeLanguage(); HaltGui(); mainWindow->Remove(&optionBrowser); mainWindow->Remove(&w); mainWindow->Remove(&titleTxt); - ResetText(); return menu; } diff --git a/source/menu.h b/source/menu.h index 3c4dca2..575669f 100644 --- a/source/menu.h +++ b/source/menu.h @@ -25,7 +25,7 @@ int YesNoPrompt(const char *msg, bool yesDefault); void ShowAction (const char *msg); void CancelAction(); void ShowProgress (const char *msg, int done, int total); -void ResetText(); +void ChangeLanguage(); enum { diff --git a/source/preferences.cpp b/source/preferences.cpp index 65646f8..590e687 100644 --- a/source/preferences.cpp +++ b/source/preferences.cpp @@ -848,7 +848,7 @@ bool LoadPrefs() CreateDirectory(dirPath); } - ResetText(); + ChangeLanguage(); return prefFound; }