ReactOS  0.4.15-dev-4863-gba0d16f
font.h
Go to the documentation of this file.
1 /*
2  * PROJECT: ReactOS Console Server DLL
3  * LICENSE: GPL-2.0-or-later (https://spdx.org/licenses/GPL-2.0-or-later)
4  * PURPOSE: Console GDI Fonts Management.
5  * COPYRIGHT: Copyright 2017-2022 Hermès Bélusca-Maïto
6  * Copyright 2017 Katayama Hirofumi MZ (katayama.hirofumi.mz@gmail.com)
7  */
8 
9 #pragma once
10 
11 /* DEFINES ********************************************************************/
12 
13 #define INVALID_CP ((UINT)-1)
14 
15 #ifndef CP_UTF8
16 #define CP_UTF8 65001
17 #endif
18 
19 #define CP_USA 437 // United States (OEM)
20 
21 #define CP_SHIFTJIS 932 // Japanese Shift-JIS
22 #define CP_HANGUL 949 // Korean Hangul/Wansung
23 #define CP_JOHAB 1361 // Korean Johab
24 #define CP_GB2312 936 // Chinese Simplified (GB2312)
25 #define CP_BIG5 950 // Chinese Traditional (Big5)
26 
27 /*
28  * "Human-understandable" names for the previous standard code pages.
29  * Taken from https://github.com/microsoft/terminal/blob/main/src/inc/unicode.hpp
30  */
31 #define CP_JAPANESE CP_SHIFTJIS
32 #define CP_KOREAN CP_HANGUL
33 #define CP_CHINESE_SIMPLIFIED CP_GB2312
34 #define CP_CHINESE_TRADITIONAL CP_BIG5
35 
36 /* IsFarEastCP(CodePage) */
37 #define IsCJKCodePage(CodePage) \
38  ((CodePage) == CP_SHIFTJIS || (CodePage) == CP_HANGUL || \
39  /* (CodePage) == CP_JOHAB || */ \
40  (CodePage) == CP_BIG5 || (CodePage) == CP_GB2312)
41 
42 #if !defined(_WINGDI_) || defined(NOGDI)
43 #define SHIFTJIS_CHARSET 128
44 #define HANGEUL_CHARSET 129
45 #define HANGUL_CHARSET 129 // HANGEUL_CHARSET
46 #if(WINVER >= 0x0400)
47 #define JOHAB_CHARSET 130
48 #endif /* WINVER */
49 #define GB2312_CHARSET 134
50 #define CHINESEBIG5_CHARSET 136
51 #endif /* !defined(_WINGDI_) || defined(NOGDI) */
52 
53 /* IsAnyDBCSCharSet(CharSet) */
54 #define IsCJKCharSet(CharSet) \
55  ((CharSet) == SHIFTJIS_CHARSET || (CharSet) == HANGUL_CHARSET || \
56  /* (CharSet) == JOHAB_CHARSET || */ \
57  (CharSet) == GB2312_CHARSET || (CharSet) == CHINESEBIG5_CHARSET)
58 
59 #define IsBoldFont(Weight) \
60  ((Weight) >= FW_SEMIBOLD) /* Sometimes, just > FW_MEDIUM */
61 
62 
63 /*
64  * @struct TrueType font list, cached from
65  * HKEY_LOCAL_MACHINE\Software\Microsoft\Windows NT\CurrentVersion\Console\TrueTypeFont
66  *
67  * See the definition of struct _TT_FONT_LIST
68  * in https://github.com/microsoft/terminal/blob/main/dep/Console/winconp.h
69  */
70 #define BOLD_MARK L'*'
71 
72 typedef struct _TT_FONT_ENTRY
73 {
80 
81 
82 /* FUNCTIONS ******************************************************************/
83 
84 BYTE
86  _In_ UINT CodePage);
87 
88 // FIXME: Will be redefined once we support a font cache.
89 typedef struct _FONT_DATA
90 {
97 
98 HFONT
100  _In_ LONG Height,
103  PWSTR FaceName,
104  _In_ ULONG FontWeight,
106  _In_ UINT CodePage,
107  _In_ BOOL UseDefaultFallback,
108  _Out_ PFONT_DATA FontData);
109 
110 HFONT
112  _In_ LONG Height,
115 
116 HFONT
119 
120 _Success_(return)
121 BOOL
122 GetFontCellSize(
123  _In_opt_ HDC hDC,
126  _Out_ PUINT Width);
127 
128 BOOL
130  _In_ PLOGFONTW lplf,
131  _In_ PNEWTEXTMETRICW lpntm,
132  _In_ DWORD FontType,
133  _In_ UINT CodePage);
134 
135 BOOL
137  // _In_reads_or_z_(LF_FACESIZE)
138  _In_ PCWSTR FaceName,
139  _In_ UINT CodePage);
140 
141 
142 VOID
144 
145 VOID
147 
148 VOID
150 
154  PCWSTR FaceName,
155  _In_ UINT CodePage);
156 
168 #define IsAdditionalTTFont(FaceName) \
169  (FindCachedTTFont((FaceName), INVALID_CP) != NULL)
170 
171 #define IsAdditionalTTFontCP(FaceName, CodePage) \
172  (FindCachedTTFont((FaceName), (CodePage)) != NULL)
173 
174 /* EOF */
_Inout_updates_z_(LF_FACESIZE) PWSTR FaceName
_In_ HFONT hFont
Definition: font.h:124
const uint16_t * PCWSTR
Definition: typedefs.h:57
#define LF_FACESIZE
Definition: dimm.idl:39
#define _In_opt_
Definition: ms_sal.h:309
#define _Inout_
Definition: ms_sal.h:378
struct _FONT_DATA * PFONT_DATA
Definition: ntbasedef.h:628
#define _Out_
Definition: ms_sal.h:345
uint16_t * PWSTR
Definition: typedefs.h:56
_In_ HFONT _Out_ PUINT _Out_ PUINT Width
Definition: font.h:124
static HDC
Definition: imagelist.c:92
VOID InitTTFontCache(VOID)
Initializes the console TrueType font cache.
Definition: font.c:1013
UINT CodePage
Definition: font.h:75
_In_ HFONT _Out_ PUINT Height
Definition: font.h:124
PTT_FONT_ENTRY FindCachedTTFont(_In_reads_or_z_opt_(LF_FACESIZE) PCWSTR FaceName, _In_ UINT CodePage)
Searches for a font in the console TrueType font cache, with the specified code page.
Definition: font.c:1183
unsigned int BOOL
Definition: ntddk_ex.h:94
long LONG
Definition: pedump.c:60
ULONG Family
Definition: font.h:93
BYTE CodePageToCharSet(_In_ UINT CodePage)
Retrieves the character set associated with a given code page.
Definition: font.c:51
COORD Size
Definition: font.h:94
#define _In_
Definition: ms_sal.h:308
VOID ClearTTFontCache(VOID)
Clears the console TrueType font cache.
Definition: font.c:1131
__wchar_t WCHAR
Definition: xmlstorage.h:180
unsigned long DWORD
Definition: ntddk_ex.h:95
#define _In_reads_or_z_opt_(size)
Definition: ms_sal.h:326
struct _TT_FONT_ENTRY TT_FONT_ENTRY
BOOL IsValidConsoleFont(_In_ PCWSTR FaceName, _In_ UINT CodePage)
Validates whether a given font can be supported in the console, under the specified code page.
Definition: font.c:974
WCHAR FaceName[LF_FACESIZE]
Definition: font.h:77
ULONG Weight
Definition: font.h:92
Definition: bl.h:1337
unsigned char BYTE
Definition: xxhash.c:193
BOOL DisableBold
Definition: font.h:76
VOID RefreshTTFontCache(VOID)
Refreshes the console TrueType font cache, by clearing and re-initializing it.
Definition: font.c:1153
SINGLE_LIST_ENTRY Entry
Definition: font.h:74
static HDC hDC
Definition: 3dtext.c:33
struct _FONT_DATA FONT_DATA
HFONT CreateConsoleFontEx(_In_ LONG Height, _In_opt_ LONG Width, _Inout_updates_z_(LF_FACESIZE) PWSTR FaceName, _In_ ULONG FontWeight, _In_ ULONG FontFamily, _In_ UINT CodePage, _In_ BOOL UseDefaultFallback, _Out_ PFONT_DATA FontData)
Validates and creates a suitable console font based on the font characteristics given in input.
Definition: font.c:505
Definition: font.h:72
struct _TT_FONT_ENTRY * PTT_FONT_ENTRY
static CONSOLE_SCREEN_BUFFER_INFO ConsoleInfo
Definition: video.c:47
#define _Inout_updates_z_(size)
Definition: ms_sal.h:389
unsigned int UINT
Definition: ndis.h:50
static DWORD *static HFONT(WINAPI *pCreateFontIndirectExA)(const ENUMLOGFONTEXDVA *)
_Success_(return) BOOL GetFontCellSize(_In_opt_ HDC hDC
WCHAR FaceNameAlt[LF_FACESIZE]
Definition: font.h:78
HFONT CreateConsoleFont(_Inout_ PCONSOLE_STATE_INFO ConsoleInfo)
A wrapper for CreateConsoleFontEx().
Definition: font.c:653
unsigned int ULONG
Definition: retypes.h:1
BYTE CharSet
Definition: font.h:95
HFONT CreateConsoleFont2(_In_ LONG Height, _In_opt_ LONG Width, _Inout_ PCONSOLE_STATE_INFO ConsoleInfo)
A wrapper for CreateConsoleFontEx().
Definition: font.c:609
unsigned int * PUINT
Definition: ndis.h:50
BOOL IsValidConsoleFont2(_In_ PLOGFONTW lplf, _In_ PNEWTEXTMETRICW lpntm, _In_ DWORD FontType, _In_ UINT CodePage)
Validates whether a given font can be supported in the console, under the specified code page.
Definition: font.c:782