#define TERMINAL_FACENAME L"Terminal"
-// RTL_STATIC_LIST_HEAD(TTFontCache);
-LIST_ENTRY TTFontCache = {&TTFontCache, &TTFontCache};
+/* TrueType font list cache */
+SINGLE_LIST_ENTRY TTFontCache = { NULL };
// NOTE: Used to tag code that makes sense only with a font cache.
// #define FONT_CACHE_PRESENT
return Param.IsValidFont;
}
-/*
+
+/**
+ * @brief
+ * Initializes the console TrueType font cache.
+ *
+ * @remark
* To install additional TrueType fonts to be available for the console,
* add entries of type REG_SZ named "0", "00" etc... in:
* HKEY_LOCAL_MACHINE\Software\Microsoft\Windows NT\CurrentVersion\Console\TrueTypeFont
* The names of the fonts listed there should match those in:
* HKEY_LOCAL_MACHINE\Software\Microsoft\Windows NT\CurrentVersion\Fonts
*
- * This function initializes the cache of the fonts listed there.
- */
+ * @return None.
+ **/
VOID
InitTTFontCache(VOID)
{
PTT_FONT_ENTRY FontEntry;
PWCHAR pszNext;
- if (!IsListEmpty(&TTFontCache))
+ if (TTFontCache.Next != NULL)
return;
- // InitializeListHead(&TTFontCache);
+ // TTFontCache.Next = NULL;
/* Open the Console\TrueTypeFont key */
// "\\Registry\\Machine\\Software\\Microsoft\\Windows NT\\CurrentVersion\\Console\\TrueTypeFont"
pszNext = szValue;
/* Check whether bold is disabled for this font */
- if (*pszNext == L'*')
+ if (*pszNext == BOLD_MARK)
{
FontEntry->DisableBold = TRUE;
++pszNext;
pszNext += wcslen(pszNext) + 1;
/* Check whether bold is disabled for this font */
- if (*pszNext == L'*')
+ if (*pszNext == BOLD_MARK)
{
FontEntry->DisableBold = TRUE;
++pszNext;
pszNext, wcslen(pszNext));
}
- InsertTailList(&TTFontCache, &FontEntry->Entry);
+ PushEntryList(&TTFontCache, &FontEntry->Entry);
}
/* Close the key and quit */
RegCloseKey(hKey);
}
+/**
+ * @brief
+ * Clears the console TrueType font cache.
+ *
+ * @return None.
+ **/
VOID
ClearTTFontCache(VOID)
{
- PLIST_ENTRY Entry;
+ PSINGLE_LIST_ENTRY Entry;
PTT_FONT_ENTRY FontEntry;
- while (!IsListEmpty(&TTFontCache))
+ while (TTFontCache.Next != NULL)
{
- Entry = RemoveHeadList(&TTFontCache);
+ Entry = PopEntryList(&TTFontCache);
FontEntry = CONTAINING_RECORD(Entry, TT_FONT_ENTRY, Entry);
RtlFreeHeap(RtlGetProcessHeap(), 0, FontEntry);
}
- InitializeListHead(&TTFontCache);
+ TTFontCache.Next = NULL;
}
+/**
+ * @brief
+ * Refreshes the console TrueType font cache,
+ * by clearing and re-initializing it.
+ *
+ * @return None.
+ **/
VOID
RefreshTTFontCache(VOID)
{
_In_ PCWSTR FaceName,
_In_ UINT CodePage)
{
- PLIST_ENTRY Entry;
+ PSINGLE_LIST_ENTRY Entry;
PTT_FONT_ENTRY FontEntry;
/* Search for the font in the cache */
- for (Entry = TTFontCache.Flink;
- Entry != &TTFontCache;
- Entry = Entry->Flink)
+ for (Entry = TTFontCache.Next;
+ Entry != NULL;
+ Entry = Entry->Next)
{
FontEntry = CONTAINING_RECORD(Entry, TT_FONT_ENTRY, Entry);
#define IsBoldFont(Weight) \
((Weight) >= FW_SEMIBOLD) /* Sometimes, just > FW_MEDIUM */
+
+/*
+ * @struct TrueType font list, cached from
+ * HKEY_LOCAL_MACHINE\Software\Microsoft\Windows NT\CurrentVersion\Console\TrueTypeFont
+ *
+ * See the definition of struct _TT_FONT_LIST
+ * in https://github.com/microsoft/terminal/blob/main/dep/Console/winconp.h
+ */
+#define BOLD_MARK L'*'
+
typedef struct _TT_FONT_ENTRY
{
- LIST_ENTRY Entry;
+ SINGLE_LIST_ENTRY Entry;
UINT CodePage;
BOOL DisableBold;
WCHAR FaceName[LF_FACESIZE];
_In_ PCWSTR FaceName,
_In_ UINT CodePage);
-/*
- * To install additional TrueType fonts to be available for the console,
- * add entries of type REG_SZ named "0", "00" etc... in:
- * HKEY_LOCAL_MACHINE\Software\Microsoft\Windows NT\CurrentVersion\Console\TrueTypeFont
- * The names of the fonts listed there should match those in:
- * HKEY_LOCAL_MACHINE\Software\Microsoft\Windows NT\CurrentVersion\Fonts
- *
- * This function initializes the cache of the fonts listed there.
- */
+
VOID
InitTTFontCache(VOID);