xref: /reactos/win32ss/user/winsrv/concfg/font.h (revision 5140a990)
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 #include <cjkcode.h>
22 
23 #define IsBoldFont(Weight)  \
24     ((Weight) >= FW_SEMIBOLD) /* Sometimes, just > FW_MEDIUM */
25 
26 /*
27  * @struct  TrueType font list, cached from
28  * HKEY_LOCAL_MACHINE\Software\Microsoft\Windows NT\CurrentVersion\Console\TrueTypeFont
29  *
30  * See the definition of struct _TT_FONT_LIST
31  * in https://github.com/microsoft/terminal/blob/main/dep/Console/winconp.h
32  */
33 #define BOLD_MARK   L'*'
34 
35 typedef struct _TT_FONT_ENTRY
36 {
37     SINGLE_LIST_ENTRY Entry;
38     UINT CodePage;
39     BOOL DisableBold;
40     WCHAR FaceName[LF_FACESIZE];
41     WCHAR FaceNameAlt[LF_FACESIZE];
42 } TT_FONT_ENTRY, *PTT_FONT_ENTRY;
43 
44 
45 /* FUNCTIONS ******************************************************************/
46 
47 BYTE
48 CodePageToCharSet(
49     _In_ UINT CodePage);
50 
51 // FIXME: Will be redefined once we support a font cache.
52 typedef struct _FONT_DATA
53 {
54     _Inout_updates_z_(LF_FACESIZE) PWSTR FaceName;
55     ULONG Weight;
56     ULONG Family;
57     COORD Size;
58     BYTE  CharSet;
59 } FONT_DATA, *PFONT_DATA;
60 
61 HFONT
62 CreateConsoleFontEx(
63     _In_     LONG Height,
64     _In_opt_ LONG Width,
65     _Inout_updates_z_(LF_FACESIZE)
66          PWSTR FaceName,
67     _In_ ULONG FontWeight,
68     _In_ ULONG FontFamily,
69     _In_ UINT  CodePage,
70     _In_ BOOL  UseDefaultFallback,
71     _Out_ PFONT_DATA FontData);
72 
73 HFONT
74 CreateConsoleFont2(
75     _In_     LONG Height,
76     _In_opt_ LONG Width,
77     _Inout_  PCONSOLE_STATE_INFO ConsoleInfo);
78 
79 HFONT
80 CreateConsoleFont(
81     _Inout_ PCONSOLE_STATE_INFO ConsoleInfo);
82 
83 _Success_(return)
84 BOOL
85 GetFontCellSize(
86     _In_opt_ HDC hDC,
87     _In_  HFONT hFont,
88     _Out_ PUINT Height,
89     _Out_ PUINT Width);
90 
91 BOOL
92 IsValidConsoleFont2(
93     _In_ PLOGFONTW lplf,
94     _In_ PNEWTEXTMETRICW lpntm,
95     _In_ DWORD FontType,
96     _In_ UINT  CodePage);
97 
98 BOOL
99 IsValidConsoleFont(
100     // _In_reads_or_z_(LF_FACESIZE)
101     _In_ PCWSTR FaceName,
102     _In_ UINT CodePage);
103 
104 
105 VOID
106 InitTTFontCache(VOID);
107 
108 VOID
109 ClearTTFontCache(VOID);
110 
111 VOID
112 RefreshTTFontCache(VOID);
113 
114 PTT_FONT_ENTRY
115 FindCachedTTFont(
116     _In_reads_or_z_opt_(LF_FACESIZE)
117          PCWSTR FaceName,
118     _In_ UINT CodePage);
119 
120 /**
121  * @brief
122  * Verifies whether the given font is an additional console TrueType font.
123  * Wrapper macros around FindCachedTTFont().
124  *
125  * @remark
126  * These macros are equivalents of the functions
127  * IsAvailableTTFont() and IsAvailableTTFontCP() in
128  * https://github.com/microsoft/terminal/blob/main/src/propsheet/dbcs.cpp
129  **/
130 
131 #define IsAdditionalTTFont(FaceName) \
132     (FindCachedTTFont((FaceName), INVALID_CP) != NULL)
133 
134 #define IsAdditionalTTFontCP(FaceName, CodePage) \
135     (FindCachedTTFont((FaceName), (CodePage)) != NULL)
136 
137 /* EOF */
138