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, ENUMLOGFONTEXA *lpelfe,
NEWTEXTMETRICEXA *lpntme, NEWTEXTMETRICEXA *lpntme,
DWORD FontType, DWORD FontType,
@ -459,7 +459,7 @@ bool gdrv::find_font(const char* fontName)
strcpy_s(lf.lfFaceName, fontName); strcpy_s(lf.lfFaceName, fontName);
HDC hDC = GetDC(NULL); 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); ReleaseDC(NULL, hDC);
return params.found; return params.found;
} }
@ -472,11 +472,9 @@ void gdrv::choose_font()
static const int fontSizes_System[3] = { 17, 21, 29 }; static const int fontSizes_System[3] = { 17, 21, 29 };
static const int fontSizes_WinMenu[3] = { 17, 21, 27 }; static const int fontSizes_WinMenu[3] = { 17, 21, 27 };
const char* system_font_filename = nullptr; // Default path: scalable TTF font with AA.
// Only System font requires non-default charset, fontCharset = DEFAULT_CHARSET;
// and custom charsets may break other fonts (like WinMenu). auto specialFont = true;
int systemFontCharset = DEFAULT_CHARSET;
switch (options::Options.Language) switch (options::Options.Language)
{ {
case Languages::TraditionalChinese: case Languages::TraditionalChinese:
@ -489,60 +487,71 @@ void gdrv::choose_font()
break; break;
case Languages::Japanese: case Languages::Japanese:
fontFamily = "MS UI Gothic"; fontFamily = "MS UI Gothic";
fontSizes = fontSizes_Arial; // we need feedback for this fontSizes = fontSizes_EastAsian;
break; break;
case Languages::Korean: case Languages::Korean:
fontFamily = "Gulim"; fontFamily = "Gulim";
fontSizes = fontSizes_EastAsian; fontSizes = fontSizes_EastAsian;
break; 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: case Languages::Greek:
system_font_filename = "vgasysg.fon"; system_font_filename = "vgasysg.fon";
systemFontCharset = GREEK_CHARSET; fontCharset = GREEK_CHARSET;
break; break;
case Languages::Russian: case Languages::Russian:
system_font_filename = "vgasysr.fon"; system_font_filename = "vgasysr.fon";
systemFontCharset = RUSSIAN_CHARSET; fontCharset = RUSSIAN_CHARSET;
break; break;
case Languages::Turkish: case Languages::Turkish:
system_font_filename = "vgasyst.fon"; system_font_filename = "vgasyst.fon";
systemFontCharset = TURKISH_CHARSET; fontCharset = TURKISH_CHARSET;
break; break;
case Languages::Danish: case Languages::Danish:
case Languages::Dutch: case Languages::Dutch:
case Languages::Norwegian: case Languages::Norwegian:
case Languages::Swedish: case Languages::Swedish:
system_font_filename = "vgasys.fon"; system_font_filename = "vgasys.fon";
systemFontCharset = DEFAULT_CHARSET; fontCharset = DEFAULT_CHARSET;
break; break;
case Languages::Czech: case Languages::Czech:
case Languages::Hungarian: case Languages::Hungarian:
case Languages::Polish: case Languages::Polish:
case Languages::Finnish:
system_font_filename = "vgasyse.fon"; system_font_filename = "vgasyse.fon";
systemFontCharset = EASTEUROPE_CHARSET; fontCharset = EASTEUROPE_CHARSET;
break; break;
default: default:
system_font_filename = "vgasys.fon"; system_font_filename = "vgasys.fon";
fontCharset = DEFAULT_CHARSET;
break; 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'); std::string windir(MAX_PATH, '\0');
DWORD result = GetEnvironmentVariableA("WINDIR", &windir[0], MAX_PATH); DWORD result = GetEnvironmentVariableA("WINDIR", &windir[0], MAX_PATH);
if (result == 0 || result > MAX_PATH) // fails or doesn't fit 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; fontFilename = windir + "\\Fonts\\" + system_font_filename;
AddFontResourceExA(fontFilename.c_str(), FR_PRIVATE, 0); 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) 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, static void copy_bitmap_w_transparency(gdrv_bitmap8* dstBmp, int width, int height, int xOff, int yOff,
gdrv_bitmap8* srcBmp, int srcXOff, int srcYOff); gdrv_bitmap8* srcBmp, int srcXOff, int srcYOff);
static void ScrollBitmapHorizontal(gdrv_bitmap8* bmp, int xStart); 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); static void grtext_draw_ttext_in_box(LPCWSTR text, int xOff, int yOff, int width, int height, bool centered);
private: private:
/*COLORONCOLOR or HALFTONE*/ /*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, 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, int SrcWidth, int SrcHeight, gdrv_bitmap8* bmp, UINT iUsage,
DWORD rop); 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();
}; };