Codechange: reduce code duplication

This commit is contained in:
glx22
2022-12-22 19:41:58 +01:00
committed by Loïc Guilloux
parent 7b5edba76c
commit af3df959c2
6 changed files with 32 additions and 42 deletions

View File

@@ -580,16 +580,7 @@ void Win32FontCache::ClearFontCache()
*/
void LoadWin32Font(FontSize fs)
{
static const char *SIZE_TO_NAME[] = { "medium", "small", "large", "mono" };
FontCacheSubSetting *settings = nullptr;
switch (fs) {
case FS_SMALL: settings = &_fcsettings.small; break;
case FS_NORMAL: settings = &_fcsettings.medium; break;
case FS_LARGE: settings = &_fcsettings.large; break;
case FS_MONO: settings = &_fcsettings.mono; break;
default: NOT_REACHED();
}
FontCacheSubSetting *settings = GetFontCacheSubSetting(fs);
if (settings->font.empty()) return;
@@ -647,7 +638,7 @@ void LoadWin32Font(FontSize fs)
logfont.lfWeight = strcasestr(font_name, " bold") != nullptr || strcasestr(font_name, "-bold") != nullptr ? FW_BOLD : FW_NORMAL; // Poor man's way to allow selecting bold fonts.
}
} else {
ShowInfoF("Unable to load file '%s' for %s font, using default windows font selection instead", font_name, SIZE_TO_NAME[fs]);
ShowInfoF("Unable to load file '%s' for %s font, using default windows font selection instead", font_name, FontSizeToName(fs));
}
}
}
@@ -659,7 +650,7 @@ void LoadWin32Font(FontSize fs)
HFONT font = CreateFontIndirect(&logfont);
if (font == nullptr) {
ShowInfoF("Unable to use '%s' for %s font, Win32 reported error 0x%lX, using sprite font instead", font_name, SIZE_TO_NAME[fs], GetLastError());
ShowInfoF("Unable to use '%s' for %s font, Win32 reported error 0x%lX, using sprite font instead", font_name, FontSizeToName(fs), GetLastError());
return;
}
DeleteObject(font);