From cc1fa20afb03b70f654b7d30c925a798a28820a6 Mon Sep 17 00:00:00 2001 From: "Unknown W. Brackets" Date: Sat, 9 Jun 2018 11:34:12 -0700 Subject: [PATCH] Qt: Use Roboto Condensed like on other platforms. May improve font fallback issues in #7581. --- Core/Config.h | 4 +++- UI/NativeApp.cpp | 25 ++++++++++++++++++++++--- ext/native/gfx_es2/draw_text_qt.cpp | 5 ++--- 3 files changed, 27 insertions(+), 7 deletions(-) diff --git a/Core/Config.h b/Core/Config.h index 05a4824203..6778413cf2 100644 --- a/Core/Config.h +++ b/Core/Config.h @@ -106,10 +106,12 @@ public: #if defined(USING_WIN_UI) bool bPauseOnLostFocus; bool bTopMost; - std::string sFont; bool bIgnoreWindowsKey; bool bRestartRequired; #endif +#if defined(USING_WIN_UI) || defined(USING_QT_UI) + std::string sFont; +#endif bool bPauseWhenMinimized; diff --git a/UI/NativeApp.cpp b/UI/NativeApp.cpp index 73781e2b61..a45c6c7597 100644 --- a/UI/NativeApp.cpp +++ b/UI/NativeApp.cpp @@ -105,6 +105,9 @@ #if !defined(MOBILE_DEVICE) && defined(USING_QT_UI) #include "Qt/QtHost.h" #endif +#if defined(USING_QT_UI) +#include +#endif // The new UI framework, for initialization @@ -276,7 +279,7 @@ void NativeGetAppInfo(std::string *app_dir_name, std::string *app_nice_name, boo #endif } -#if defined(_WIN32) && !PPSSPP_PLATFORM(UWP) +#if defined(USING_WIN_UI) && !PPSSPP_PLATFORM(UWP) static bool CheckFontIsUsable(const wchar_t *fontFace) { wchar_t actualFontFace[1024] = { 0 }; @@ -558,7 +561,7 @@ void NativeInit(int argc, const char *argv[], const char *savegame_dir, const ch // Note to translators: do not translate this/add this to PPSSPP-lang's files. // It's intended to be custom for every user. // Only add it to your own personal copies of PPSSPP. -#if defined(_WIN32) && !PPSSPP_PLATFORM(UWP) +#if defined(USING_WIN_UI) && !PPSSPP_PLATFORM(UWP) // TODO: Could allow a setting to specify a font file to load? // TODO: Make this a constant if we can sanely load the font on other systems? AddFontResourceEx(L"assets/Roboto-Condensed.ttf", FR_PRIVATE, NULL); @@ -568,6 +571,22 @@ void NativeInit(int argc, const char *argv[], const char *savegame_dir, const ch } else { g_Config.sFont = des->T("Font", "Roboto"); } +#elif defined(USING_QT_UI) + size_t fontSize = 0; + uint8_t *fontData = VFSReadFile("Roboto-Condensed.ttf", &fontSize); + if (fontData) { + int fontID = QFontDatabase::addApplicationFontFromData(QByteArray((const char *)fontData, fontSize)); + delete [] fontData; + + QStringList fontsFound = QFontDatabase::applicationFontFamilies(fontID); + if (fontsFound.size() >= 1) { + // Might be "Roboto" or "Roboto Condensed". + g_Config.sFont = des->T("Font", fontsFound.at(0).toUtf8().constData()); + } + } else { + // Let's try for it being a system font. + g_Config.sFont = des->T("Font", "Roboto Condensed"); + } #endif if (!boot_filename.empty() && stateToLoad != NULL) { @@ -618,7 +637,7 @@ static UI::Style MakeStyle(uint32_t fg, uint32_t bg) { } static void UIThemeInit() { -#if defined(_WIN32) && !PPSSPP_PLATFORM(UWP) +#if (defined(USING_WIN_UI) && !PPSSPP_PLATFORM(UWP)) || defined(USING_QT_UI) ui_theme.uiFont = UI::FontStyle(UBUNTU24, g_Config.sFont.c_str(), 22); ui_theme.uiFontSmall = UI::FontStyle(UBUNTU24, g_Config.sFont.c_str(), 15); ui_theme.uiFontSmaller = UI::FontStyle(UBUNTU24, g_Config.sFont.c_str(), 12); diff --git a/ext/native/gfx_es2/draw_text_qt.cpp b/ext/native/gfx_es2/draw_text_qt.cpp index 973e8d27ad..a2fae32f39 100644 --- a/ext/native/gfx_es2/draw_text_qt.cpp +++ b/ext/native/gfx_es2/draw_text_qt.cpp @@ -23,8 +23,7 @@ TextDrawerQt::~TextDrawerQt() { } uint32_t TextDrawerQt::SetFont(const char *fontName, int size, int flags) { - // We will only use the default font - uint32_t fontHash = 0; //hash::Adler32((const uint8_t *)fontName, strlen(fontName)); + uint32_t fontHash = fontName && strlen(fontName) ? hash::Adler32((const uint8_t *)fontName, strlen(fontName)) : 0; fontHash ^= size; fontHash ^= flags << 10; @@ -34,7 +33,7 @@ uint32_t TextDrawerQt::SetFont(const char *fontName, int size, int flags) { return fontHash; } - QFont* font = new QFont(); + QFont* font = fontName ? new QFont(fontName) : new QFont(); font->setPixelSize(size + 6); fontMap_[fontHash] = font; fontHash_ = fontHash;