Skip to content

Commit 2f3ef6a

Browse files
authored
add font fallback (Fluorohydride#2330)
1 parent 3ef790b commit 2f3ef6a

File tree

1 file changed

+63
-8
lines changed

1 file changed

+63
-8
lines changed

gframe/game.cpp

Lines changed: 63 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -71,14 +71,70 @@ bool Game::Initialize() {
7171
dataManager.LoadStrings("./expansions/strings.conf");
7272
env = device->getGUIEnvironment();
7373
numFont = irr::gui::CGUITTFont::createTTFont(env, gameConf.numfont, 16);
74-
adFont = irr::gui::CGUITTFont::createTTFont(env, gameConf.numfont, 12);
75-
lpcFont = irr::gui::CGUITTFont::createTTFont(env, gameConf.numfont, 48);
76-
guiFont = irr::gui::CGUITTFont::createTTFont(env, gameConf.textfont, gameConf.textfontsize);
74+
if(!numFont) {
75+
const wchar_t* numFontPaths[] = {
76+
L"C:/Windows/Fonts/arialbd.ttf",
77+
L"/usr/share/fonts/truetype/DroidSansFallbackFull.ttf",
78+
L"/usr/share/fonts/opentype/noto/NotoSansCJK-Bold.ttc",
79+
L"/usr/share/fonts/google-noto-cjk/NotoSansCJK-Bold.ttc",
80+
L"/System/Library/Fonts/SFNSTextCondensed-Bold.otf",
81+
L"/System/Library/Fonts/SFNS.ttf",
82+
L"./fonts/numFont.ttf",
83+
L"./fonts/numFont.ttc",
84+
L"./fonts/numFont.otf"
85+
};
86+
for(const wchar_t* path : numFontPaths) {
87+
myswprintf(gameConf.numfont, path);
88+
numFont = irr::gui::CGUITTFont::createTTFont(env, gameConf.numfont, 16);
89+
if(numFont)
90+
break;
91+
}
92+
}
7793
textFont = irr::gui::CGUITTFont::createTTFont(env, gameConf.textfont, gameConf.textfontsize);
94+
if(!textFont) {
95+
const wchar_t* textFontPaths[] = {
96+
L"C:/Windows/Fonts/msyh.ttc",
97+
L"C:/Windows/Fonts/msyh.ttf",
98+
L"C:/Windows/Fonts/simsun.ttc",
99+
L"/usr/share/fonts/truetype/DroidSansFallbackFull.ttf",
100+
L"/usr/share/fonts/opentype/noto/NotoSansCJK-Regular.ttc",
101+
L"/usr/share/fonts/google-noto-cjk/NotoSansCJK-Regular.ttc",
102+
L"/System/Library/Fonts/PingFang.ttc",
103+
L"./fonts/textFont.ttf",
104+
L"./fonts/textFont.ttc",
105+
L"./fonts/textFont.otf"
106+
};
107+
for(const wchar_t* path : textFontPaths) {
108+
myswprintf(gameConf.textfont, path);
109+
textFont = irr::gui::CGUITTFont::createTTFont(env, gameConf.textfont, gameConf.textfontsize);
110+
if(textFont)
111+
break;
112+
}
113+
}
78114
if(!numFont || !textFont) {
79-
ErrorLog("Failed to load font(s)!");
80-
return false;
115+
wchar_t fpath[1024];
116+
fpath[0] = 0;
117+
FileSystem::TraversalDir(L"./fonts", [&fpath](const wchar_t* name, bool isdir) {
118+
if(!isdir && wcsrchr(name, '.') && (!mywcsncasecmp(wcsrchr(name, '.'), L".ttf", 4) || !mywcsncasecmp(wcsrchr(name, '.'), L".ttc", 4) || !mywcsncasecmp(wcsrchr(name, '.'), L".otf", 4))) {
119+
myswprintf(fpath, L"./fonts/%ls", name);
120+
}
121+
});
122+
if(fpath[0] == 0) {
123+
ErrorLog("Failed to load font(s)!");
124+
return false;
125+
}
126+
if(!numFont) {
127+
myswprintf(gameConf.numfont, fpath);
128+
numFont = irr::gui::CGUITTFont::createTTFont(env, gameConf.numfont, 16);
129+
}
130+
if(!textFont) {
131+
myswprintf(gameConf.textfont, fpath);
132+
textFont = irr::gui::CGUITTFont::createTTFont(env, gameConf.textfont, gameConf.textfontsize);
133+
}
81134
}
135+
adFont = irr::gui::CGUITTFont::createTTFont(env, gameConf.numfont, 12);
136+
lpcFont = irr::gui::CGUITTFont::createTTFont(env, gameConf.numfont, 48);
137+
guiFont = irr::gui::CGUITTFont::createTTFont(env, gameConf.textfont, gameConf.textfontsize);
82138
smgr = device->getSceneManager();
83139
device->setWindowCaption(L"YGOPro");
84140
device->setResizable(true);
@@ -762,7 +818,6 @@ bool Game::Initialize() {
762818
stCardListTip->setTextAlignment(irr::gui::EGUIA_CENTER, irr::gui::EGUIA_CENTER);
763819
stCardListTip->setVisible(false);
764820
device->setEventReceiver(&menuHandler);
765-
LoadConfig();
766821
if(!soundManager.Init()) {
767822
chkEnableSound->setChecked(false);
768823
chkEnableSound->setEnabled(false);
@@ -1080,7 +1135,7 @@ void Game::LoadConfig() {
10801135
gameConf.use_image_scale = 1;
10811136
gameConf.antialias = 0;
10821137
gameConf.serverport = 7911;
1083-
gameConf.textfontsize = 12;
1138+
gameConf.textfontsize = 14;
10841139
gameConf.nickname[0] = 0;
10851140
gameConf.gamename[0] = 0;
10861141
gameConf.lastdeck[0] = 0;
@@ -1133,7 +1188,7 @@ void Game::LoadConfig() {
11331188
enable_log = atoi(valbuf);
11341189
} else if(!strcmp(strbuf, "textfont")) {
11351190
BufferIO::DecodeUTF8(valbuf, wstr);
1136-
int textfontsize;
1191+
int textfontsize = gameConf.textfontsize;
11371192
sscanf(linebuf, "%s = %s %d", strbuf, valbuf, &textfontsize);
11381193
gameConf.textfontsize = textfontsize;
11391194
BufferIO::CopyWStr(wstr, gameConf.textfont, 256);

0 commit comments

Comments
 (0)