-
Notifications
You must be signed in to change notification settings - Fork 81
/
switch_font.cpp
103 lines (87 loc) · 3.8 KB
/
switch_font.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
/*
Copyright 2019 p-sam
Copyright 2021 natinusala
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
#include <switch.h>
#include <borealis/core/application.hpp>
#include <borealis/core/logger.hpp>
#include <borealis/core/i18n.hpp>
#include <borealis/platforms/switch/switch_font.hpp>
namespace brls
{
void SwitchFontLoader::loadFonts()
{
PlFontData font;
Result rc;
// Standard
rc = plGetSharedFontByType(&font, PlSharedFontType_Standard);
if (R_SUCCEEDED(rc))
Application::loadFontFromMemory(FONT_STANDARD_REGULAR, font.address, font.size, false);
else
Logger::error("switch: could not load Standard shared font: {:#x}", rc);
{
// Detect if non applet
bool isFullFallback = false;
AppletType at = appletGetAppletType();
if (at == AppletType_Application || at == AppletType_SystemApplication) // title takeover
{
isFullFallback = true;
Logger::info("switch: non applet mode, all shared font will be loaded!");
} else {
Logger::info("switch: applet mode, only shared font for current locale will be loaded!");
}
std::string locale = Application::getLocale();
if (locale == LOCALE_ZH_CN || locale == LOCALE_ZH_HANS || isFullFallback)
{
// S.Chinese
rc = plGetSharedFontByType(&font, PlSharedFontType_ChineseSimplified);
if (R_SUCCEEDED(rc))
Application::loadFontFromMemory(FONT_SCHINESE_REGULAR, font.address, font.size, false);
else
Logger::error("switch: could not load S.Chinese shared font: {:#x}", rc);
// Ext S.Chinese
rc = plGetSharedFontByType(&font, PlSharedFontType_ExtChineseSimplified);
if (R_SUCCEEDED(rc))
Application::loadFontFromMemory(FONT_SCHINESE_EXTEND, font.address, font.size, false);
else
Logger::error("switch: could not load Ext. S.Chinese shared font: {:#x}", rc);
}
if (locale == LOCALE_ZH_TW || locale == LOCALE_ZH_HANT || isFullFallback)
{
// T.Chinese
rc = plGetSharedFontByType(&font, PlSharedFontType_ChineseTraditional);
if (R_SUCCEEDED(rc))
Application::loadFontFromMemory(FONT_TCHINESE_REGULAR, font.address, font.size, false);
else
Logger::error("switch: could not load T.Chinese shared font: {:#x}", rc);
}
if (locale == LOCALE_KO || isFullFallback)
{
// Korean
rc = plGetSharedFontByType(&font, PlSharedFontType_KO);
if (R_SUCCEEDED(rc))
Application::loadFontFromMemory(FONT_KOREAN_REGULAR, font.address, font.size, false);
else
Logger::error("switch: could not load Korean shared font: {:#x}", rc);
}
}
// Extented (symbols)
rc = plGetSharedFontByType(&font, PlSharedFontType_NintendoExt);
if (R_SUCCEEDED(rc))
Application::loadFontFromMemory(FONT_SWITCH_ICONS, font.address, font.size, false);
else
Logger::error("switch: could not load Extented shared font: {:#x}", rc);
// Material icons
if (!this->loadMaterialFromResources())
Logger::error("switch: could not load Material icons font from resources", rc);
}
} // namespace brls