2017-05-03 19:47:18 +00:00
|
|
|
/*
|
2022-01-29 19:04:16 +00:00
|
|
|
* PROJECT: ReactOS Console Server DLL
|
|
|
|
* LICENSE: GPL-2.0-or-later (https://spdx.org/licenses/GPL-2.0-or-later)
|
|
|
|
* PURPOSE: Console GDI Fonts Management.
|
|
|
|
* COPYRIGHT: Copyright 2017-2022 Hermès Bélusca-Maïto
|
|
|
|
* Copyright 2017 Katayama Hirofumi MZ (katayama.hirofumi.mz@gmail.com)
|
2017-05-03 19:47:18 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
#pragma once
|
|
|
|
|
|
|
|
/* DEFINES ********************************************************************/
|
|
|
|
|
2019-05-19 20:55:14 +00:00
|
|
|
#define INVALID_CP ((UINT)-1)
|
|
|
|
|
2022-01-29 19:04:16 +00:00
|
|
|
#ifndef CP_UTF8
|
|
|
|
#define CP_UTF8 65001
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#define CP_USA 437 // United States (OEM)
|
|
|
|
|
2019-05-19 20:55:14 +00:00
|
|
|
#define CP_SHIFTJIS 932 // Japanese Shift-JIS
|
|
|
|
#define CP_HANGUL 949 // Korean Hangul/Wansung
|
|
|
|
#define CP_JOHAB 1361 // Korean Johab
|
|
|
|
#define CP_GB2312 936 // Chinese Simplified (GB2312)
|
|
|
|
#define CP_BIG5 950 // Chinese Traditional (Big5)
|
2017-05-03 19:47:18 +00:00
|
|
|
|
2022-01-14 21:00:55 +00:00
|
|
|
/*
|
|
|
|
* "Human-understandable" names for the previous standard code pages.
|
|
|
|
* Taken from https://github.com/microsoft/terminal/blob/main/src/inc/unicode.hpp
|
|
|
|
*/
|
|
|
|
#define CP_JAPANESE CP_SHIFTJIS
|
|
|
|
#define CP_KOREAN CP_HANGUL
|
|
|
|
#define CP_CHINESE_SIMPLIFIED CP_GB2312
|
|
|
|
#define CP_CHINESE_TRADITIONAL CP_BIG5
|
|
|
|
|
2017-05-03 19:47:18 +00:00
|
|
|
/* IsFarEastCP(CodePage) */
|
|
|
|
#define IsCJKCodePage(CodePage) \
|
|
|
|
((CodePage) == CP_SHIFTJIS || (CodePage) == CP_HANGUL || \
|
2019-05-19 20:55:14 +00:00
|
|
|
/* (CodePage) == CP_JOHAB || */ \
|
2017-05-03 19:47:18 +00:00
|
|
|
(CodePage) == CP_BIG5 || (CodePage) == CP_GB2312)
|
|
|
|
|
2019-05-19 20:55:14 +00:00
|
|
|
#if !defined(_WINGDI_) || defined(NOGDI)
|
|
|
|
#define SHIFTJIS_CHARSET 128
|
|
|
|
#define HANGEUL_CHARSET 129
|
|
|
|
#define HANGUL_CHARSET 129 // HANGEUL_CHARSET
|
|
|
|
#if(WINVER >= 0x0400)
|
|
|
|
#define JOHAB_CHARSET 130
|
|
|
|
#endif /* WINVER */
|
|
|
|
#define GB2312_CHARSET 134
|
|
|
|
#define CHINESEBIG5_CHARSET 136
|
|
|
|
#endif /* !defined(_WINGDI_) || defined(NOGDI) */
|
|
|
|
|
|
|
|
/* IsAnyDBCSCharSet(CharSet) */
|
|
|
|
#define IsCJKCharSet(CharSet) \
|
|
|
|
((CharSet) == SHIFTJIS_CHARSET || (CharSet) == HANGUL_CHARSET || \
|
|
|
|
/* (CharSet) == JOHAB_CHARSET || */ \
|
|
|
|
(CharSet) == GB2312_CHARSET || (CharSet) == CHINESEBIG5_CHARSET)
|
|
|
|
|
|
|
|
#define IsBoldFont(Weight) \
|
|
|
|
((Weight) >= FW_SEMIBOLD) /* Sometimes, just > FW_MEDIUM */
|
|
|
|
|
2021-07-05 18:07:21 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* @struct TrueType font list, cached from
|
|
|
|
* HKEY_LOCAL_MACHINE\Software\Microsoft\Windows NT\CurrentVersion\Console\TrueTypeFont
|
|
|
|
*
|
|
|
|
* See the definition of struct _TT_FONT_LIST
|
|
|
|
* in https://github.com/microsoft/terminal/blob/main/dep/Console/winconp.h
|
|
|
|
*/
|
|
|
|
#define BOLD_MARK L'*'
|
|
|
|
|
2019-05-19 20:55:14 +00:00
|
|
|
typedef struct _TT_FONT_ENTRY
|
|
|
|
{
|
2021-07-05 18:07:21 +00:00
|
|
|
SINGLE_LIST_ENTRY Entry;
|
2019-05-19 20:55:14 +00:00
|
|
|
UINT CodePage;
|
|
|
|
BOOL DisableBold;
|
|
|
|
WCHAR FaceName[LF_FACESIZE];
|
|
|
|
WCHAR FaceNameAlt[LF_FACESIZE];
|
|
|
|
} TT_FONT_ENTRY, *PTT_FONT_ENTRY;
|
|
|
|
|
|
|
|
|
2017-05-03 19:47:18 +00:00
|
|
|
/* FUNCTIONS ******************************************************************/
|
|
|
|
|
|
|
|
BYTE
|
|
|
|
CodePageToCharSet(
|
2022-01-24 15:45:59 +00:00
|
|
|
_In_ UINT CodePage);
|
2017-05-03 19:47:18 +00:00
|
|
|
|
2022-01-29 19:04:16 +00:00
|
|
|
// FIXME: Will be redefined once we support a font cache.
|
|
|
|
typedef struct _FONT_DATA
|
|
|
|
{
|
|
|
|
_Inout_updates_z_(LF_FACESIZE) PWSTR FaceName;
|
|
|
|
ULONG Weight;
|
|
|
|
ULONG Family;
|
|
|
|
COORD Size;
|
|
|
|
BYTE CharSet;
|
|
|
|
} FONT_DATA, *PFONT_DATA;
|
|
|
|
|
2017-05-03 19:47:18 +00:00
|
|
|
HFONT
|
|
|
|
CreateConsoleFontEx(
|
2022-01-24 15:45:59 +00:00
|
|
|
_In_ LONG Height,
|
|
|
|
_In_opt_ LONG Width,
|
|
|
|
_Inout_updates_z_(LF_FACESIZE)
|
|
|
|
PWSTR FaceName,
|
|
|
|
_In_ ULONG FontWeight,
|
2022-01-29 19:04:16 +00:00
|
|
|
_In_ ULONG FontFamily,
|
|
|
|
_In_ UINT CodePage,
|
|
|
|
_In_ BOOL UseDefaultFallback,
|
|
|
|
_Out_ PFONT_DATA FontData);
|
2017-05-03 19:47:18 +00:00
|
|
|
|
|
|
|
HFONT
|
|
|
|
CreateConsoleFont2(
|
2022-01-24 15:45:59 +00:00
|
|
|
_In_ LONG Height,
|
|
|
|
_In_opt_ LONG Width,
|
|
|
|
_Inout_ PCONSOLE_STATE_INFO ConsoleInfo);
|
2017-05-03 19:47:18 +00:00
|
|
|
|
|
|
|
HFONT
|
|
|
|
CreateConsoleFont(
|
2022-01-24 15:45:59 +00:00
|
|
|
_Inout_ PCONSOLE_STATE_INFO ConsoleInfo);
|
2017-05-03 19:47:18 +00:00
|
|
|
|
2022-01-24 15:45:59 +00:00
|
|
|
_Success_(return)
|
2017-05-03 19:47:18 +00:00
|
|
|
BOOL
|
|
|
|
GetFontCellSize(
|
2022-01-24 15:45:59 +00:00
|
|
|
_In_opt_ HDC hDC,
|
|
|
|
_In_ HFONT hFont,
|
|
|
|
_Out_ PUINT Height,
|
|
|
|
_Out_ PUINT Width);
|
2017-05-03 19:47:18 +00:00
|
|
|
|
|
|
|
BOOL
|
|
|
|
IsValidConsoleFont2(
|
2022-01-24 15:45:59 +00:00
|
|
|
_In_ PLOGFONTW lplf,
|
|
|
|
_In_ PNEWTEXTMETRICW lpntm,
|
|
|
|
_In_ DWORD FontType,
|
|
|
|
_In_ UINT CodePage);
|
2017-05-03 19:47:18 +00:00
|
|
|
|
|
|
|
BOOL
|
|
|
|
IsValidConsoleFont(
|
2022-01-24 15:45:59 +00:00
|
|
|
// _In_reads_or_z_(LF_FACESIZE)
|
|
|
|
_In_ PCWSTR FaceName,
|
|
|
|
_In_ UINT CodePage);
|
2017-05-03 19:47:18 +00:00
|
|
|
|
2021-07-05 18:07:21 +00:00
|
|
|
|
2019-05-19 20:55:14 +00:00
|
|
|
VOID
|
|
|
|
InitTTFontCache(VOID);
|
|
|
|
|
|
|
|
VOID
|
|
|
|
ClearTTFontCache(VOID);
|
|
|
|
|
|
|
|
VOID
|
|
|
|
RefreshTTFontCache(VOID);
|
|
|
|
|
|
|
|
PTT_FONT_ENTRY
|
|
|
|
FindCachedTTFont(
|
2022-01-30 17:29:00 +00:00
|
|
|
_In_reads_or_z_opt_(LF_FACESIZE)
|
|
|
|
PCWSTR FaceName,
|
2022-01-24 15:45:59 +00:00
|
|
|
_In_ UINT CodePage);
|
2019-05-19 20:55:14 +00:00
|
|
|
|
2022-01-30 17:29:00 +00:00
|
|
|
/**
|
|
|
|
* @brief
|
|
|
|
* Verifies whether the given font is an additional console TrueType font.
|
|
|
|
* Wrapper macros around FindCachedTTFont().
|
|
|
|
*
|
|
|
|
* @remark
|
|
|
|
* These macros are equivalents of the functions
|
|
|
|
* IsAvailableTTFont() and IsAvailableTTFontCP() in
|
|
|
|
* https://github.com/microsoft/terminal/blob/main/src/propsheet/dbcs.cpp
|
|
|
|
**/
|
|
|
|
|
2019-05-19 20:55:14 +00:00
|
|
|
#define IsAdditionalTTFont(FaceName) \
|
|
|
|
(FindCachedTTFont((FaceName), INVALID_CP) != NULL)
|
|
|
|
|
|
|
|
#define IsAdditionalTTFontCP(FaceName, CodePage) \
|
|
|
|
(FindCachedTTFont((FaceName), (CodePage)) != NULL)
|
|
|
|
|
2017-05-03 19:47:18 +00:00
|
|
|
/* EOF */
|