Use system fonts for Chinese

This commit is contained in:
Pk11 2021-03-20 17:49:39 -05:00
commit 46b17521a7
7 changed files with 64 additions and 48 deletions

@ -1 +1 @@
Subproject commit 12759353de264a22f40beedd9dfbea718bbe30c8
Subproject commit bb168fdab1cb6a8aee1bd7fbd6e2c29ed3f87a1b

View file

@ -86,10 +86,6 @@ public:
bool customfont() const { return this->v_customFont; };
void customfont(bool v) { this->v_customFont = v; if (!this->changesMade) this->changesMade = true; };
/* The most recently downloaded language font */
std::string downloadedFont() const { return this->v_downloadedFont; };
void downloadedFont(const std::string &v) { this->v_downloadedFont = v; if (!this->changesMade) this->changesMade = true; };
/* The shortcut path. */
std::string shortcut() const { return this->v_shortcutPath; };
void shortcut(const std::string &v) { this->v_shortcutPath = v; if (!this->changesMade) this->changesMade = true; };
@ -119,7 +115,7 @@ private:
int v_theme = 0;
std::string v_language = "en", v_lastStore = "universal-db.unistore", v_downloadedFont = "",
std::string v_language = "en", v_lastStore = "universal-db.unistore",
v_3dsxPath = "sdmc:/3ds", v_ndsPath = "sdmc:", v_archivePath = "sdmc:",
v_shortcutPath = "sdmc:/3ds/Universal-Updater/shortcuts", v_firmPath = "sdmc:/luma/payloads";

View file

@ -118,21 +118,12 @@ void Init::UnloadFont() {
Result Init::Initialize() {
gfxInitDefault();
romfsInit();
u8 region;
CFGU_SecureInfoGetRegion(&region);
Gui::init((CFG_Region)region);
cfguInit();
ptmuInit();
amInit();
acInit();
APT_GetAppCpuTimeLimit(&old_time_limit);
APT_SetAppCpuTimeLimit(30); // Needed for QR Scanner to work.
getCurrentUsage();
aptSetSleepAllowed(false);
hidSetRepeatParameters(20, 8);
/* Create Directories, if missing. */
mkdir("sdmc:/3ds", 0777);
mkdir("sdmc:/3ds/Universal-Updater", 0777);
@ -140,6 +131,23 @@ Result Init::Initialize() {
mkdir("sdmc:/3ds/Universal-Updater/shortcuts", 0777);
config = std::make_unique<Config>();
CFG_Region region = CFG_REGION_USA;
if(config->language() == "zh-CN") {
region = CFG_REGION_CHN;
} else if(config->language() == "zh-TW") {
region = CFG_REGION_TWN;
} else if(config->language() == "ko") {
region = CFG_REGION_KOR;
}
Gui::init(region);
APT_GetAppCpuTimeLimit(&old_time_limit);
APT_SetAppCpuTimeLimit(30); // Needed for QR Scanner to work.
getCurrentUsage();
aptSetSleepAllowed(false);
hidSetRepeatParameters(20, 8);
GFX::SelectedTheme = config->theme();
if (GFX::SelectedTheme > (_THEME_AMOUNT - 1)) GFX::SelectedTheme = 0; // In case it is above the max themes.
Lang::load(config->language());

View file

@ -37,10 +37,8 @@ std::string _3dsxPath = "";
static void InitForARG() {
gfxInitDefault();
romfsInit();
cfguInit();
u8 region;
CFGU_SecureInfoGetRegion(&region);
Gui::init((CFG_Region)region);
amInit();
acInit();
@ -50,6 +48,18 @@ static void InitForARG() {
mkdir("sdmc:/3ds/Universal-Updater/stores", 0777);
mkdir("sdmc:/3ds/Universal-Updater/shortcuts", 0777);
config = std::make_unique<Config>();
CFG_Region region = CFG_REGION_USA;
if(config->language() == "zh-CN") {
region = CFG_REGION_CHN;
} else if(config->language() == "zh-TW") {
region = CFG_REGION_TWN;
} else if(config->language() == "ko") {
region = CFG_REGION_KOR;
}
Gui::init(region);
config = std::make_unique<Config>();
GFX::SelectedTheme = config->theme();
if (GFX::SelectedTheme > (_THEME_AMOUNT - 1)) GFX::SelectedTheme = 0; // In case it is above the max themes.

View file

@ -577,17 +577,24 @@ static void LanguageLogic(int &page, int &selection, int &sPos) {
const std::string l = langsTemp[selection];
/* Check if language needs a custom font. */
u8 region;
CFGU_SecureInfoGetRegion(&region);
if (l == "uk" || (l == "zh-CN" && region != CFG_REGION_CHN) || (l == "zh-TW" && region != CFG_REGION_TWN)) {
if (access("sdmc:/3ds/Universal-Updater/font.bcfnt", F_OK) != 0 || config->downloadedFont() != l) {
ScriptUtils::downloadFile("https://github.com/Universal-Team/extras/raw/master/files/" + l + ".bcfnt", "sdmc:/3ds/Universal-Updater/font.bcfnt", Lang::get("DOWNLOADING_COMPATIBLE_FONT"), true);
config->downloadedFont(l);
if (l == "uk") {
if (access("sdmc:/3ds/Universal-Updater/font.bcfnt", F_OK) != 0) {
ScriptUtils::downloadFile("https://github.com/Universal-Team/extras/raw/master/files/universal-updater.bcfnt", "sdmc:/3ds/Universal-Updater/font.bcfnt", Lang::get("DOWNLOADING_COMPATIBLE_FONT"), true);
Init::UnloadFont();
}
config->customfont(true);
Init::LoadFont();
} else if(!config->customfont()) {
CFG_Region region = CFG_REGION_USA;
if(l == "zh-CN") {
region = CFG_REGION_CHN;
} else if(l == "zh-TW") {
region = CFG_REGION_TWN;
} else if(l == "ko") {
region = CFG_REGION_KOR;
}
Gui::loadSystemFont(region);
}
config->language(l);
@ -604,17 +611,24 @@ static void LanguageLogic(int &page, int &selection, int &sPos) {
const std::string l = langsTemp[i + sPos];
/* Check if language needs a custom font. */
u8 region;
CFGU_SecureInfoGetRegion(&region);
if (l == "uk" || (l == "zh-CN" && region != CFG_REGION_CHN) || (l == "zh-TW" && region != CFG_REGION_TWN)) {
if (access("sdmc:/3ds/Universal-Updater/font.bcfnt", F_OK) != 0 || config->downloadedFont() != l) {
ScriptUtils::downloadFile("https://github.com/Universal-Team/extras/raw/master/files/" + l + ".bcfnt", "sdmc:/3ds/Universal-Updater/font.bcfnt", Lang::get("DOWNLOADING_COMPATIBLE_FONT"), true);
config->downloadedFont(l);
if (l == "uk") {
if (access("sdmc:/3ds/Universal-Updater/font.bcfnt", F_OK) != 0) {
ScriptUtils::downloadFile("https://github.com/Universal-Team/extras/raw/master/files/universal-updater.bcfnt", "sdmc:/3ds/Universal-Updater/font.bcfnt", Lang::get("DOWNLOADING_COMPATIBLE_FONT"), true);
Init::UnloadFont();
}
config->customfont(true);
Init::LoadFont();
} else if(!config->customfont()) {
CFG_Region region = CFG_REGION_USA;
if(l == "zh-CN") {
region = CFG_REGION_CHN;
} else if(l == "zh-TW") {
region = CFG_REGION_TWN;
} else if(l == "ko") {
region = CFG_REGION_KOR;
}
Gui::loadSystemFont(region);
}
config->language(l);
@ -631,10 +645,7 @@ static void LanguageLogic(int &page, int &selection, int &sPos) {
if (touching(touch, langButtons[6])) {
/* Download Font. */
std::string l = config->language();
if(l != "uk" && l != "zh-CN" && l != "zh-TW")
l = "uk";
ScriptUtils::downloadFile("https://github.com/Universal-Team/extras/raw/master/files/" + l + ".bcfnt", "sdmc:/3ds/Universal-Updater/font.bcfnt", Lang::get("DOWNLOADING_COMPATIBLE_FONT"), true);
config->downloadedFont(l);
ScriptUtils::downloadFile("https://github.com/Universal-Team/extras/raw/master/files/universal-updater.bcfnt", "sdmc:/3ds/Universal-Updater/font.bcfnt", Lang::get("DOWNLOADING_COMPATIBLE_FONT"), true);
config->customfont(true);
Init::UnloadFont();
Init::LoadFont();

View file

@ -27,7 +27,6 @@
#include "common.hpp"
#include "config.hpp"
#include "json.hpp"
#include "scriptUtils.hpp"
#include <string>
#include <unistd.h>
@ -118,6 +117,9 @@ Config::Config() {
/* Let us create a new one. */
if (!this->json.contains("Version")) this->initialize();
if (!this->json.contains("Language")) this->sysLang();
else this->language(this->getString("Language"));
if (this->json.contains("LastStore")) this->lastStore(this->getString("LastStore"));
if (this->json.contains("List")) this->list(this->getBool("List"));
if (this->json.contains("AutoUpdate")) this->autoupdate(this->getBool("AutoUpdate"));
@ -130,21 +132,11 @@ Config::Config() {
if (this->json.contains("UpdateCheck")) this->updatecheck(this->getBool("UpdateCheck"));
if (this->json.contains("UseBG")) this->usebg(this->getBool("UseBG"));
if (this->json.contains("CustomFont")) this->customfont(this->getBool("CustomFont"));
if (this->json.contains("DownloadedFont")) this->downloadedFont(this->getString("DownloadedFont"));
if (this->json.contains("Shortcut_Path")) this->shortcut(this->getString("Shortcut_Path"));
if (this->json.contains("Display_Changelog")) this->changelog(this->getBool("Display_Changelog"));
if (this->json.contains("Active_Theme")) this->theme(this->getInt("Active_Theme"));
if (this->json.contains("Prompt")) this->prompt(this->getBool("Prompt"));
if (!this->json.contains("Language")) {
this->sysLang();
if((this->language() == "zh-CN" || this->language() == "zh-TW") && (access("sdmc:/3ds/Universal-Updater/font.bcfnt", F_OK) != 0 || this->downloadedFont() != this->language())) {
ScriptUtils::downloadFile("https://github.com/Universal-Team/extras/raw/master/files/" + this->language() + ".bcfnt", "sdmc:/3ds/Universal-Updater/font.bcfnt", "Downloading compatible font...", true);
this->downloadedFont(this->language());
this->customfont(true);
}
} else this->language(this->getString("Language"));
this->changesMade = false; // No changes made yet.
}
@ -168,7 +160,6 @@ void Config::save() {
this->setBool("UpdateCheck", this->updatecheck());
this->setBool("UseBG", this->usebg());
this->setBool("CustomFont", this->customfont());
this->setString("DownloadedFont", this->downloadedFont());
this->setString("Shortcut_Path", this->shortcut());
this->setBool("Display_Changelog", this->changelog());
this->setInt("Active_Theme", this->theme());

View file

@ -41,13 +41,13 @@ void Lang::load(const std::string &lang) {
/* Check if exist. */
if (access(("romfs:/lang/" + lang + "/app.json").c_str(), F_OK) == 0) {
values = fopen(std::string(("romfs:/lang/" + lang + "/app.json")).c_str(), "rt");
values = fopen(("romfs:/lang/" + lang + "/app.json").c_str(), "rt");
appJson = nlohmann::json::parse(values, nullptr, false);
fclose(values);
return;
} else {
values = fopen(("romfs:/lang/en/app.json"), "rt");
values = fopen("romfs:/lang/en/app.json", "rt");
appJson = nlohmann::json::parse(values, nullptr, false);
fclose(values);
return;