Refactored System font option.

This commit is contained in:
Muzychenko Andrey 2022-01-18 12:53:20 +03:00
parent 7a6ae6ac50
commit 6ce3f654b1
2 changed files with 69 additions and 60 deletions

View File

@ -436,7 +436,7 @@ void gdrv::ScrollBitmapHorizontal(gdrv_bitmap8* bmp, int xStart)
}
}
int CALLBACK gdrv_find_font_func(
int CALLBACK gdrv::find_font_func(
ENUMLOGFONTEXA *lpelfe,
NEWTEXTMETRICEXA *lpntme,
DWORD FontType,
@ -459,7 +459,7 @@ bool gdrv::find_font(const char* fontName)
strcpy_s(lf.lfFaceName, fontName);
HDC hDC = GetDC(NULL);
EnumFontFamiliesExA(hDC, &lf, (FONTENUMPROCA)&gdrv_find_font_func, reinterpret_cast<LPARAM>(&params), 0);
EnumFontFamiliesExA(hDC, &lf, (FONTENUMPROCA)&find_font_func, reinterpret_cast<LPARAM>(&params), 0);
ReleaseDC(NULL, hDC);
return params.found;
}
@ -472,11 +472,9 @@ void gdrv::choose_font()
static const int fontSizes_System[3] = { 17, 21, 29 };
static const int fontSizes_WinMenu[3] = { 17, 21, 27 };
const char* system_font_filename = nullptr;
// Only System font requires non-default charset,
// and custom charsets may break other fonts (like WinMenu).
int systemFontCharset = DEFAULT_CHARSET;
// Default path: scalable TTF font with AA.
fontCharset = DEFAULT_CHARSET;
auto specialFont = true;
switch (options::Options.Language)
{
case Languages::TraditionalChinese:
@ -489,60 +487,71 @@ void gdrv::choose_font()
break;
case Languages::Japanese:
fontFamily = "MS UI Gothic";
fontSizes = fontSizes_Arial; // we need feedback for this
fontSizes = fontSizes_EastAsian;
break;
case Languages::Korean:
fontFamily = "Gulim";
fontSizes = fontSizes_EastAsian;
break;
default:
fontFamily = "Arial";
fontSizes = fontSizes_Arial;
specialFont = false;
}
// System font does not support some languages.
if (!options::Options.SystemFont || specialFont)
return;
// Alternative path: user defined font or System font.
auto userFont = options::Options.SystemFontName;
if (userFont[0] != '\0' && find_font(userFont))
{
fontFamily = userFont;
fontSizes = fontSizes_WinMenu;
}
else
{
// Original game does no font setup, so it ends up with default System font.
// System is a bitmap font with no AA and limited scaling support.
// Specific .fon selection is needed for improved language support.
fontFamily = "System";
fontSizes = fontSizes_System;
const char* system_font_filename = nullptr;
switch (options::Options.Language)
{
case Languages::Greek:
system_font_filename = "vgasysg.fon";
systemFontCharset = GREEK_CHARSET;
fontCharset = GREEK_CHARSET;
break;
case Languages::Russian:
system_font_filename = "vgasysr.fon";
systemFontCharset = RUSSIAN_CHARSET;
fontCharset = RUSSIAN_CHARSET;
break;
case Languages::Turkish:
system_font_filename = "vgasyst.fon";
systemFontCharset = TURKISH_CHARSET;
fontCharset = TURKISH_CHARSET;
break;
case Languages::Danish:
case Languages::Dutch:
case Languages::Norwegian:
case Languages::Swedish:
system_font_filename = "vgasys.fon";
systemFontCharset = DEFAULT_CHARSET;
fontCharset = DEFAULT_CHARSET;
break;
case Languages::Czech:
case Languages::Hungarian:
case Languages::Polish:
case Languages::Finnish:
system_font_filename = "vgasyse.fon";
systemFontCharset = EASTEUROPE_CHARSET;
fontCharset = EASTEUROPE_CHARSET;
break;
default:
system_font_filename = "vgasys.fon";
fontCharset = DEFAULT_CHARSET;
break;
}
if (fontFamily.empty()) // no font chosen yet
{
if (!options::Options.SystemFont)
{
fontFamily = "Arial";
fontSizes = fontSizes_Arial;
}
else if (options::Options.SystemFontName[0] != '\0' && find_font(options::Options.SystemFontName))
{
fontFamily = options::Options.SystemFontName;
fontSizes = fontSizes_WinMenu;
}
else
{
fontFamily = "System";
fontSizes = fontSizes_System;
fontCharset = systemFontCharset;
std::string windir(MAX_PATH, '\0');
DWORD result = GetEnvironmentVariableA("WINDIR", &windir[0], MAX_PATH);
if (result == 0 || result > MAX_PATH) // fails or doesn't fit
@ -553,7 +562,6 @@ void gdrv::choose_font()
fontFilename = windir + "\\Fonts\\" + system_font_filename;
AddFontResourceExA(fontFilename.c_str(), FR_PRIVATE, 0);
}
}
}
void gdrv::grtext_draw_ttext_in_box(LPCWSTR text, int xOff, int yOff, int width, int height, bool centered)

View File

@ -70,8 +70,6 @@ public:
static void copy_bitmap_w_transparency(gdrv_bitmap8* dstBmp, int width, int height, int xOff, int yOff,
gdrv_bitmap8* srcBmp, int srcXOff, int srcYOff);
static void ScrollBitmapHorizontal(gdrv_bitmap8* bmp, int xStart);
static bool find_font(const char* fontName);
static void choose_font();
static void grtext_draw_ttext_in_box(LPCWSTR text, int xOff, int yOff, int width, int height, bool centered);
private:
/*COLORONCOLOR or HALFTONE*/
@ -89,4 +87,7 @@ private:
static int StretchDIBitsScaled(HDC hdc, int xDest, int yDest, int DestWidth, int DestHeight, int xSrc, int ySrc,
int SrcWidth, int SrcHeight, gdrv_bitmap8* bmp, UINT iUsage,
DWORD rop);
static bool find_font(const char* fontName);
static int CALLBACK find_font_func(ENUMLOGFONTEXA* lpelfe, NEWTEXTMETRICEXA* lpntme, DWORD FontType, LPARAM lParam);
static void choose_font();
};