Author: hbelusca Date: Mon Apr 17 23:21:13 2017 New Revision: 74365
URL: http://svn.reactos.org/svn/reactos?rev=74365&view=rev Log: [CONSOLE.CPL]: Add support for Asian fonts & CJK codepage in the console properties dialog. Based on a patch by Katayama Hirofumi MZ. CORE-12451
Modified: trunk/reactos/dll/cpl/console/console.h trunk/reactos/dll/cpl/console/font.c
Modified: trunk/reactos/dll/cpl/console/console.h URL: http://svn.reactos.org/svn/reactos/trunk/reactos/dll/cpl/console/console.h?r... ============================================================================== --- trunk/reactos/dll/cpl/console/console.h [iso-8859-1] (original) +++ trunk/reactos/dll/cpl/console/console.h [iso-8859-1] Mon Apr 17 23:21:13 2017 @@ -8,6 +8,7 @@ #include <windef.h> #include <winbase.h> #include <wingdi.h> +#include <winnls.h> #include <winreg.h> #include <winuser.h> #include <wincon.h> @@ -32,6 +33,7 @@ extern PCONSOLE_STATE_INFO ConInfo;
VOID ApplyConsoleInfo(HWND hwndDlg); +BYTE CodePageToCharSet(UINT CodePage); VOID PaintConsole(LPDRAWITEMSTRUCT drawItem, PCONSOLE_STATE_INFO pConInfo); BOOL PaintText(LPDRAWITEMSTRUCT drawItem, PCONSOLE_STATE_INFO pConInfo, TEXT_TYPE TextMode);
Modified: trunk/reactos/dll/cpl/console/font.c URL: http://svn.reactos.org/svn/reactos/trunk/reactos/dll/cpl/console/font.c?rev=... ============================================================================== --- trunk/reactos/dll/cpl/console/font.c [iso-8859-1] (original) +++ trunk/reactos/dll/cpl/console/font.c [iso-8859-1] Mon Apr 17 23:21:13 2017 @@ -5,6 +5,7 @@ * PURPOSE: Font dialog * PROGRAMMERS: Johannes Anderwald (johannes.anderwald@reactos.org) * Hermes Belusca-Maito (hermes.belusca@sfr.fr) + * Katayama Hirofumi MZ (katayama.hirofumi.mz@gmail.com) */
#include "console.h" @@ -92,6 +93,26 @@ // 22, 24, 26, 28, 36, 48, 72 5, 6, 7, 8, 10, 12, 14, 16, 18, 20, 24, 28, 36, 72 }; + +#define CP_SHIFTJIS 932 // Japanese Shift-JIS +#define CP_HANGUL 949 // Korean Hangul +#define CP_GB2312 936 // Chinese Simplified (GB2312) +#define CP_BIG5 950 // Chinese Traditional (Big5) + +/* IsFarEastCP(CodePage) */ +#define IsCJKCodePage(CodePage) \ + ((CodePage) == CP_SHIFTJIS || (CodePage) == CP_HANGUL || \ + (CodePage) == CP_BIG5 || (CodePage) == CP_GB2312) + +/* Retrieves the character set associated with a given code page */ +BYTE CodePageToCharSet(UINT CodePage) +{ + CHARSETINFO CharInfo; + if (TranslateCharsetInfo((LPDWORD)CodePage, &CharInfo, TCI_SRCCODEPAGE)) + return CharInfo.ciCharset; + else + return DEFAULT_CHARSET; +}
static BOOL CALLBACK EnumFontNamesProc(PLOGFONTW lplf, @@ -134,7 +155,6 @@ * that can be italic or have negative A or C space. * - If it is not a TrueType font, it can be from another character set * than OEM_CHARSET. - * - We do not support Asian criteria at the moment. * - We do not look into the magic registry key mentioned above. */
@@ -162,23 +182,42 @@ return TRUE; }
- /* Reject non-TrueType fonts that are not OEM */ -#if 0 - if ((FontType != TRUETYPE_FONTTYPE) && (lplf->lfCharSet != OEM_CHARSET)) - { - DPRINT1("Non-TrueType font '%S' rejected because it's not OEM_CHARSET %d\n", - pszName, lplf->lfCharSet); - return TRUE; - } -#else // Improved criterium - if ((FontType != TRUETYPE_FONTTYPE) && - ((lplf->lfCharSet != ANSI_CHARSET) && (lplf->lfCharSet != DEFAULT_CHARSET) && (lplf->lfCharSet != OEM_CHARSET))) - { - DPRINT1("Non-TrueType font '%S' rejected because it's not ANSI_CHARSET or DEFAULT_CHARSET or OEM_CHARSET (lfCharSet = %d)\n", - pszName, lplf->lfCharSet); - return TRUE; - } -#endif + /* Is the current code page Chinese, Japanese or Korean? */ + if (IsCJKCodePage(ConInfo->CodePage)) + { + /* It's Asian */ + if (FontType == TRUETYPE_FONTTYPE) + { + if (lplf->lfCharSet != CodePageToCharSet(ConInfo->CodePage)) + { + DPRINT1("TrueType font '%S' rejected because it's not user Asian charset (lfCharSet = %d)\n", + pszName, lplf->lfCharSet); + return TRUE; + } + } + else + { + /* Reject non-TrueType fonts that are not Terminal */ + if (wcscmp(pszName, L"Terminal") != 0) + { + DPRINT1("Non-TrueType font '%S' rejected because it's not Terminal\n", pszName); + return TRUE; + } + } + } + else + { + /* Not CJK */ + if ((FontType != TRUETYPE_FONTTYPE) && + (lplf->lfCharSet != ANSI_CHARSET) && + (lplf->lfCharSet != DEFAULT_CHARSET) && + (lplf->lfCharSet != OEM_CHARSET)) + { + DPRINT1("Non-TrueType font '%S' rejected because it's not ANSI_CHARSET or DEFAULT_CHARSET or OEM_CHARSET (lfCharSet = %d)\n", + pszName, lplf->lfCharSet); + return TRUE; + } + }
/* Reject fonts that are vertical (tategaki) */ if (pszName[0] == L'@') @@ -186,17 +225,6 @@ DPRINT1("Font '%S' rejected because it's vertical\n", pszName); return TRUE; } - -#if 0 // For Asian installations only - /* Reject non-TrueType fonts that are not Terminal */ - if ((FontType != TRUETYPE_FONTTYPE) && (wcscmp(pszName, L"Terminal") != 0)) - { - DPRINT1("Non-TrueType font '%S' rejected because it's not Terminal\n", pszName); - return TRUE; - } - - // TODO: Asian TrueType font must also be an Asian character set. -#endif
/* Make sure the font doesn't already exist in the list */ if (SendMessageW(hwndCombo, LB_FINDSTRINGEXACT, 0, (LPARAM)pszName) == LB_ERR) @@ -314,7 +342,7 @@
/* Enumerate the available sizes for the selected font */ ZeroMemory(&lf, sizeof(lf)); - lf.lfCharSet = DEFAULT_CHARSET; // OEM_CHARSET; + lf.lfCharSet = DEFAULT_CHARSET; // CodePageToCharSet(pConInfo->CodePage); // lf.lfPitchAndFamily = FIXED_PITCH | FF_DONTCARE; wcsncpy(lf.lfFaceName, FaceName, LF_FACESIZE); lf.lfFaceName[Length] = L'\0'; @@ -386,13 +414,39 @@ INT idx;
ZeroMemory(&lf, sizeof(lf)); - lf.lfCharSet = DEFAULT_CHARSET; // OEM_CHARSET; + lf.lfCharSet = DEFAULT_CHARSET; // CodePageToCharSet(ConInfo->CodePage); // lf.lfPitchAndFamily = FIXED_PITCH | FF_DONTCARE;
hDC = GetDC(NULL); EnumFontFamiliesExW(hDC, &lf, (FONTENUMPROCW)EnumFontNamesProc, (LPARAM)GetDlgItem(hwndDlg, IDC_LBOX_FONTTYPE), 0); ReleaseDC(NULL, hDC); + + idx = (INT)SendDlgItemMessageW(hwndDlg, IDC_LBOX_FONTTYPE, LB_GETCOUNT, 0, 0); + if ((idx == 0) || (idx == LB_ERR)) + { + DPRINT1("The ideal console fonts are not found; manually add default ones.\n"); + + /* This world is not ideal. We have to do it realistically. */ + idx = (INT)SendDlgItemMessageW(hwndDlg, IDC_LBOX_FONTTYPE, LB_ADDSTRING, 0, + (LPARAM)L"Lucida Console"); + if (idx != LB_ERR) + { + SendDlgItemMessageW(hwndDlg, IDC_LBOX_FONTTYPE, + LB_SETITEMDATA, idx, TRUETYPE_FONTTYPE); + } + + if (CodePageToCharSet(ConInfo->CodePage) != DEFAULT_CHARSET) + { + idx = (INT)SendDlgItemMessageW(hwndDlg, IDC_LBOX_FONTTYPE, LB_ADDSTRING, 0, + (LPARAM)L"Droid Sans Fallback"); + if (idx != LB_ERR) + { + SendDlgItemMessageW(hwndDlg, IDC_LBOX_FONTTYPE, + LB_SETITEMDATA, idx, TRUETYPE_FONTTYPE); + } + } + }
DPRINT1("ConInfo->FaceName = '%S'\n", ConInfo->FaceName); idx = (INT)SendDlgItemMessageW(hwndDlg, IDC_LBOX_FONTTYPE,