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 { 74 SINGLE_LIST_ENTRY Entry; 75 UINT CodePage; 76 BOOL DisableBold; 77 WCHAR FaceName[LF_FACESIZE]; 78 WCHAR FaceNameAlt[LF_FACESIZE]; 79 } TT_FONT_ENTRY, *PTT_FONT_ENTRY; 80 81 82 /* FUNCTIONS ******************************************************************/ 83 84 BYTE 85 CodePageToCharSet( 86 _In_ UINT CodePage); 87 88 // FIXME: Will be redefined once we support a font cache. 89 typedef struct _FONT_DATA 90 { 91 _Inout_updates_z_(LF_FACESIZE) PWSTR FaceName; 92 ULONG Weight; 93 ULONG Family; 94 COORD Size; 95 BYTE CharSet; 96 } FONT_DATA, *PFONT_DATA; 97 98 HFONT 99 CreateConsoleFontEx( 100 _In_ LONG Height, 101 _In_opt_ LONG Width, 102 _Inout_updates_z_(LF_FACESIZE) 103 PWSTR FaceName, 104 _In_ ULONG FontWeight, 105 _In_ ULONG FontFamily, 106 _In_ UINT CodePage, 107 _In_ BOOL UseDefaultFallback, 108 _Out_ PFONT_DATA FontData); 109 110 HFONT 111 CreateConsoleFont2( 112 _In_ LONG Height, 113 _In_opt_ LONG Width, 114 _Inout_ PCONSOLE_STATE_INFO ConsoleInfo); 115 116 HFONT 117 CreateConsoleFont( 118 _Inout_ PCONSOLE_STATE_INFO ConsoleInfo); 119 120 _Success_(return) 121 BOOL 122 GetFontCellSize( 123 _In_opt_ HDC hDC, 124 _In_ HFONT hFont, 125 _Out_ PUINT Height, 126 _Out_ PUINT Width); 127 128 BOOL 129 IsValidConsoleFont2( 130 _In_ PLOGFONTW lplf, 131 _In_ PNEWTEXTMETRICW lpntm, 132 _In_ DWORD FontType, 133 _In_ UINT CodePage); 134 135 BOOL 136 IsValidConsoleFont( 137 // _In_reads_or_z_(LF_FACESIZE) 138 _In_ PCWSTR FaceName, 139 _In_ UINT CodePage); 140 141 142 VOID 143 InitTTFontCache(VOID); 144 145 VOID 146 ClearTTFontCache(VOID); 147 148 VOID 149 RefreshTTFontCache(VOID); 150 151 PTT_FONT_ENTRY 152 FindCachedTTFont( 153 _In_reads_or_z_opt_(LF_FACESIZE) 154 PCWSTR FaceName, 155 _In_ UINT CodePage); 156 157 /** 158 * @brief 159 * Verifies whether the given font is an additional console TrueType font. 160 * Wrapper macros around FindCachedTTFont(). 161 * 162 * @remark 163 * These macros are equivalents of the functions 164 * IsAvailableTTFont() and IsAvailableTTFontCP() in 165 * https://github.com/microsoft/terminal/blob/main/src/propsheet/dbcs.cpp 166 **/ 167 168 #define IsAdditionalTTFont(FaceName) \ 169 (FindCachedTTFont((FaceName), INVALID_CP) != NULL) 170 171 #define IsAdditionalTTFontCP(FaceName, CodePage) \ 172 (FindCachedTTFont((FaceName), (CodePage)) != NULL) 173 174 /* EOF */ 175