Merge pull request #8025 from unknownbrackets/ui-tweaks

Allow loading Roboto Condensed or Roboto
This commit is contained in:
Henrik Rydgård 2015-10-05 00:15:22 +02:00
commit 94477df686

View File

@ -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)