Skip to content

Commit 51de40c

Browse files
committed
Improve CJK fonts rendering under Windows.
1 parent 4cea1e1 commit 51de40c

File tree

1 file changed

+51
-0
lines changed

1 file changed

+51
-0
lines changed

src/main.cpp

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,10 @@
3333
typedef QApplication UchmviewerApp;
3434
#endif
3535

36+
#ifdef _WIN32
37+
#include <windows.h>
38+
#endif
39+
3640
#if defined USE_DBUS
3741
#include <QDBusConnection>
3842
#include "dbus_interface.h"
@@ -45,6 +49,51 @@
4549
MainWindow* mainWindow;
4650

4751

52+
void fallbackFonts()
53+
{
54+
#ifdef _WIN32
55+
// Obtain default GUI font (typically "Segoe UI, 9pt", see QTBUG-58610)
56+
QFont systemFont = QApplication::font("QMessageBox");
57+
LANGID lid = GetUserDefaultLangID();
58+
QStringList result;
59+
switch ( lid & 0xff )
60+
{
61+
case LANG_CHINESE:
62+
if ( lid == 0x0804 || lid == 0x1004 ) // China mainland and Singapore
63+
result << "Microsoft YaHei UI" << "Microsoft YaHei" << "Arial"
64+
<< "Microsoft JhengHei UI" << "Microsoft JhengHei" << "Malgun Gothic" << "Yu Gothic UI" << "Meiryo UI"
65+
<< "Yu Gothic" << "Meiryo";
66+
else
67+
result << "Microsoft JhengHei UI" << "Microsoft JhengHei" << "Arial"
68+
<< "Microsoft YaHei UI" << "Microsoft YaHei" << "Malgun Gothic" << "Yu Gothic UI" << "Meiryo UI"
69+
<< "Yu Gothic" << "Meiryo";
70+
break;
71+
case LANG_JAPANESE:
72+
result << "Yu Gothic UI" << "Meiryo UI" << "Yu Gothic" << "Meiryo" << "Arial"
73+
<< "Malgun Gothic" << "Microsoft YaHei UI" << "Microsoft YaHei" << "Microsoft JhengHei UI" << "Microsoft JhengHei";
74+
break;
75+
case LANG_KOREAN:
76+
result << "Malgun Gothic" << "Arial"
77+
<< "Microsoft JhengHei UI" << "Microsoft JhengHei" << "Microsoft YaHei UI" << "Microsoft YaHei"
78+
<< "Yu Gothic UI" << "Meiryo UI" << "Yu Gothic" << "Meiryo";
79+
break;
80+
default:
81+
result << "Arial" << "Yu Gothic UI" << "Meiryo UI" << "Yu Gothic" << "Meiryo" << "Malgun Gothic"
82+
<< "Microsoft JhengHei UI" << "Microsoft JhengHei" << "Microsoft YaHei UI" << "Microsoft YaHei";
83+
break;
84+
}
85+
result << "Nirmala UI"
86+
<< "Iskoola Pota"
87+
<< "Ebrima"
88+
<< "Arial Unicode MS"
89+
<< "Segoe UI Emoji"
90+
<< "Segoe UI Symbol";
91+
systemFont.insertSubstitutions(systemFont.family(), result);
92+
systemFont.setHintingPreference(QFont::PreferNoHinting);
93+
QApplication::setFont(systemFont);
94+
#endif
95+
}
96+
4897
int main( int argc, char** argv )
4998
{
5099
#if QT_VERSION >= 0x050600
@@ -72,6 +121,8 @@ int main( int argc, char** argv )
72121
app.addLibraryPath( "qt-plugins" );
73122
#endif
74123

124+
fallbackFonts();
125+
75126
app_i18n::init();
76127

77128
// Set data for QSettings

0 commit comments

Comments
 (0)