Browse Source

Merge pull request #5671

73cd4ed qt: avoid hard-coding font names (Cory Fields)
52954e6 qt: fix broken unicode chars on osx 10.10 (Cory Fields)
f5ad78b qt: fonts: allow SubstituteFonts to filter based on user's language (Cory Fields)
0.13
Wladimir J. van der Laan 10 years ago
parent
commit
e1aecae33a
No known key found for this signature in database
GPG Key ID: 74810B012346C9A6
  1. 27
      src/qt/bitcoin.cpp
  2. 25
      src/qt/guiutil.cpp
  3. 2
      src/qt/guiutil.h
  4. 2
      src/qt/splashscreen.cpp

27
src/qt/bitcoin.cpp

@ -89,10 +89,24 @@ static std::string Translate(const char* psz)
return QCoreApplication::translate("bitcoin-core", psz).toStdString(); return QCoreApplication::translate("bitcoin-core", psz).toStdString();
} }
static QString GetLangTerritory()
{
QSettings settings;
// Get desired locale (e.g. "de_DE")
// 1) System default language
QString lang_territory = QLocale::system().name();
// 2) Language from QSettings
QString lang_territory_qsettings = settings.value("language", "").toString();
if(!lang_territory_qsettings.isEmpty())
lang_territory = lang_territory_qsettings;
// 3) -lang command line argument
lang_territory = QString::fromStdString(GetArg("-lang", lang_territory.toStdString()));
return lang_territory;
}
/** Set up translations */ /** Set up translations */
static void initTranslations(QTranslator &qtTranslatorBase, QTranslator &qtTranslator, QTranslator &translatorBase, QTranslator &translator) static void initTranslations(QTranslator &qtTranslatorBase, QTranslator &qtTranslator, QTranslator &translatorBase, QTranslator &translator)
{ {
QSettings settings;
// Remove old translators // Remove old translators
QApplication::removeTranslator(&qtTranslatorBase); QApplication::removeTranslator(&qtTranslatorBase);
@ -102,13 +116,7 @@ static void initTranslations(QTranslator &qtTranslatorBase, QTranslator &qtTrans
// Get desired locale (e.g. "de_DE") // Get desired locale (e.g. "de_DE")
// 1) System default language // 1) System default language
QString lang_territory = QLocale::system().name(); QString lang_territory = GetLangTerritory();
// 2) Language from QSettings
QString lang_territory_qsettings = settings.value("language", "").toString();
if(!lang_territory_qsettings.isEmpty())
lang_territory = lang_territory_qsettings;
// 3) -lang command line argument
lang_territory = QString::fromStdString(GetArg("-lang", lang_territory.toStdString()));
// Convert to "de" only by truncating "_DE" // Convert to "de" only by truncating "_DE"
QString lang = lang_territory; QString lang = lang_territory;
@ -498,8 +506,6 @@ int main(int argc, char *argv[])
Q_INIT_RESOURCE(bitcoin); Q_INIT_RESOURCE(bitcoin);
Q_INIT_RESOURCE(bitcoin_locale); Q_INIT_RESOURCE(bitcoin_locale);
GUIUtil::SubstituteFonts();
BitcoinApplication app(argc, argv); BitcoinApplication app(argc, argv);
#if QT_VERSION > 0x050100 #if QT_VERSION > 0x050100
// Generate high-dpi pixmaps // Generate high-dpi pixmaps
@ -521,6 +527,7 @@ int main(int argc, char *argv[])
QApplication::setOrganizationName(QAPP_ORG_NAME); QApplication::setOrganizationName(QAPP_ORG_NAME);
QApplication::setOrganizationDomain(QAPP_ORG_DOMAIN); QApplication::setOrganizationDomain(QAPP_ORG_DOMAIN);
QApplication::setApplicationName(QAPP_APP_NAME_DEFAULT); QApplication::setApplicationName(QAPP_APP_NAME_DEFAULT);
GUIUtil::SubstituteFonts(GetLangTerritory());
/// 4. Initialization of translations, so that intro dialog is in user's language /// 4. Initialization of translations, so that intro dialog is in user's language
// Now that QSettings are accessible, initialize translations // Now that QSettings are accessible, initialize translations

25
src/qt/guiutil.cpp

@ -67,6 +67,9 @@ static boost::filesystem::detail::utf8_codecvt_facet utf8;
#if defined(Q_OS_MAC) #if defined(Q_OS_MAC)
extern double NSAppKitVersionNumber; extern double NSAppKitVersionNumber;
#if !defined(NSAppKitVersionNumber10_8)
#define NSAppKitVersionNumber10_8 1187
#endif
#if !defined(NSAppKitVersionNumber10_9) #if !defined(NSAppKitVersionNumber10_9)
#define NSAppKitVersionNumber10_9 1265 #define NSAppKitVersionNumber10_9 1265
#endif #endif
@ -383,7 +386,7 @@ void openDebugLogfile()
QDesktopServices::openUrl(QUrl::fromLocalFile(boostPathToQString(pathDebug))); QDesktopServices::openUrl(QUrl::fromLocalFile(boostPathToQString(pathDebug)));
} }
void SubstituteFonts() void SubstituteFonts(const QString& language)
{ {
#if defined(Q_OS_MAC) #if defined(Q_OS_MAC)
// Background: // Background:
@ -393,12 +396,28 @@ void SubstituteFonts()
// If this fallback is not properly loaded, some characters may fail to // If this fallback is not properly loaded, some characters may fail to
// render correctly. // render correctly.
// //
// The same thing happened with 10.10. .Helvetica Neue DeskInterface is now default.
//
// Solution: If building with the 10.7 SDK or lower and the user's platform // Solution: If building with the 10.7 SDK or lower and the user's platform
// is 10.9 or higher at runtime, substitute the correct font. This needs to // is 10.9 or higher at runtime, substitute the correct font. This needs to
// happen before the QApplication is created. // happen before the QApplication is created.
#if defined(MAC_OS_X_VERSION_MAX_ALLOWED) && MAC_OS_X_VERSION_MAX_ALLOWED < MAC_OS_X_VERSION_10_8 #if defined(MAC_OS_X_VERSION_MAX_ALLOWED) && MAC_OS_X_VERSION_MAX_ALLOWED < MAC_OS_X_VERSION_10_8
if (floor(NSAppKitVersionNumber) >= NSAppKitVersionNumber10_9) if (floor(NSAppKitVersionNumber) > NSAppKitVersionNumber10_8)
QFont::insertSubstitution(".Lucida Grande UI", "Lucida Grande"); {
if (floor(NSAppKitVersionNumber) <= NSAppKitVersionNumber10_9)
/* On a 10.9 - 10.9.x system */
QFont::insertSubstitution(".Lucida Grande UI", "Lucida Grande");
else
{
/* 10.10 or later system */
if (language == "zh_CN" || language == "zh_TW" || language == "zh_HK") // traditional or simplified Chinese
QFont::insertSubstitution(".Helvetica Neue DeskInterface", "Heiti SC");
else if (language == "ja") // Japanesee
QFont::insertSubstitution(".Helvetica Neue DeskInterface", "Songti SC");
else
QFont::insertSubstitution(".Helvetica Neue DeskInterface", "Lucida Grande");
}
}
#endif #endif
#endif #endif
} }

2
src/qt/guiutil.h

@ -107,7 +107,7 @@ namespace GUIUtil
void openDebugLogfile(); void openDebugLogfile();
// Replace invalid default fonts with known good ones // Replace invalid default fonts with known good ones
void SubstituteFonts(); void SubstituteFonts(const QString& language);
/** Qt event filter that intercepts ToolTipChange events, and replaces the tooltip with a rich text /** Qt event filter that intercepts ToolTipChange events, and replaces the tooltip with a rich text
representation if needed. This assures that Qt can word-wrap long tooltip messages. representation if needed. This assures that Qt can word-wrap long tooltip messages.

2
src/qt/splashscreen.cpp

@ -42,7 +42,7 @@ SplashScreen::SplashScreen(Qt::WindowFlags f, const NetworkStyle *networkStyle)
QString copyrightText = QChar(0xA9)+QString(" 2009-%1 ").arg(COPYRIGHT_YEAR) + QString(tr("The Bitcoin Core developers")); QString copyrightText = QChar(0xA9)+QString(" 2009-%1 ").arg(COPYRIGHT_YEAR) + QString(tr("The Bitcoin Core developers"));
QString titleAddText = networkStyle->getTitleAddText(); QString titleAddText = networkStyle->getTitleAddText();
QString font = "Arial"; QString font = QApplication::font().toString();
// create a bitmap according to device pixelratio // create a bitmap according to device pixelratio
QSize splashSize(480*devicePixelRatio,320*devicePixelRatio); QSize splashSize(480*devicePixelRatio,320*devicePixelRatio);

Loading…
Cancel
Save