ReactOS  0.4.13-dev-482-ge57f103
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 500 of file font.c.

501 {
503  PTT_FONT_ENTRY FontEntry;
504 
505  while (!IsListEmpty(&TTFontCache))
506  {
509  RtlFreeHeap(RtlGetProcessHeap(), 0, FontEntry);
510  }
512 }
struct _Entry Entry
Definition: kefuncs.h:640
BOOLEAN NTAPI RtlFreeHeap(IN PVOID HeapHandle, IN ULONG Flags, IN PVOID HeapBase)
Definition: heap.c:603
_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:117
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:1524
#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 95 of file font.c.

97 {
98  /*
99  * Format:
100  * Width = FontSize.X = LOWORD(FontSize);
101  * Height = FontSize.Y = HIWORD(FontSize);
102  */
103  /* NOTE: FontSize is always in cell height/width units (pixels) */
104  return CreateConsoleFontEx((LONG)(ULONG)ConsoleInfo->FontSize.Y,
105  (LONG)(ULONG)ConsoleInfo->FontSize.X,
106  ConsoleInfo->FaceName,
107  ConsoleInfo->FontFamily,
108  ConsoleInfo->FontWeight,
109  ConsoleInfo->CodePage);
110 }
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 81 of file font.c.

85 {
86  return CreateConsoleFontEx(Height,
87  Width,
88  ConsoleInfo->FaceName,
89  ConsoleInfo->FontFamily,
90  ConsoleInfo->FontWeight,
91  ConsoleInfo->CodePage);
92 }
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  StringCchCopyW(FaceName, LF_FACESIZE, L"Terminal");
73 
75  FaceName, LF_FACESIZE);
76 
77  return CreateFontIndirectW(&lf);
78 }
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 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
BOOL IsValidConsoleFont(IN LPCWSTR FaceName, IN UINT CodePage)
Definition: font.c:358

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

◆ FindCachedTTFont()

PTT_FONT_ENTRY FindCachedTTFont ( IN LPCWSTR  FaceName,
IN UINT  CodePage 
)

Definition at line 522 of file font.c.

525 {
527  PTT_FONT_ENTRY FontEntry;
528 
529  /* Search for the font in the cache */
530  for (Entry = TTFontCache.Flink;
531  Entry != &TTFontCache;
532  Entry = Entry->Flink)
533  {
535 
536  /* NOTE: The font face names are case-sensitive */
537  if ((wcscmp(FontEntry->FaceName , FaceName) == 0) ||
538  (wcscmp(FontEntry->FaceNameAlt, FaceName) == 0))
539  {
540  /* Return a match if we don't look at the code pages, or when they match */
541  if ((CodePage == INVALID_CP) || (CodePage == FontEntry->CodePage))
542  {
543  return FontEntry;
544  }
545  }
546  }
547  return NULL;
548 }
struct _Entry Entry
Definition: kefuncs.h:640
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:119
#define INVALID_CP
Definition: stream.h:53
WCHAR FaceName[LF_FACESIZE]
Definition: font.h:53
Definition: typedefs.h:117
_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 113 of file font.c.

118 {
119  BOOL Success = FALSE;
120  HDC hOrgDC = hDC;
121  HFONT hOldFont;
122  // LONG LogSize, PointSize;
124  TEXTMETRICW tm;
125  // SIZE CharSize;
126 
127  if (!hDC)
128  hDC = GetDC(NULL);
129 
130  hOldFont = SelectObject(hDC, hFont);
131  if (hOldFont == NULL)
132  {
133  DPRINT1("GetFontCellSize: SelectObject failed\n");
134  goto Quit;
135  }
136 
137 /*
138  * See also: Display_SetTypeFace in applications/fontview/display.c
139  */
140 
141  /*
142  * Note that the method with GetObjectW just returns
143  * the original parameters with which the font was created.
144  */
145  if (!GetTextMetricsW(hDC, &tm))
146  {
147  DPRINT1("GetFontCellSize: GetTextMetrics failed\n");
148  goto Cleanup;
149  }
150 
151  CharHeight = tm.tmHeight + tm.tmExternalLeading;
152 
153 #if 0
154  /* Measure real char width more precisely if possible */
155  if (GetTextExtentPoint32W(hDC, L"R", 1, &CharSize))
156  CharWidth = CharSize.cx;
157 #else
158  CharWidth = tm.tmAveCharWidth; // tm.tmMaxCharWidth;
159 #endif
160 
161 #if 0
162  /*** Logical to Point size ***/
163  LogSize = tm.tmHeight - tm.tmInternalLeading;
164  PointSize = MulDiv(LogSize, 72, GetDeviceCaps(hDC, LOGPIXELSY));
165  /*****************************/
166 #endif
167 
168  *Height = (UINT)CharHeight;
169  *Width = (UINT)CharWidth;
170  Success = TRUE;
171 
172 Cleanup:
173  SelectObject(hDC, hOldFont);
174 Quit:
175  if (!hOrgDC)
176  ReleaseDC(NULL, hDC);
177 
178  return Success;
179 }
#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 391 of file font.c.

392 {
394  HKEY hKeyTTFonts; // hKey;
395  DWORD dwNumValues = 0;
396  DWORD dwIndex;
397  DWORD dwType;
398  WCHAR szValueName[MAX_PATH];
399  DWORD dwValueName;
400  WCHAR szValue[LF_FACESIZE] = L"";
401  DWORD dwValue;
402  PTT_FONT_ENTRY FontEntry;
403  PWCHAR pszNext = NULL;
404  UINT CodePage;
405 
406  if (!IsListEmpty(&TTFontCache))
407  return;
408  // InitializeListHead(&TTFontCache);
409 
410  /* Open the key */
411  // "\\Registry\\Machine\\Software\\Microsoft\\Windows NT\\CurrentVersion\\Console\\TrueTypeFont"
413  L"Software\\Microsoft\\Windows NT\\CurrentVersion\\Console\\TrueTypeFont",
414  0,
415  KEY_READ,
416  &hKeyTTFonts) == ERROR_SUCCESS);
417  if (!Success)
418  return;
419 
420  /* Enumerate each value */
421  if (RegQueryInfoKeyW(hKeyTTFonts, NULL, NULL, NULL, NULL, NULL, NULL,
422  &dwNumValues, NULL, NULL, NULL, NULL) != ERROR_SUCCESS)
423  {
424  DPRINT("ConCfgReadUserSettings: RegQueryInfoKeyW failed\n");
425  RegCloseKey(hKeyTTFonts);
426  return;
427  }
428 
429  for (dwIndex = 0; dwIndex < dwNumValues; dwIndex++)
430  {
431  dwValue = sizeof(szValue);
432  dwValueName = ARRAYSIZE(szValueName);
433  if (RegEnumValueW(hKeyTTFonts, dwIndex, szValueName, &dwValueName, NULL, &dwType, (BYTE*)szValue, &dwValue) != ERROR_SUCCESS)
434  {
435  DPRINT1("InitTTFontCache: RegEnumValueW failed, continuing...\n");
436  continue;
437  }
438  /* Only (multi-)string values are supported */
439  if ((dwType != REG_SZ) && (dwType != REG_MULTI_SZ))
440  continue;
441 
442  /* The value name is a code page (in decimal), validate it */
443  CodePage = wcstoul(szValueName, &pszNext, 10);
444  if (*pszNext)
445  continue; // Non-numerical garbage followed...
446  // IsValidCodePage(CodePage);
447 
448  FontEntry = RtlAllocateHeap(RtlGetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(*FontEntry));
449  if (!FontEntry)
450  {
451  DPRINT1("InitTTFontCache: Failed to allocate memory, continuing...\n");
452  continue;
453  }
454 
455  FontEntry->CodePage = CodePage;
456 
457  pszNext = szValue;
458 
459  /* Check whether bold is disabled for this font */
460  if (*pszNext == L'*')
461  {
462  FontEntry->DisableBold = TRUE;
463  ++pszNext;
464  }
465  else
466  {
467  FontEntry->DisableBold = FALSE;
468  }
469 
470  /* Copy the font name */
471  StringCchCopyNW(FontEntry->FaceName, ARRAYSIZE(FontEntry->FaceName),
472  pszNext, wcslen(pszNext));
473 
474  if (dwType == REG_MULTI_SZ)
475  {
476  /* There may be an alternate face name as the second string */
477  pszNext += wcslen(pszNext) + 1;
478 
479  /* Check whether bold is disabled for this font */
480  if (*pszNext == L'*')
481  {
482  FontEntry->DisableBold = TRUE;
483  ++pszNext;
484  }
485  // else, keep the original setting.
486 
487  /* Copy the alternate font name */
488  StringCchCopyNW(FontEntry->FaceNameAlt, ARRAYSIZE(FontEntry->FaceNameAlt),
489  pszNext, wcslen(pszNext));
490  }
491 
492  InsertTailList(&TTFontCache, &FontEntry->Entry);
493  }
494 
495  /* Close the key and quit */
496  RegCloseKey(hKeyTTFonts);
497 }
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:54
_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:585
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 358 of file font.c.

361 {
363  HDC hDC;
364  LOGFONTW lf;
365 
366  Param.IsValidFont = FALSE;
367  Param.CodePage = CodePage;
368 
369  RtlZeroMemory(&lf, sizeof(lf));
370  lf.lfCharSet = DEFAULT_CHARSET; // CodePageToCharSet(CodePage);
371  // lf.lfPitchAndFamily = FIXED_PITCH | FF_MODERN;
372  StringCchCopyW(lf.lfFaceName, ARRAYSIZE(lf.lfFaceName), FaceName);
373 
374  hDC = GetDC(NULL);
376  ReleaseDC(NULL, hDC);
377 
378  return Param.IsValidFont;
379 }
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:344
LONG_PTR LPARAM
Definition: windef.h:208
static HDC hDC
Definition: 3dtext.c:33
FARPROC FONTENUMPROCW
Definition: wingdi.h:2875
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 182 of file font.c.

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

Referenced by EnumFaceNamesProc(), and IsValidConsoleFontProc().

◆ RefreshTTFontCache()

VOID RefreshTTFontCache ( VOID  )

Definition at line 515 of file font.c.

516 {
518  InitTTFontCache();
519 }
VOID InitTTFontCache(VOID)
Definition: font.c:391
VOID ClearTTFontCache(VOID)
Definition: font.c:500

Referenced by GuiApplyUserSettings().