1
0
Fork 0
mirror of https://github.com/reactos/reactos.git synced 2025-05-29 05:58:13 +00:00

[CONCFG:FONT] Implement support for the Windows 10 "__DefaultTTFont__" special FaceName value. ()

This special value tells the console to default to whichever font
is deemed most appropriate for the current code page.

Add Doxygen documentation for FindCachedTTFont().
This commit is contained in:
Hermès Bélusca-Maïto 2022-01-30 18:29:00 +01:00
parent 0b6b0b0021
commit 2ae45e0985
No known key found for this signature in database
GPG key ID: 3B2539C65E7B93D0
2 changed files with 117 additions and 22 deletions
win32ss/user/winsrv/concfg

View file

@ -25,6 +25,8 @@
/* GLOBALS ********************************************************************/ /* GLOBALS ********************************************************************/
#define TERMINAL_FACENAME L"Terminal" #define TERMINAL_FACENAME L"Terminal"
#define DEFAULT_NON_DBCS_FONTFACE L"Lucida Console" // L"Consolas"
#define DEFAULT_TT_FONT_FACENAME L"__DefaultTTFont__"
/* TrueType font list cache */ /* TrueType font list cache */
SINGLE_LIST_ENTRY TTFontCache = { NULL }; SINGLE_LIST_ENTRY TTFontCache = { NULL };
@ -322,6 +324,35 @@ FindSuitableFont(
Param.SearchFont.CharSet = CodePageToCharSet(CodePage); Param.SearchFont.CharSet = CodePageToCharSet(CodePage);
Param.CodePage = CodePage; Param.CodePage = CodePage;
if (/* !FaceName || */ !*FaceName)
{
/* Find and use a default Raster font */
/* Use "Terminal" as the fallback */
StringCchCopyW(FaceName, LF_FACESIZE, TERMINAL_FACENAME);
#if 0
// FIXME: CJK font choose workaround: Don't choose Asian
// charset font if there is no preferred font for CJK.
if (IsCJKCodePage(CodePage))
FontData->CharSet = ANSI_CHARSET;
#endif
FontData->Family &= ~TMPF_TRUETYPE;
}
else if (wcscmp(FaceName, DEFAULT_TT_FONT_FACENAME) == 0)
{
/* Find and use a default TrueType font */
FontEntry = FindCachedTTFont(NULL, CodePage);
if (FontEntry)
{
StringCchCopyW(FaceName, LF_FACESIZE, FontEntry->FaceName);
}
else
{
StringCchCopyW(FaceName, LF_FACESIZE, DEFAULT_NON_DBCS_FONTFACE);
}
FontData->Family |= TMPF_TRUETYPE;
}
/* Search for a TrueType alternative face name */ /* Search for a TrueType alternative face name */
FontEntry = FindCachedTTFont(FaceName, CodePage); FontEntry = FindCachedTTFont(FaceName, CodePage);
if (FontEntry) if (FontEntry)
@ -492,12 +523,20 @@ CreateConsoleFontEx(
FontData->Size.Y = Height; FontData->Size.Y = Height;
FontData->CharSet = 0; // CodePageToCharSet(CodePage); FontData->CharSet = 0; // CodePageToCharSet(CodePage);
if (/* !FaceName || */ !*FaceName || wcscmp(FaceName, DEFAULT_TT_FONT_FACENAME) == 0)
{
/* We do not have an actual font face name yet and should find one.
* Call FindSuitableFont() to determine the default font to use. */
}
else
{
hFont = CreateConsoleFontWorker(FontData, CodePage); hFont = CreateConsoleFontWorker(FontData, CodePage);
if (hFont) if (hFont)
return hFont; return hFont;
DBGFNT1("CreateConsoleFont('%S') failed - Try to find a suitable font...\n", DBGFNT1("CreateConsoleFont('%S') failed - Try to find a suitable font...\n",
FaceName); FaceName);
}
/* /*
* We could not create a font with the default settings. * We could not create a font with the default settings.
@ -515,6 +554,9 @@ CreateConsoleFontEx(
if (!UseDefaultFallback) if (!UseDefaultFallback)
return NULL; return NULL;
//
// FIXME: See also !*FaceName case in FindSuitableFont().
//
/* Use "Terminal" as the fallback */ /* Use "Terminal" as the fallback */
StringCchCopyW(FaceName, LF_FACESIZE, TERMINAL_FACENAME); StringCchCopyW(FaceName, LF_FACESIZE, TERMINAL_FACENAME);
#if 0 #if 0
@ -523,6 +565,7 @@ CreateConsoleFontEx(
if (IsCJKCodePage(CodePage)) if (IsCJKCodePage(CodePage))
FontData->CharSet = ANSI_CHARSET; FontData->CharSet = ANSI_CHARSET;
#endif #endif
FontData->Family &= ~TMPF_TRUETYPE;
} }
else else
{ {
@ -1113,16 +1156,41 @@ RefreshTTFontCache(VOID)
InitTTFontCache(); InitTTFontCache();
} }
/**
* @brief
* Searches for a font in the console TrueType font cache,
* with the specified code page.
*
* @param[in,opt] FaceName
* An optional pointer to a maximally @b LF_FACESIZE-sized buffer.
* The buffer contains the face name of the font to search for.
*
* - If FaceName != NULL, search for the named font that should
* match the provided code page (when CodePage != INVALID_CP).
*
* - If FaceName == NULL, search for a font with the provided
* code page. In this case, CodePage cannot be == INVALID_CP,
* otherwise the search fails.
*
* @param[in] CodePage
* The code page the font has to support, or @b INVALID_CP when
* searching a font by face name only.
*
* @return
* A pointer to the cache entry for the font, or @b NULL if not found.
**/
PTT_FONT_ENTRY PTT_FONT_ENTRY
FindCachedTTFont( FindCachedTTFont(
// _In_reads_or_z_(LF_FACESIZE) _In_reads_or_z_opt_(LF_FACESIZE)
_In_ PCWSTR FaceName, PCWSTR FaceName,
_In_ UINT CodePage) _In_ UINT CodePage)
{ {
PSINGLE_LIST_ENTRY Entry; PSINGLE_LIST_ENTRY Entry;
PTT_FONT_ENTRY FontEntry; PTT_FONT_ENTRY FontEntry;
/* Search for the font in the cache */ if (FaceName)
{
/* Search for the named font */
for (Entry = TTFontCache.Next; for (Entry = TTFontCache.Next;
Entry != NULL; Entry != NULL;
Entry = Entry->Next) Entry = Entry->Next)
@ -1133,13 +1201,29 @@ FindCachedTTFont(
if ((wcscmp(FontEntry->FaceName , FaceName) == 0) || if ((wcscmp(FontEntry->FaceName , FaceName) == 0) ||
(wcscmp(FontEntry->FaceNameAlt, FaceName) == 0)) (wcscmp(FontEntry->FaceNameAlt, FaceName) == 0))
{ {
/* Return a match if we don't look at the code pages, or when they match */ /* Return the font if we don't search by code page, or when they match */
if ((CodePage == INVALID_CP) || (CodePage == FontEntry->CodePage)) if ((CodePage == INVALID_CP) || (CodePage == FontEntry->CodePage))
{ {
return FontEntry; return FontEntry;
} }
} }
} }
}
else if (CodePage != INVALID_CP)
{
/* Search for a font with the specified code page */
for (Entry = TTFontCache.Next;
Entry != NULL;
Entry = Entry->Next)
{
FontEntry = CONTAINING_RECORD(Entry, TT_FONT_ENTRY, Entry);
/* Return the font if the code pages match */
if (CodePage == FontEntry->CodePage)
return FontEntry;
}
}
return NULL; return NULL;
} }

View file

@ -150,10 +150,21 @@ RefreshTTFontCache(VOID);
PTT_FONT_ENTRY PTT_FONT_ENTRY
FindCachedTTFont( FindCachedTTFont(
// _In_reads_or_z_(LF_FACESIZE) _In_reads_or_z_opt_(LF_FACESIZE)
_In_ PCWSTR FaceName, PCWSTR FaceName,
_In_ UINT CodePage); _In_ UINT CodePage);
/**
* @brief
* Verifies whether the given font is an additional console TrueType font.
* Wrapper macros around FindCachedTTFont().
*
* @remark
* These macros are equivalents of the functions
* IsAvailableTTFont() and IsAvailableTTFontCP() in
* https://github.com/microsoft/terminal/blob/main/src/propsheet/dbcs.cpp
**/
#define IsAdditionalTTFont(FaceName) \ #define IsAdditionalTTFont(FaceName) \
(FindCachedTTFont((FaceName), INVALID_CP) != NULL) (FindCachedTTFont((FaceName), INVALID_CP) != NULL)