-
Notifications
You must be signed in to change notification settings - Fork 89
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Application: General i18n workaround for shared font loading #76
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -229,23 +229,126 @@ bool Application::init(std::string title, Style* style, LibraryViewsThemeVariant | |
#ifdef __SWITCH__ | ||
{ | ||
PlFontData font; | ||
int locale = i18n::swGetCurrentLocaleID(); | ||
|
||
// Standard font | ||
Result rc = plGetSharedFontByType(&font, PlSharedFontType_Standard); | ||
if (R_SUCCEEDED(rc)) | ||
{ | ||
Logger::info("Using Switch shared font"); | ||
Application::fontStash.regular = Application::loadFontFromMemory("regular", font.address, font.size, false); | ||
Logger::info("Adding Switch shared standard font"); | ||
Application::fontStash.standard = Application::loadFontFromMemory("regular", font.address, font.size, false); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Wouldn't that be There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. changed |
||
} | ||
|
||
// Korean font | ||
rc = plGetSharedFontByType(&font, PlSharedFontType_KO); | ||
if (R_SUCCEEDED(rc)) | ||
// Load other fonts on demand | ||
bool isFullFallback = false; | ||
AppletType at = appletGetAppletType(); | ||
if (at == AppletType_Application || at == AppletType_SystemApplication) // title takeover | ||
{ | ||
isFullFallback = true; | ||
Logger::warning("Non applet mode, font full fallback is enabled!"); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Is this really a warning? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. changed to |
||
} | ||
|
||
if (locale == 6 || locale == 15 || isFullFallback) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Not a fan of magic values here, could you define them somewhere instead? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. substituted with enforcing |
||
{ | ||
// S.Chinese font | ||
rc = plGetSharedFontByType(&font, PlSharedFontType_ChineseSimplified); | ||
if (R_SUCCEEDED(rc)) | ||
{ | ||
Logger::info("Adding Switch shared S.Chinese font"); | ||
Application::fontStash.schinese = Application::loadFontFromMemory("schinese", font.address, font.size, false); | ||
} | ||
// Ext S.Chinese font | ||
rc = plGetSharedFontByType(&font, PlSharedFontType_ExtChineseSimplified); | ||
if (R_SUCCEEDED(rc)) | ||
{ | ||
Logger::info("Adding Switch shared S.Chinese extended font"); | ||
Application::fontStash.extSchinese = Application::loadFontFromMemory("extSchinese", font.address, font.size, false); | ||
} | ||
} | ||
if (locale == 11 || locale == 16 || isFullFallback) | ||
{ | ||
Logger::info("Adding Switch shared Korean font"); | ||
Application::fontStash.korean = Application::loadFontFromMemory("korean", font.address, font.size, false); | ||
nvgAddFallbackFontId(Application::vg, Application::fontStash.regular, Application::fontStash.korean); | ||
// T.Chinese font | ||
rc = plGetSharedFontByType(&font, PlSharedFontType_ChineseTraditional); | ||
if (R_SUCCEEDED(rc)) | ||
{ | ||
Logger::info("Adding Switch shared T.Chinese font"); | ||
Application::fontStash.tchinese = Application::loadFontFromMemory("tchinese", font.address, font.size, false); | ||
} | ||
} | ||
if (locale == 7 || isFullFallback) | ||
{ | ||
// Korean font | ||
rc = plGetSharedFontByType(&font, PlSharedFontType_KO); | ||
if (R_SUCCEEDED(rc)) | ||
{ | ||
Logger::info("Adding Switch shared Korean font"); | ||
Application::fontStash.korean = Application::loadFontFromMemory("korean", font.address, font.size, false); | ||
} | ||
} | ||
|
||
// Sequentially fallback to other fonts and decide regular font, also on demand | ||
switch (locale) | ||
{ | ||
case 6 : | ||
case 15 : | ||
if (isFullFallback) | ||
{ | ||
nvgAddFallbackFontId(Application::vg, Application::fontStash.schinese, Application::fontStash.korean); | ||
nvgAddFallbackFontId(Application::vg, Application::fontStash.schinese, Application::fontStash.standard); | ||
nvgAddFallbackFontId(Application::vg, Application::fontStash.schinese, Application::fontStash.tchinese); | ||
nvgAddFallbackFontId(Application::vg, Application::fontStash.schinese, Application::fontStash.extSchinese); | ||
} | ||
else | ||
{ | ||
nvgAddFallbackFontId(Application::vg, Application::fontStash.schinese, Application::fontStash.standard); | ||
nvgAddFallbackFontId(Application::vg, Application::fontStash.schinese, Application::fontStash.extSchinese); | ||
} | ||
Logger::info("Using Switch shared S.Chinese font as regular"); | ||
Application::fontStash.regular = Application::fontStash.schinese; | ||
break; | ||
case 11 : | ||
case 16 : | ||
if (isFullFallback) | ||
{ | ||
nvgAddFallbackFontId(Application::vg, Application::fontStash.tchinese, Application::fontStash.korean); | ||
nvgAddFallbackFontId(Application::vg, Application::fontStash.tchinese, Application::fontStash.standard); | ||
nvgAddFallbackFontId(Application::vg, Application::fontStash.tchinese, Application::fontStash.extSchinese); | ||
nvgAddFallbackFontId(Application::vg, Application::fontStash.tchinese, Application::fontStash.schinese); | ||
} | ||
else | ||
{ | ||
nvgAddFallbackFontId(Application::vg, Application::fontStash.tchinese, Application::fontStash.standard); | ||
} | ||
Logger::info("Using Switch shared T.Chinese font as regular"); | ||
Application::fontStash.regular = Application::fontStash.tchinese; | ||
break; | ||
case 7 : | ||
if (isFullFallback) | ||
{ | ||
nvgAddFallbackFontId(Application::vg, Application::fontStash.korean, Application::fontStash.standard); | ||
nvgAddFallbackFontId(Application::vg, Application::fontStash.korean, Application::fontStash.tchinese); | ||
nvgAddFallbackFontId(Application::vg, Application::fontStash.korean, Application::fontStash.extSchinese); | ||
nvgAddFallbackFontId(Application::vg, Application::fontStash.korean, Application::fontStash.schinese); | ||
} | ||
else | ||
{ | ||
nvgAddFallbackFontId(Application::vg, Application::fontStash.korean, Application::fontStash.standard); | ||
} | ||
Logger::info("Using Switch shared Korean font as regular"); | ||
Application::fontStash.regular = Application::fontStash.korean; | ||
break; | ||
default: | ||
if (isFullFallback) | ||
{ | ||
nvgAddFallbackFontId(Application::vg, Application::fontStash.standard, Application::fontStash.korean); | ||
nvgAddFallbackFontId(Application::vg, Application::fontStash.standard, Application::fontStash.tchinese); | ||
nvgAddFallbackFontId(Application::vg, Application::fontStash.standard, Application::fontStash.extSchinese); | ||
nvgAddFallbackFontId(Application::vg, Application::fontStash.standard, Application::fontStash.schinese); | ||
} | ||
Logger::info("Using Switch shared standard font as regular"); | ||
Application::fontStash.regular = Application::fontStash.standard; | ||
break; | ||
} | ||
|
||
// Extented font | ||
rc = plGetSharedFontByType(&font, PlSharedFontType_NintendoExt); | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -108,6 +108,34 @@ std::string getCurrentLocale() | |
return DEFAULT_LOCALE; | ||
} | ||
|
||
#ifdef __SWITCH__ | ||
int swGetCurrentLocaleID() | ||
{ | ||
u64 languageCode = 0; | ||
SetLanguage setlanguage = SetLanguage_ENUS; | ||
|
||
Result res = setGetSystemLanguage(&languageCode); | ||
|
||
if (R_SUCCEEDED(res)) | ||
{ | ||
if (R_SUCCEEDED(res)) | ||
{ | ||
res = setMakeLanguage(languageCode, &setlanguage); | ||
return (int)setlanguage; | ||
} | ||
else | ||
{ | ||
brls::Logger::error("Unable to convert system language ID (error 0x{0:x}), using the default one: {1}", res, DEFAULT_LOCALE); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. You can use There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. done |
||
} | ||
} | ||
else | ||
{ | ||
brls::Logger::error("Unable to get system language (error 0x{0:x}), using the default one: {1}", res, DEFAULT_LOCALE); | ||
} | ||
return 1; // SetLanguage_ENUS | ||
} | ||
#endif | ||
|
||
void loadTranslations() | ||
{ | ||
loadLocale(DEFAULT_LOCALE, &defaultLocale); | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why put it here? Technically it's i18n related but it doesn't belong to the i18n system
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I mean it depends on the Switch implementation, and i18n is supposed to be generic (and eventually will)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this id only make sense for libnx i think
removed
#ifdef