ReactOS  0.4.14-dev-1279-gc1464a4
font.h File Reference
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Classes

struct  _TT_FONT_ENTRY
 

Macros

#define INVALID_CP   ((UINT)-1)
 
#define CP_SHIFTJIS   932
 
#define CP_HANGUL   949
 
#define CP_JOHAB   1361
 
#define CP_GB2312   936
 
#define CP_BIG5   950
 
#define IsCJKCodePage(CodePage)
 
#define SHIFTJIS_CHARSET   128
 
#define HANGEUL_CHARSET   129
 
#define HANGUL_CHARSET   129
 
#define GB2312_CHARSET   134
 
#define CHINESEBIG5_CHARSET   136
 
#define IsCJKCharSet(CharSet)
 
#define IsBoldFont(Weight)   ((Weight) >= FW_SEMIBOLD) /* Sometimes, just > FW_MEDIUM */
 
#define IsAdditionalTTFont(FaceName)   (FindCachedTTFont((FaceName), INVALID_CP) != NULL)
 
#define IsAdditionalTTFontCP(FaceName, CodePage)   (FindCachedTTFont((FaceName), (CodePage)) != NULL)
 

Typedefs

typedef struct _TT_FONT_ENTRY TT_FONT_ENTRY
 
typedef struct _TT_FONT_ENTRYPTT_FONT_ENTRY
 

Functions

BYTE CodePageToCharSet (IN UINT CodePage)
 
HFONT CreateConsoleFontEx (IN LONG Height, IN LONG Width OPTIONAL, IN OUT LPWSTR FaceName, IN ULONG FontFamily, IN ULONG FontWeight, IN UINT CodePage)
 
HFONT CreateConsoleFont2 (IN LONG Height, IN LONG Width OPTIONAL, IN OUT PCONSOLE_STATE_INFO ConsoleInfo)
 
HFONT CreateConsoleFont (IN OUT PCONSOLE_STATE_INFO ConsoleInfo)
 
BOOL GetFontCellSize (IN HDC hDC OPTIONAL, IN HFONT hFont, OUT PUINT Height, OUT PUINT Width)
 
BOOL IsValidConsoleFont2 (IN PLOGFONTW lplf, IN PNEWTEXTMETRICW lpntm, IN DWORD FontType, IN UINT CodePage)
 
BOOL IsValidConsoleFont (IN LPCWSTR FaceName, IN UINT CodePage)
 
VOID InitTTFontCache (VOID)
 
VOID ClearTTFontCache (VOID)
 
VOID RefreshTTFontCache (VOID)
 
PTT_FONT_ENTRY FindCachedTTFont (IN LPCWSTR FaceName, IN UINT CodePage)
 

Macro Definition Documentation

◆ CHINESEBIG5_CHARSET

#define CHINESEBIG5_CHARSET   136

Definition at line 36 of file font.h.

◆ CP_BIG5

#define CP_BIG5   950

Definition at line 20 of file font.h.

◆ CP_GB2312

#define CP_GB2312   936

Definition at line 19 of file font.h.

◆ CP_HANGUL

#define CP_HANGUL   949

Definition at line 17 of file font.h.

◆ CP_JOHAB

#define CP_JOHAB   1361

Definition at line 18 of file font.h.

◆ CP_SHIFTJIS

#define CP_SHIFTJIS   932

Definition at line 16 of file font.h.

◆ GB2312_CHARSET

#define GB2312_CHARSET   134

Definition at line 35 of file font.h.

◆ HANGEUL_CHARSET

#define HANGEUL_CHARSET   129

Definition at line 30 of file font.h.

◆ HANGUL_CHARSET

#define HANGUL_CHARSET   129

Definition at line 31 of file font.h.

◆ INVALID_CP

#define INVALID_CP   ((UINT)-1)

Definition at line 14 of file font.h.

◆ IsAdditionalTTFont

#define IsAdditionalTTFont (   FaceName)    (FindCachedTTFont((FaceName), INVALID_CP) != NULL)

Definition at line 125 of file font.h.

◆ IsAdditionalTTFontCP

#define IsAdditionalTTFontCP (   FaceName,
  CodePage 
)    (FindCachedTTFont((FaceName), (CodePage)) != NULL)

Definition at line 128 of file font.h.

◆ IsBoldFont

#define IsBoldFont (   Weight)    ((Weight) >= FW_SEMIBOLD) /* Sometimes, just > FW_MEDIUM */

Definition at line 45 of file font.h.

◆ IsCJKCharSet

#define IsCJKCharSet (   CharSet)
Value:
/* (CharSet) == JOHAB_CHARSET || */ \
static void CharSet(RTF_Info *info)
Definition: reader.c:2420
#define GB2312_CHARSET
Definition: font.h:35
#define SHIFTJIS_CHARSET
Definition: font.h:29
#define CHINESEBIG5_CHARSET
Definition: font.h:36
#define HANGUL_CHARSET
Definition: font.h:31

Definition at line 40 of file font.h.

◆ IsCJKCodePage

#define IsCJKCodePage (   CodePage)
Value:
((CodePage) == CP_SHIFTJIS || (CodePage) == CP_HANGUL || \
/* (CodePage) == CP_JOHAB || */ \
(CodePage) == CP_BIG5 || (CodePage) == CP_GB2312)
#define CP_GB2312
Definition: font.h:19
#define CP_HANGUL
Definition: font.h:17
#define CP_SHIFTJIS
Definition: font.h:16
#define CP_BIG5
Definition: font.h:20

Definition at line 23 of file font.h.

◆ SHIFTJIS_CHARSET

#define SHIFTJIS_CHARSET   128

Definition at line 29 of file font.h.

Typedef Documentation

◆ PTT_FONT_ENTRY

◆ TT_FONT_ENTRY

Function Documentation

◆ ClearTTFontCache()

VOID ClearTTFontCache ( VOID  )

Definition at line 506 of file font.c.

507 {
509  PTT_FONT_ENTRY FontEntry;
510 
511  while (!IsListEmpty(&TTFontCache))
512  {
515  RtlFreeHeap(RtlGetProcessHeap(), 0, FontEntry);
516  }
518 }
struct _Entry Entry
Definition: kefuncs.h:627
BOOLEAN NTAPI RtlFreeHeap(IN PVOID HeapHandle, IN ULONG Flags, IN PVOID HeapBase)
Definition: heap.c:606
_Must_inspect_result_ FORCEINLINE BOOLEAN IsListEmpty(_In_ const LIST_ENTRY *ListHead)
Definition: rtlfuncs.h:57
LIST_ENTRY TTFontCache
Definition: font.c:26
FORCEINLINE PLIST_ENTRY RemoveHeadList(_Inout_ PLIST_ENTRY ListHead)
Definition: rtlfuncs.h:128
PFLT_MESSAGE_WAITER_QUEUE CONTAINING_RECORD(Csq, DEVICE_EXTENSION, IrpQueue)) -> WaiterQ.mLock) _IRQL_raises_(DISPATCH_LEVEL) VOID NTAPI FltpAcquireMessageWaiterLock(_In_ PIO_CSQ Csq, _Out_ PKIRQL Irql)
Definition: Messaging.c:560
Definition: typedefs.h:118
Definition: font.h:48
#define InitializeListHead(ListHead)
Definition: env_spec_w32.h:944
base of all file and directory entries
Definition: entries.h:82

Referenced by InitApplet(), and RefreshTTFontCache().

◆ CodePageToCharSet()

BYTE CodePageToCharSet ( IN UINT  CodePage)

Definition at line 32 of file font.c.

34 {
35  CHARSETINFO CharInfo;
36  if (TranslateCharsetInfo(UlongToPtr(CodePage), &CharInfo, TCI_SRCCODEPAGE))
37  return CharInfo.ciCharset;
38  else
39  return DEFAULT_CHARSET;
40 }
#define DEFAULT_CHARSET
Definition: wingdi.h:383
UINT ciCharset
Definition: wingdi.h:1545
#define UlongToPtr(u)
Definition: config.h:106
BOOL WINAPI TranslateCharsetInfo(LPDWORD lpSrc, LPCHARSETINFO lpCs, DWORD flags)
Definition: font.c:2186
#define TCI_SRCCODEPAGE
Definition: wingdi.h:961

Referenced by CreateConsoleFontEx(), and FaceNameList_Initialize().

◆ CreateConsoleFont()

HFONT CreateConsoleFont ( IN OUT PCONSOLE_STATE_INFO  ConsoleInfo)

Definition at line 101 of file font.c.

103 {
104  /*
105  * Format:
106  * Width = FontSize.X = LOWORD(FontSize);
107  * Height = FontSize.Y = HIWORD(FontSize);
108  */
109  /* NOTE: FontSize is always in cell height/width units (pixels) */
110  return CreateConsoleFontEx((LONG)(ULONG)ConsoleInfo->FontSize.Y,
111  (LONG)(ULONG)ConsoleInfo->FontSize.X,
112  ConsoleInfo->FaceName,
113  ConsoleInfo->FontFamily,
114  ConsoleInfo->FontWeight,
115  ConsoleInfo->CodePage);
116 }
long LONG
Definition: pedump.c:60
static CONSOLE_SCREEN_BUFFER_INFO ConsoleInfo
Definition: video.c:47
HFONT CreateConsoleFontEx(IN LONG Height, IN LONG Width OPTIONAL, IN OUT LPWSTR FaceName, IN ULONG FontFamily, IN ULONG FontWeight, IN UINT CodePage)
Definition: font.c:43
unsigned int ULONG
Definition: retypes.h:1

Referenced by RefreshFontPreview().

◆ CreateConsoleFont2()

HFONT CreateConsoleFont2 ( IN LONG  Height,
IN LONG Width  OPTIONAL,
IN OUT PCONSOLE_STATE_INFO  ConsoleInfo 
)

Definition at line 87 of file font.c.

91 {
92  return CreateConsoleFontEx(Height,
93  Width,
94  ConsoleInfo->FaceName,
95  ConsoleInfo->FontFamily,
96  ConsoleInfo->FontWeight,
97  ConsoleInfo->CodePage);
98 }
static CONSOLE_SCREEN_BUFFER_INFO ConsoleInfo
Definition: video.c:47
HFONT CreateConsoleFontEx(IN LONG Height, IN LONG Width OPTIONAL, IN OUT LPWSTR FaceName, IN ULONG FontFamily, IN ULONG FontWeight, IN UINT CodePage)
Definition: font.c:43

Referenced by FontSizeChange().

◆ CreateConsoleFontEx()

HFONT CreateConsoleFontEx ( IN LONG  Height,
IN LONG Width  OPTIONAL,
IN OUT LPWSTR  FaceName,
IN ULONG  FontFamily,
IN ULONG  FontWeight,
IN UINT  CodePage 
)

Definition at line 43 of file font.c.

50 {
51  LOGFONTW lf;
52 
53  RtlZeroMemory(&lf, sizeof(lf));
54 
55  lf.lfHeight = Height;
56  lf.lfWidth = Width;
57 
58  lf.lfEscapement = 0;
59  lf.lfOrientation = 0; // TA_BASELINE; // TA_RTLREADING; when the console supports RTL?
60  // lf.lfItalic = lf.lfUnderline = lf.lfStrikeOut = FALSE;
61  lf.lfWeight = FontWeight;
62  lf.lfCharSet = CodePageToCharSet(CodePage);
66 
67  /* Set the mandatory flags and remove those that we do not support */
70 
71  if (!IsValidConsoleFont(FaceName, CodePage))
72  {
73  StringCchCopyW(FaceName, LF_FACESIZE, L"Terminal");
74  if (IsCJKCodePage(CodePage))
75  {
77  }
78  }
79 
81  FaceName, LF_FACESIZE);
82 
83  return CreateFontIndirectW(&lf);
84 }
HFONT WINAPI CreateFontIndirectW(CONST LOGFONTW *lplf)
Definition: font.c:1803
STRSAFEAPI StringCchCopyNW(STRSAFE_LPWSTR pszDest, size_t cchDest, STRSAFE_LPCWSTR pszSrc, size_t cchToCopy)
Definition: strsafe.h:236
#define LF_FACESIZE
Definition: dimm.idl:39
BYTE lfPitchAndFamily
Definition: dimm.idl:71
#define VARIABLE_PITCH
Definition: wingdi.h:444
#define DEFAULT_QUALITY
Definition: wingdi.h:435
#define FF_DECORATIVE
Definition: wingdi.h:446
LONG lfHeight
Definition: dimm.idl:59
BYTE lfCharSet
Definition: dimm.idl:67
BYTE lfClipPrecision
Definition: dimm.idl:69
BYTE CodePageToCharSet(IN UINT CodePage)
Definition: font.c:32
#define ARRAYSIZE(array)
Definition: filtermapper.c:47
LONG lfEscapement
Definition: dimm.idl:61
#define IsCJKCodePage(CodePage)
Definition: font.h:23
#define FIXED_PITCH
Definition: wingdi.h:443
LONG lfOrientation
Definition: dimm.idl:62
STRSAFEAPI StringCchCopyW(STRSAFE_LPWSTR pszDest, size_t cchDest, STRSAFE_LPCWSTR pszSrc)
Definition: strsafe.h:149
#define CLIP_DEFAULT_PRECIS
Definition: wingdi.h:425
LONG lfWidth
Definition: dimm.idl:60
BYTE lfOutPrecision
Definition: dimm.idl:68
#define OUT_DEFAULT_PRECIS
Definition: wingdi.h:414
BYTE lfQuality
Definition: dimm.idl:70
static const WCHAR L[]
Definition: oid.c:1250
unsigned char BYTE
Definition: mem.h:68
#define FF_ROMAN
Definition: wingdi.h:449
#define FF_SWISS
Definition: wingdi.h:451
#define FF_MODERN
Definition: wingdi.h:448
#define FF_SCRIPT
Definition: wingdi.h:450
WCHAR lfFaceName[LF_FACESIZE]
Definition: dimm.idl:72
#define RtlZeroMemory(Destination, Length)
Definition: typedefs.h:261
LONG lfWeight
Definition: dimm.idl:63
#define ANSI_CHARSET
Definition: wingdi.h:382
BOOL IsValidConsoleFont(IN LPCWSTR FaceName, IN UINT CodePage)
Definition: font.c:364

Referenced by CreateConsoleFont(), CreateConsoleFont2(), and InitFonts().

◆ FindCachedTTFont()

PTT_FONT_ENTRY FindCachedTTFont ( IN LPCWSTR  FaceName,
IN UINT  CodePage 
)

Definition at line 528 of file font.c.

531 {
533  PTT_FONT_ENTRY FontEntry;
534 
535  /* Search for the font in the cache */
536  for (Entry = TTFontCache.Flink;
537  Entry != &TTFontCache;
538  Entry = Entry->Flink)
539  {
541 
542  /* NOTE: The font face names are case-sensitive */
543  if ((wcscmp(FontEntry->FaceName , FaceName) == 0) ||
544  (wcscmp(FontEntry->FaceNameAlt, FaceName) == 0))
545  {
546  /* Return a match if we don't look at the code pages, or when they match */
547  if ((CodePage == INVALID_CP) || (CodePage == FontEntry->CodePage))
548  {
549  return FontEntry;
550  }
551  }
552  }
553  return NULL;
554 }
struct _Entry Entry
Definition: kefuncs.h:627
UINT CodePage
Definition: font.h:51
LIST_ENTRY TTFontCache
Definition: font.c:26
smooth NULL
Definition: ftsmooth.c:416
PFLT_MESSAGE_WAITER_QUEUE CONTAINING_RECORD(Csq, DEVICE_EXTENSION, IrpQueue)) -> WaiterQ.mLock) _IRQL_raises_(DISPATCH_LEVEL) VOID NTAPI FltpAcquireMessageWaiterLock(_In_ PIO_CSQ Csq, _Out_ PKIRQL Irql)
Definition: Messaging.c:560
struct _LIST_ENTRY * Flink
Definition: typedefs.h:120
#define INVALID_CP
Definition: stream.h:53
WCHAR FaceName[LF_FACESIZE]
Definition: font.h:53
Definition: typedefs.h:118
_Check_return_ _CRTIMP int __cdecl wcscmp(_In_z_ const wchar_t *_Str1, _In_z_ const wchar_t *_Str2)
Definition: font.h:48
WCHAR FaceNameAlt[LF_FACESIZE]
Definition: font.h:54
base of all file and directory entries
Definition: entries.h:82

◆ GetFontCellSize()

BOOL GetFontCellSize ( IN HDC hDC  OPTIONAL,
IN HFONT  hFont,
OUT PUINT  Height,
OUT PUINT  Width 
)

Definition at line 119 of file font.c.

124 {
125  BOOL Success = FALSE;
126  HDC hOrgDC = hDC;
127  HFONT hOldFont;
128  // LONG LogSize, PointSize;
130  TEXTMETRICW tm;
131  // SIZE CharSize;
132 
133  if (!hDC)
134  hDC = GetDC(NULL);
135 
136  hOldFont = SelectObject(hDC, hFont);
137  if (hOldFont == NULL)
138  {
139  DPRINT1("GetFontCellSize: SelectObject failed\n");
140  goto Quit;
141  }
142 
143 /*
144  * See also: Display_SetTypeFace in applications/fontview/display.c
145  */
146 
147  /*
148  * Note that the method with GetObjectW just returns
149  * the original parameters with which the font was created.
150  */
151  if (!GetTextMetricsW(hDC, &tm))
152  {
153  DPRINT1("GetFontCellSize: GetTextMetrics failed\n");
154  goto Cleanup;
155  }
156 
157  CharHeight = tm.tmHeight + tm.tmExternalLeading;
158 
159 #if 0
160  /* Measure real char width more precisely if possible */
161  if (GetTextExtentPoint32W(hDC, L"R", 1, &CharSize))
162  CharWidth = CharSize.cx;
163 #else
164  CharWidth = tm.tmAveCharWidth; // tm.tmMaxCharWidth;
165 #endif
166 
167 #if 0
168  /*** Logical to Point size ***/
169  LogSize = tm.tmHeight - tm.tmInternalLeading;
170  PointSize = MulDiv(LogSize, 72, GetDeviceCaps(hDC, LOGPIXELSY));
171  /*****************************/
172 #endif
173 
174  *Height = (UINT)CharHeight;
175  *Width = (UINT)CharWidth;
176  Success = TRUE;
177 
178 Cleanup:
179  SelectObject(hDC, hOldFont);
180 Quit:
181  if (!hOrgDC)
182  ReleaseDC(NULL, hDC);
183 
184  return Success;
185 }
#define TRUE
Definition: types.h:120
BOOL WINAPI GetTextMetricsW(_In_ HDC, _Out_ LPTEXTMETRICW)
Definition: text.c:221
HDC WINAPI GetDC(_In_opt_ HWND)
static HDC
Definition: imagelist.c:92
HGDIOBJ WINAPI SelectObject(_In_ HDC, _In_ HGDIOBJ)
Definition: dc.c:1497
HFONT hFont
Definition: main.c:53
unsigned int BOOL
Definition: ntddk_ex.h:94
long LONG
Definition: pedump.c:60
int WINAPI ReleaseDC(_In_opt_ HWND, _In_ HDC)
smooth NULL
Definition: ftsmooth.c:416
static int CharHeight
Definition: carets.c:8
static int CharWidth
Definition: carets.c:7
static const WCHAR L[]
Definition: oid.c:1250
int WINAPI GetDeviceCaps(_In_opt_ HDC, _In_ int)
Definition: time.h:76
static const WCHAR Cleanup[]
Definition: register.c:80
static HDC hDC
Definition: 3dtext.c:33
unsigned int UINT
Definition: ndis.h:50
#define DPRINT1
Definition: precomp.h:8
static DWORD *static HFONT(WINAPI *pCreateFontIndirectExA)(const ENUMLOGFONTEXDVA *)
#define LOGPIXELSY
Definition: wingdi.h:718
#define MulDiv(x, y, z)
Definition: gdifloat.h:86
BOOL WINAPI GetTextExtentPoint32W(_In_ HDC hdc, _In_reads_(c) LPCWSTR lpString, _In_ int c, _Out_ LPSIZE psizl)

Referenced by FontSizeChange(), InitFonts(), and RefreshFontPreview().

◆ InitTTFontCache()

VOID InitTTFontCache ( VOID  )

Definition at line 397 of file font.c.

398 {
400  HKEY hKeyTTFonts; // hKey;
401  DWORD dwNumValues = 0;
402  DWORD dwIndex;
403  DWORD dwType;
404  WCHAR szValueName[MAX_PATH];
405  DWORD dwValueName;
406  WCHAR szValue[LF_FACESIZE] = L"";
407  DWORD dwValue;
408  PTT_FONT_ENTRY FontEntry;
409  PWCHAR pszNext = NULL;
410  UINT CodePage;
411 
412  if (!IsListEmpty(&TTFontCache))
413  return;
414  // InitializeListHead(&TTFontCache);
415 
416  /* Open the key */
417  // "\\Registry\\Machine\\Software\\Microsoft\\Windows NT\\CurrentVersion\\Console\\TrueTypeFont"
419  L"Software\\Microsoft\\Windows NT\\CurrentVersion\\Console\\TrueTypeFont",
420  0,
421  KEY_READ,
422  &hKeyTTFonts) == ERROR_SUCCESS);
423  if (!Success)
424  return;
425 
426  /* Enumerate each value */
427  if (RegQueryInfoKeyW(hKeyTTFonts, NULL, NULL, NULL, NULL, NULL, NULL,
428  &dwNumValues, NULL, NULL, NULL, NULL) != ERROR_SUCCESS)
429  {
430  DPRINT("ConCfgReadUserSettings: RegQueryInfoKeyW failed\n");
431  RegCloseKey(hKeyTTFonts);
432  return;
433  }
434 
435  for (dwIndex = 0; dwIndex < dwNumValues; dwIndex++)
436  {
437  dwValue = sizeof(szValue);
438  dwValueName = ARRAYSIZE(szValueName);
439  if (RegEnumValueW(hKeyTTFonts, dwIndex, szValueName, &dwValueName, NULL, &dwType, (BYTE*)szValue, &dwValue) != ERROR_SUCCESS)
440  {
441  DPRINT1("InitTTFontCache: RegEnumValueW failed, continuing...\n");
442  continue;
443  }
444  /* Only (multi-)string values are supported */
445  if ((dwType != REG_SZ) && (dwType != REG_MULTI_SZ))
446  continue;
447 
448  /* The value name is a code page (in decimal), validate it */
449  CodePage = wcstoul(szValueName, &pszNext, 10);
450  if (*pszNext)
451  continue; // Non-numerical garbage followed...
452  // IsValidCodePage(CodePage);
453 
454  FontEntry = RtlAllocateHeap(RtlGetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(*FontEntry));
455  if (!FontEntry)
456  {
457  DPRINT1("InitTTFontCache: Failed to allocate memory, continuing...\n");
458  continue;
459  }
460 
461  FontEntry->CodePage = CodePage;
462 
463  pszNext = szValue;
464 
465  /* Check whether bold is disabled for this font */
466  if (*pszNext == L'*')
467  {
468  FontEntry->DisableBold = TRUE;
469  ++pszNext;
470  }
471  else
472  {
473  FontEntry->DisableBold = FALSE;
474  }
475 
476  /* Copy the font name */
477  StringCchCopyNW(FontEntry->FaceName, ARRAYSIZE(FontEntry->FaceName),
478  pszNext, wcslen(pszNext));
479 
480  if (dwType == REG_MULTI_SZ)
481  {
482  /* There may be an alternate face name as the second string */
483  pszNext += wcslen(pszNext) + 1;
484 
485  /* Check whether bold is disabled for this font */
486  if (*pszNext == L'*')
487  {
488  FontEntry->DisableBold = TRUE;
489  ++pszNext;
490  }
491  // else, keep the original setting.
492 
493  /* Copy the alternate font name */
494  StringCchCopyNW(FontEntry->FaceNameAlt, ARRAYSIZE(FontEntry->FaceNameAlt),
495  pszNext, wcslen(pszNext));
496  }
497 
498  InsertTailList(&TTFontCache, &FontEntry->Entry);
499  }
500 
501  /* Close the key and quit */
502  RegCloseKey(hKeyTTFonts);
503 }
STRSAFEAPI StringCchCopyNW(STRSAFE_LPWSTR pszDest, size_t cchDest, STRSAFE_LPCWSTR pszSrc, size_t cchToCopy)
Definition: strsafe.h:236
#define TRUE
Definition: types.h:120
#define LF_FACESIZE
Definition: dimm.idl:39
#define ERROR_SUCCESS
Definition: deptool.c:10
#define KEY_READ
Definition: nt_native.h:1023
#define ARRAYSIZE(array)
Definition: filtermapper.c:47
UINT CodePage
Definition: font.h:51
uint16_t * PWCHAR
Definition: typedefs.h:55
_Check_return_ unsigned long __cdecl wcstoul(_In_z_ const wchar_t *_Str, _Out_opt_ _Deref_post_z_ wchar_t **_EndPtr, _In_ int _Radix)
#define InsertTailList(ListHead, Entry)
_Must_inspect_result_ FORCEINLINE BOOLEAN IsListEmpty(_In_ const LIST_ENTRY *ListHead)
Definition: rtlfuncs.h:57
LIST_ENTRY TTFontCache
Definition: font.c:26
LONG WINAPI RegCloseKey(HKEY hKey)
Definition: reg.c:423
#define REG_MULTI_SZ
Definition: nt_native.h:1501
unsigned char BOOLEAN
LONG WINAPI RegEnumValueW(_In_ HKEY hKey, _In_ DWORD index, _Out_ LPWSTR value, _Inout_ PDWORD val_count, _Reserved_ PDWORD reserved, _Out_opt_ PDWORD type, _Out_opt_ LPBYTE data, _Inout_opt_ PDWORD count)
Definition: reg.c:2853
smooth NULL
Definition: ftsmooth.c:416
void DPRINT(...)
Definition: polytest.cpp:61
PVOID NTAPI RtlAllocateHeap(IN PVOID HeapHandle, IN ULONG Flags, IN SIZE_T Size)
Definition: heap.c:588
LIST_ENTRY Entry
Definition: font.h:50
__wchar_t WCHAR
Definition: xmlstorage.h:180
#define MAX_PATH
Definition: compat.h:26
unsigned long DWORD
Definition: ntddk_ex.h:95
LONG WINAPI RegQueryInfoKeyW(HKEY hKey, LPWSTR lpClass, LPDWORD lpcClass, LPDWORD lpReserved, LPDWORD lpcSubKeys, LPDWORD lpcMaxSubKeyLen, LPDWORD lpcMaxClassLen, LPDWORD lpcValues, LPDWORD lpcMaxValueNameLen, LPDWORD lpcMaxValueLen, LPDWORD lpcbSecurityDescriptor, PFILETIME lpftLastWriteTime)
Definition: reg.c:3686
static const WCHAR L[]
Definition: oid.c:1250
WCHAR FaceName[LF_FACESIZE]
Definition: font.h:53
unsigned char BYTE
Definition: mem.h:68
BOOL DisableBold
Definition: font.h:52
Definition: font.h:48
unsigned int UINT
Definition: ndis.h:50
#define HEAP_ZERO_MEMORY
Definition: compat.h:123
#define DPRINT1
Definition: precomp.h:8
WCHAR FaceNameAlt[LF_FACESIZE]
Definition: font.h:54
LONG WINAPI RegOpenKeyExW(HKEY hKey, LPCWSTR lpSubKey, DWORD ulOptions, REGSAM samDesired, PHKEY phkResult)
Definition: reg.c:3366
size_t __cdecl wcslen(_In_z_ const wchar_t *_Str)
#define HKEY_LOCAL_MACHINE
Definition: winreg.h:12
#define REG_SZ
Definition: layer.c:22

Referenced by GuiInit(), InitApplet(), and RefreshTTFontCache().

◆ IsValidConsoleFont()

BOOL IsValidConsoleFont ( IN LPCWSTR  FaceName,
IN UINT  CodePage 
)

Definition at line 364 of file font.c.

367 {
369  HDC hDC;
370  LOGFONTW lf;
371 
372  Param.IsValidFont = FALSE;
373  Param.CodePage = CodePage;
374 
375  RtlZeroMemory(&lf, sizeof(lf));
376  lf.lfCharSet = DEFAULT_CHARSET; // CodePageToCharSet(CodePage);
377  // lf.lfPitchAndFamily = FIXED_PITCH | FF_MODERN;
378  StringCchCopyW(lf.lfFaceName, ARRAYSIZE(lf.lfFaceName), FaceName);
379 
380  hDC = GetDC(NULL);
382  ReleaseDC(NULL, hDC);
383 
384  return Param.IsValidFont;
385 }
int WINAPI EnumFontFamiliesExW(HDC hdc, LPLOGFONTW lpLogfont, FONTENUMPROCW lpEnumFontFamExProc, LPARAM lParam, DWORD dwFlags)
Definition: font.c:400
HDC WINAPI GetDC(_In_opt_ HWND)
BYTE lfCharSet
Definition: dimm.idl:67
static HDC
Definition: imagelist.c:92
#define ARRAYSIZE(array)
Definition: filtermapper.c:47
#define DEFAULT_CHARSET
Definition: wingdi.h:383
STRSAFEAPI StringCchCopyW(STRSAFE_LPWSTR pszDest, size_t cchDest, STRSAFE_LPCWSTR pszSrc)
Definition: strsafe.h:149
int WINAPI ReleaseDC(_In_opt_ HWND, _In_ HDC)
smooth NULL
Definition: ftsmooth.c:416
static BOOL CALLBACK IsValidConsoleFontProc(IN PLOGFONTW lplf, IN PNEWTEXTMETRICW lpntm, IN DWORD FontType, IN LPARAM lParam)
Definition: font.c:350
LONG_PTR LPARAM
Definition: windef.h:208
static HDC hDC
Definition: 3dtext.c:33
FARPROC FONTENUMPROCW
Definition: wingdi.h:2896
WCHAR lfFaceName[LF_FACESIZE]
Definition: dimm.idl:72
#define RtlZeroMemory(Destination, Length)
Definition: typedefs.h:261

Referenced by CreateConsoleFontEx().

◆ IsValidConsoleFont2()

BOOL IsValidConsoleFont2 ( IN PLOGFONTW  lplf,
IN PNEWTEXTMETRICW  lpntm,
IN DWORD  FontType,
IN UINT  CodePage 
)

Definition at line 188 of file font.c.

193 {
194  LPCWSTR FaceName = lplf->lfFaceName;
195 
196  /*
197  * According to: https://web.archive.org/web/20140901124501/http://support.microsoft.com/kb/247815
198  * "Necessary criteria for fonts to be available in a command window",
199  * the criteria for console-eligible fonts are as follows:
200  * - The font must be a fixed-pitch font.
201  * - The font cannot be an italic font.
202  * - The font cannot have a negative A or C space.
203  * - If it is a TrueType font, it must be FF_MODERN.
204  * - If it is not a TrueType font, it must be OEM_CHARSET.
205  *
206  * Non documented: vertical fonts are forbidden (their name start with a '@').
207  *
208  * Additional criteria for Asian installations:
209  * - If it is not a TrueType font, the face name must be "Terminal".
210  * - If it is an Asian TrueType font, it must also be an Asian character set.
211  *
212  * See also Raymond Chen's blog: https://devblogs.microsoft.com/oldnewthing/?p=26843
213  * and MIT-licensed Microsoft Terminal source code: https://github.com/microsoft/Terminal/blob/master/src/propsheet/misc.cpp
214  * for other details.
215  *
216  * To install additional TrueType fonts to be available for the console,
217  * add entries of type REG_SZ named "0", "00" etc... in:
218  * HKEY_LOCAL_MACHINE\Software\Microsoft\Windows NT\CurrentVersion\Console\TrueTypeFont
219  * The names of the fonts listed there should match those in:
220  * HKEY_LOCAL_MACHINE\Software\Microsoft\Windows NT\CurrentVersion\Fonts
221  */
222 
223  /*
224  * In ReactOS we relax some of the criteria:
225  * - We allow fixed-pitch FF_MODERN (Monospace) TrueType fonts
226  * that can be italic or have negative A or C space.
227  * - If it is not a TrueType font, it can be from another character set
228  * than OEM_CHARSET. When an Asian codepage is active however, we require
229  * that this non-TrueType font has an Asian character set.
230  */
231 
232  /* Reject variable-width fonts ... */
233  if ( ( ((lplf->lfPitchAndFamily & 0x03) != FIXED_PITCH)
234 #if 0 /* Reject italic and TrueType fonts with negative A or C space ... */
235  || (lplf->lfItalic)
236  || !(lpntm->ntmFlags & NTM_NONNEGATIVE_AC)
237 #endif
238  ) &&
239  /* ... if they are not in the list of additional TrueType fonts to include */
240  !IsAdditionalTTFont(FaceName) )
241  {
242  DPRINT1("Font '%S' rejected because it%s (lfPitchAndFamily = %d)\n",
243  FaceName,
244  !(lplf->lfPitchAndFamily & FIXED_PITCH) ? "'s not FIXED_PITCH"
245  : (!(lpntm->ntmFlags & NTM_NONNEGATIVE_AC) ? " has negative A or C space"
246  : " is broken"),
247  lplf->lfPitchAndFamily);
248  return FALSE;
249  }
250 
251  /* Reject TrueType fonts that are not FF_MODERN */
252  if ((FontType == TRUETYPE_FONTTYPE) && ((lplf->lfPitchAndFamily & 0xF0) != FF_MODERN))
253  {
254  DPRINT1("TrueType font '%S' rejected because it's not FF_MODERN (lfPitchAndFamily = %d)\n",
255  FaceName, lplf->lfPitchAndFamily);
256  return FALSE;
257  }
258 
259  /* Reject vertical fonts (tategaki) */
260  if (FaceName[0] == L'@')
261  {
262  DPRINT1("Font '%S' rejected because it's vertical\n", FaceName);
263  return FALSE;
264  }
265 
266  /* Is the current code page Chinese, Japanese or Korean? */
267  if (IsCJKCodePage(CodePage))
268  {
269  /* It's CJK */
270 
271  if (FontType == TRUETYPE_FONTTYPE)
272  {
273  /*
274  * Here we are inclusive and check for any CJK character set,
275  * instead of looking just at the current one via CodePageToCharSet().
276  */
277  if (!IsCJKCharSet(lplf->lfCharSet)
278 #if 1 // FIXME: Temporary HACK!
279  && wcscmp(FaceName, L"Terminal") != 0
280 #endif
281  )
282  {
283  DPRINT1("TrueType font '%S' rejected because it's not Asian charset (lfCharSet = %d)\n",
284  FaceName, lplf->lfCharSet);
285  return FALSE;
286  }
287 
288  /*
289  * If this is a cached TrueType font that is used only for certain
290  * code pages, verify that the charset it claims is the correct one.
291  *
292  * Since there may be multiple entries for a cached TrueType font,
293  * a general one (code page == 0) and one or more for explicit
294  * code pages, we need to perform two search queries instead of
295  * just one and retrieving the code page for this entry.
296  */
297  if (IsAdditionalTTFont(FaceName) && !IsAdditionalTTFontCP(FaceName, 0) &&
298  !IsCJKCharSet(lplf->lfCharSet))
299  {
300  DPRINT1("Cached TrueType font '%S' rejected because it claims a code page that is not Asian charset (lfCharSet = %d)\n",
301  FaceName, lplf->lfCharSet);
302  return FALSE;
303  }
304  }
305  else
306  {
307  /* Reject non-TrueType fonts that do not have an Asian character set */
308  if (!IsCJKCharSet(lplf->lfCharSet) && (lplf->lfCharSet != OEM_CHARSET))
309  {
310  DPRINT1("Non-TrueType font '%S' rejected because it's not Asian charset or OEM_CHARSET (lfCharSet = %d)\n",
311  FaceName, lplf->lfCharSet);
312  return FALSE;
313  }
314 
315  /* Reject non-TrueType fonts that are not Terminal */
316  if (wcscmp(FaceName, L"Terminal") != 0)
317  {
318  DPRINT1("Non-TrueType font '%S' rejected because it's not 'Terminal'\n", FaceName);
319  return FALSE;
320  }
321  }
322  }
323  else
324  {
325  /* Not CJK */
326 
327  /* Reject non-TrueType fonts that are not OEM or similar */
328  if ((FontType != TRUETYPE_FONTTYPE) &&
329  (lplf->lfCharSet != ANSI_CHARSET) &&
330  (lplf->lfCharSet != DEFAULT_CHARSET) &&
331  (lplf->lfCharSet != OEM_CHARSET))
332  {
333  DPRINT1("Non-TrueType font '%S' rejected because it's not ANSI_CHARSET or DEFAULT_CHARSET or OEM_CHARSET (lfCharSet = %d)\n",
334  FaceName, lplf->lfCharSet);
335  return FALSE;
336  }
337  }
338 
339  /* All good */
340  return TRUE;
341 }
#define TRUE
Definition: types.h:120
#define IsCJKCharSet(CharSet)
Definition: font.h:40
#define NTM_NONNEGATIVE_AC
Definition: wingdi.h:25
const WCHAR * LPCWSTR
Definition: xmlstorage.h:185
#define DEFAULT_CHARSET
Definition: wingdi.h:383
#define IsAdditionalTTFont(FaceName)
Definition: font.h:125
#define IsCJKCodePage(CodePage)
Definition: font.h:23
#define FIXED_PITCH
Definition: wingdi.h:443
#define OEM_CHARSET
Definition: wingdi.h:399
static const WCHAR L[]
Definition: oid.c:1250
_Check_return_ _CRTIMP int __cdecl wcscmp(_In_z_ const wchar_t *_Str1, _In_z_ const wchar_t *_Str2)
#define FF_MODERN
Definition: wingdi.h:448
#define DPRINT1
Definition: precomp.h:8
#define ANSI_CHARSET
Definition: wingdi.h:382
#define TRUETYPE_FONTTYPE
Definition: wingdi.h:1108
#define IsAdditionalTTFontCP(FaceName, CodePage)
Definition: font.h:128

Referenced by EnumFaceNamesProc(), and IsValidConsoleFontProc().

◆ RefreshTTFontCache()

VOID RefreshTTFontCache ( VOID  )

Definition at line 521 of file font.c.

522 {
524  InitTTFontCache();
525 }
VOID InitTTFontCache(VOID)
Definition: font.c:397
VOID ClearTTFontCache(VOID)
Definition: font.c:506

Referenced by GuiApplyUserSettings().