9 #define COUNT_OF(array) (sizeof(array) / sizeof((array)[0]))
11 // See https://en.wikipedia.org/wiki/List_of_CJK_fonts
12 const wchar_t kMSGothic[] = { 0xff2d, 0xff33, 0x0020, 0x30b4, 0x30b7, 0x30c3, 0x30af, 0 }; // Japanese
13 const wchar_t kNSimSun[] = { 0x65b0, 0x5b8b, 0x4f53, 0 }; // Simplified Chinese
14 const wchar_t kMingLight[] = { 0x7d30, 0x660e, 0x9ad4, 0 }; // Traditional Chinese
15 const wchar_t kGulimChe[] = { 0xad74, 0xb9bc, 0xccb4, 0 }; // Korean
18 setlocale(LC_ALL, "");
19 wchar_t *cmdline = GetCommandLineW();
21 wchar_t **argv = CommandLineToArgvW(cmdline, &argc);
22 const HANDLE conout = openConout();
26 cprintf(L" SetFont <index>\n");
27 cprintf(L" SetFont options\n");
29 cprintf(L"Options for SetCurrentConsoleFontEx:\n");
30 cprintf(L" -idx INDEX\n");
31 cprintf(L" -w WIDTH\n");
32 cprintf(L" -h HEIGHT\n");
33 cprintf(L" -family (0xNN|NN)\n");
34 cprintf(L" -weight (normal|bold|NNN)\n");
35 cprintf(L" -face FACENAME\n");
36 cprintf(L" -face-{gothic|simsun|minglight|gulimche) [JP,CN-sim,CN-tra,KR]\n");
41 cprintf(L" -roman\n");
42 cprintf(L" -swiss\n");
43 cprintf(L" -modern\n");
44 cprintf(L" -script\n");
45 cprintf(L" -decorative\n");
49 if (isdigit(argv[1][0])) {
50 int index = _wtoi(argv[1]);
51 HMODULE kernel32 = LoadLibraryW(L"kernel32.dll");
52 FARPROC proc = GetProcAddress(kernel32, "SetConsoleFont");
54 cprintf(L"Couldn't get address of SetConsoleFont\n");
56 BOOL ret = reinterpret_cast<BOOL WINAPI(*)(HANDLE, DWORD)>(proc)(
58 cprintf(L"SetFont returned %d\n", ret);
63 CONSOLE_FONT_INFOEX fontex = {0};
64 fontex.cbSize = sizeof(fontex);
66 for (int i = 1; i < argc; ++i) {
67 std::wstring arg = argv[i];
69 std::wstring next = argv[i + 1];
71 fontex.nFont = _wtoi(next.c_str());
73 } else if (arg == L"-w") {
74 fontex.dwFontSize.X = _wtoi(next.c_str());
76 } else if (arg == L"-h") {
77 fontex.dwFontSize.Y = _wtoi(next.c_str());
79 } else if (arg == L"-weight") {
80 if (next == L"normal") {
81 fontex.FontWeight = 400;
82 } else if (next == L"bold") {
83 fontex.FontWeight = 700;
85 fontex.FontWeight = _wtoi(next.c_str());
88 } else if (arg == L"-face") {
89 wcsncpy(fontex.FaceName, next.c_str(), COUNT_OF(fontex.FaceName));
91 } else if (arg == L"-family") {
92 fontex.FontFamily = strtol(narrowString(next).c_str(), nullptr, 0);
97 fontex.FontFamily |= TMPF_TRUETYPE;
98 } else if (arg == L"-vec") {
99 fontex.FontFamily |= TMPF_VECTOR;
100 } else if (arg == L"-vp") {
101 // Setting the TMPF_FIXED_PITCH bit actually indicates variable
103 fontex.FontFamily |= TMPF_FIXED_PITCH;
104 } else if (arg == L"-dev") {
105 fontex.FontFamily |= TMPF_DEVICE;
106 } else if (arg == L"-roman") {
107 fontex.FontFamily = (fontex.FontFamily & ~0xF0) | FF_ROMAN;
108 } else if (arg == L"-swiss") {
109 fontex.FontFamily = (fontex.FontFamily & ~0xF0) | FF_SWISS;
110 } else if (arg == L"-modern") {
111 fontex.FontFamily = (fontex.FontFamily & ~0xF0) | FF_MODERN;
112 } else if (arg == L"-script") {
113 fontex.FontFamily = (fontex.FontFamily & ~0xF0) | FF_SCRIPT;
114 } else if (arg == L"-decorative") {
115 fontex.FontFamily = (fontex.FontFamily & ~0xF0) | FF_DECORATIVE;
116 } else if (arg == L"-face-gothic") {
117 wcsncpy(fontex.FaceName, kMSGothic, COUNT_OF(fontex.FaceName));
118 } else if (arg == L"-face-simsun") {
119 wcsncpy(fontex.FaceName, kNSimSun, COUNT_OF(fontex.FaceName));
120 } else if (arg == L"-face-minglight") {
121 wcsncpy(fontex.FaceName, kMingLight, COUNT_OF(fontex.FaceName));
122 } else if (arg == L"-face-gulimche") {
123 wcsncpy(fontex.FaceName, kGulimChe, COUNT_OF(fontex.FaceName));
125 cprintf(L"Unrecognized argument: %ls\n", arg.c_str());
130 cprintf(L"Setting to: nFont=%u dwFontSize=(%d,%d) "
131 L"FontFamily=0x%x FontWeight=%u "
132 L"FaceName=\"%ls\"\n",
133 static_cast<unsigned>(fontex.nFont),
134 fontex.dwFontSize.X, fontex.dwFontSize.Y,
135 fontex.FontFamily, fontex.FontWeight,
138 BOOL ret = SetCurrentConsoleFontEx(
142 cprintf(L"SetCurrentConsoleFontEx returned %d\n", ret);