add ability to externally load fonts and activate japanese/korean

translations.
This commit is contained in:
Daryl Borth 2019-01-05 17:07:33 -07:00
parent 23ae2a2349
commit e0b0f005b2
8 changed files with 109 additions and 7 deletions

BIN
fonts/jp.ttf Normal file

Binary file not shown.

BIN
fonts/ko.ttf Normal file

Binary file not shown.

View File

@ -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,

View File

@ -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

View File

@ -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[];

View File

@ -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;
}

View File

@ -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
{

View File

@ -848,7 +848,7 @@ bool LoadPrefs()
CreateDirectory(dirPath);
}
ResetText();
ChangeLanguage();
return prefFound;
}