From d41947fdcac62551e374db293e78fda51d6e4570 Mon Sep 17 00:00:00 2001 From: "Unknown W. Brackets" Date: Sun, 4 Oct 2015 15:11:36 -0700 Subject: [PATCH] Allow loading Roboto Condensed or Roboto. The 2.x font name has changed, so let's allow either as the default. --- UI/NativeApp.cpp | 30 +++++++++++++++++++++++++++++- 1 file changed, 29 insertions(+), 1 deletion(-) diff --git a/UI/NativeApp.cpp b/UI/NativeApp.cpp index 09a0ee6f70..8a61e8c4f8 100644 --- a/UI/NativeApp.cpp +++ b/UI/NativeApp.cpp @@ -261,6 +261,29 @@ void NativeGetAppInfo(std::string *app_dir_name, std::string *app_nice_name, boo #endif } +#ifdef _WIN32 +bool CheckFontIsUsable(const wchar_t *fontFace) { + wchar_t actualFontFace[1024] = { 0 }; + + HFONT f = CreateFont(0, 0, 0, 0, FW_LIGHT, 0, FALSE, FALSE, DEFAULT_CHARSET, OUT_DEFAULT_PRECIS, CLIP_DEFAULT_PRECIS, PROOF_QUALITY, VARIABLE_PITCH, fontFace); + if (f != nullptr) { + HDC hdc = CreateCompatibleDC(nullptr); + if (hdc != nullptr) { + SelectObject(hdc, f); + GetTextFace(hdc, 1024, actualFontFace); + DeleteDC(hdc); + } + DeleteObject(f); + } + + // If we were able to get the font name, did it load? + if (actualFontFace[0] != 0) { + return wcsncmp(actualFontFace, fontFace, ARRAY_SIZE(actualFontFace)) == 0; + } + return false; +} +#endif + void NativeInit(int argc, const char *argv[], const char *savegame_directory, const char *external_directory, const char *installID, bool fs) { #ifdef ANDROID_NDK_PROFILER @@ -445,7 +468,12 @@ void NativeInit(int argc, const char *argv[], // 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); - g_Config.sFont = des->T("Font", "Roboto"); + // The font goes by two names, let's allow either one. + if (CheckFontIsUsable(L"Roboto Condensed")) { + g_Config.sFont = des->T("Font", "Roboto Condensed"); + } else { + g_Config.sFont = des->T("Font", "Roboto"); + } #endif if (!boot_filename.empty() && stateToLoad != NULL)