2015-10-07 04:51:12 +00:00
|
|
|
|
#include <windows.h>
|
2015-10-09 23:52:20 +00:00
|
|
|
|
#include <locale.h>
|
2015-10-09 22:42:18 +00:00
|
|
|
|
#include <stdio.h>
|
2015-10-07 04:51:12 +00:00
|
|
|
|
#include <stdlib.h>
|
2015-10-09 22:42:18 +00:00
|
|
|
|
#include <string>
|
|
|
|
|
|
|
|
|
|
#include "TestUtil.cc"
|
2015-10-07 04:51:12 +00:00
|
|
|
|
|
|
|
|
|
#define COUNT_OF(array) (sizeof(array) / sizeof((array)[0]))
|
|
|
|
|
|
|
|
|
|
// Attempt to set the console font to the given facename and pixel size.
|
|
|
|
|
// These APIs should exist on Vista and up.
|
|
|
|
|
static void setConsoleFont(const wchar_t *faceName, int pixelSize)
|
|
|
|
|
{
|
|
|
|
|
CONSOLE_FONT_INFOEX fontex = {0};
|
|
|
|
|
fontex.cbSize = sizeof(fontex);
|
|
|
|
|
fontex.FontWeight = 400;
|
|
|
|
|
fontex.dwFontSize.Y = pixelSize;
|
|
|
|
|
wcsncpy(fontex.FaceName, faceName, COUNT_OF(fontex.FaceName));
|
2015-10-09 22:42:18 +00:00
|
|
|
|
fontex.nFont = 34;
|
|
|
|
|
BOOL ret = SetCurrentConsoleFontEx(
|
2015-10-07 04:51:12 +00:00
|
|
|
|
GetStdHandle(STD_OUTPUT_HANDLE),
|
|
|
|
|
FALSE,
|
|
|
|
|
&fontex);
|
2015-10-09 23:52:20 +00:00
|
|
|
|
cprintf(L"SetCurrentConsoleFontEx returned %d\n", ret);
|
2015-10-07 04:51:12 +00:00
|
|
|
|
}
|
|
|
|
|
|
2015-10-09 23:52:20 +00:00
|
|
|
|
int main() {
|
|
|
|
|
setlocale(LC_ALL, "");
|
|
|
|
|
wchar_t *cmdline = GetCommandLineW();
|
|
|
|
|
int argc = 0;
|
|
|
|
|
wchar_t **argv = CommandLineToArgvW(cmdline, &argc);
|
|
|
|
|
|
2015-10-09 22:42:18 +00:00
|
|
|
|
if (argc == 1) {
|
2015-10-09 23:52:20 +00:00
|
|
|
|
cprintf(L"Usage:\n");
|
|
|
|
|
cprintf(L" SetFont <index>\n");
|
|
|
|
|
cprintf(L" SetFont options\n");
|
|
|
|
|
cprintf(L"\n");
|
|
|
|
|
cprintf(L"Options for SetCurrentConsoleFontEx:\n");
|
|
|
|
|
cprintf(L" -idx INDEX\n");
|
|
|
|
|
cprintf(L" -w WIDTH\n");
|
|
|
|
|
cprintf(L" -h HEIGHT\n");
|
|
|
|
|
cprintf(L" -weight (normal|bold|NNN)\n");
|
|
|
|
|
cprintf(L" -face FACENAME\n");
|
|
|
|
|
cprintf(L" -tt\n");
|
|
|
|
|
cprintf(L" -vec\n");
|
|
|
|
|
cprintf(L" -vp\n");
|
|
|
|
|
cprintf(L" -dev\n");
|
|
|
|
|
cprintf(L" -roman\n");
|
|
|
|
|
cprintf(L" -swiss\n");
|
|
|
|
|
cprintf(L" -modern\n");
|
|
|
|
|
cprintf(L" -script\n");
|
|
|
|
|
cprintf(L" -decorative\n");
|
2015-10-09 22:42:18 +00:00
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (isdigit(argv[1][0])) {
|
2015-10-09 23:52:20 +00:00
|
|
|
|
int index = _wtoi(argv[1]);
|
2015-10-09 22:42:18 +00:00
|
|
|
|
HMODULE kernel32 = LoadLibraryW(L"kernel32.dll");
|
|
|
|
|
FARPROC proc = GetProcAddress(kernel32, "SetConsoleFont");
|
|
|
|
|
if (proc == NULL) {
|
2015-10-09 23:52:20 +00:00
|
|
|
|
cprintf(L"Couldn't get address of SetConsoleFont\n");
|
2015-10-09 22:42:18 +00:00
|
|
|
|
} else {
|
|
|
|
|
const HANDLE conout = GetStdHandle(STD_OUTPUT_HANDLE);
|
|
|
|
|
BOOL ret = reinterpret_cast<BOOL WINAPI(*)(HANDLE, DWORD)>(proc)(
|
|
|
|
|
conout, index);
|
2015-10-09 23:52:20 +00:00
|
|
|
|
cprintf(L"SetFont returned %d\n", ret);
|
2015-10-09 22:42:18 +00:00
|
|
|
|
}
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
CONSOLE_FONT_INFOEX fontex = {0};
|
|
|
|
|
fontex.cbSize = sizeof(fontex);
|
|
|
|
|
|
|
|
|
|
for (int i = 1; i < argc; ++i) {
|
2015-10-09 23:52:20 +00:00
|
|
|
|
std::wstring arg = argv[i];
|
2015-10-09 22:42:18 +00:00
|
|
|
|
if (i + 1 < argc) {
|
2015-10-09 23:52:20 +00:00
|
|
|
|
std::wstring next = argv[i + 1];
|
|
|
|
|
if (arg == L"-idx") {
|
|
|
|
|
fontex.nFont = _wtoi(next.c_str());
|
2015-10-09 22:42:18 +00:00
|
|
|
|
++i; continue;
|
2015-10-09 23:52:20 +00:00
|
|
|
|
} else if (arg == L"-w") {
|
|
|
|
|
fontex.dwFontSize.X = _wtoi(next.c_str());
|
2015-10-09 22:42:18 +00:00
|
|
|
|
++i; continue;
|
2015-10-09 23:52:20 +00:00
|
|
|
|
} else if (arg == L"-h") {
|
|
|
|
|
fontex.dwFontSize.Y = _wtoi(next.c_str());
|
2015-10-09 22:42:18 +00:00
|
|
|
|
++i; continue;
|
2015-10-09 23:52:20 +00:00
|
|
|
|
} else if (arg == L"-weight") {
|
|
|
|
|
if (next == L"normal") {
|
2015-10-09 22:42:18 +00:00
|
|
|
|
fontex.FontWeight = 400;
|
2015-10-09 23:52:20 +00:00
|
|
|
|
} else if (next == L"bold") {
|
2015-10-09 22:42:18 +00:00
|
|
|
|
fontex.FontWeight = 700;
|
|
|
|
|
} else {
|
2015-10-09 23:52:20 +00:00
|
|
|
|
fontex.FontWeight = _wtoi(next.c_str());
|
2015-10-09 22:42:18 +00:00
|
|
|
|
}
|
|
|
|
|
++i; continue;
|
2015-10-09 23:52:20 +00:00
|
|
|
|
} else if (arg == L"-face") {
|
|
|
|
|
wcsncpy(fontex.FaceName, next.c_str(), COUNT_OF(fontex.FaceName));
|
2015-10-09 22:42:18 +00:00
|
|
|
|
++i; continue;
|
|
|
|
|
}
|
|
|
|
|
}
|
2015-10-09 23:52:20 +00:00
|
|
|
|
if (arg == L"-tt") {
|
2015-10-09 22:42:18 +00:00
|
|
|
|
fontex.FontFamily |= TMPF_TRUETYPE;
|
2015-10-09 23:52:20 +00:00
|
|
|
|
} else if (arg == L"-vec") {
|
2015-10-09 22:42:18 +00:00
|
|
|
|
fontex.FontFamily |= TMPF_VECTOR;
|
2015-10-09 23:52:20 +00:00
|
|
|
|
} else if (arg == L"-vp") {
|
2015-10-09 22:42:18 +00:00
|
|
|
|
// Setting the TMPF_FIXED_PITCH bit actually indicates variable
|
|
|
|
|
// pitch.
|
|
|
|
|
fontex.FontFamily |= TMPF_FIXED_PITCH;
|
2015-10-09 23:52:20 +00:00
|
|
|
|
} else if (arg == L"-dev") {
|
2015-10-09 22:42:18 +00:00
|
|
|
|
fontex.FontFamily |= TMPF_DEVICE;
|
2015-10-09 23:52:20 +00:00
|
|
|
|
} else if (arg == L"-roman") {
|
2015-10-09 22:42:18 +00:00
|
|
|
|
fontex.FontFamily = (fontex.FontFamily & ~0xF0) | FF_ROMAN;
|
2015-10-09 23:52:20 +00:00
|
|
|
|
} else if (arg == L"-swiss") {
|
2015-10-09 22:42:18 +00:00
|
|
|
|
fontex.FontFamily = (fontex.FontFamily & ~0xF0) | FF_SWISS;
|
2015-10-09 23:52:20 +00:00
|
|
|
|
} else if (arg == L"-modern") {
|
2015-10-09 22:42:18 +00:00
|
|
|
|
fontex.FontFamily = (fontex.FontFamily & ~0xF0) | FF_MODERN;
|
2015-10-09 23:52:20 +00:00
|
|
|
|
} else if (arg == L"-script") {
|
2015-10-09 22:42:18 +00:00
|
|
|
|
fontex.FontFamily = (fontex.FontFamily & ~0xF0) | FF_SCRIPT;
|
2015-10-09 23:52:20 +00:00
|
|
|
|
} else if (arg == L"-decorative") {
|
2015-10-09 22:42:18 +00:00
|
|
|
|
fontex.FontFamily = (fontex.FontFamily & ~0xF0) | FF_DECORATIVE;
|
2015-10-09 23:52:20 +00:00
|
|
|
|
} else if (arg == L"-face-gothic") {
|
2015-10-09 22:42:18 +00:00
|
|
|
|
// MS ゴシック
|
|
|
|
|
const wchar_t gothicFace[] = {
|
|
|
|
|
0xFF2D, 0xFF33, 0x20, 0x30B4, 0x30B7, 0x30C3, 0x30AF, 0x0
|
|
|
|
|
};
|
2015-10-09 23:52:20 +00:00
|
|
|
|
wcsncpy(fontex.FaceName, gothicFace, COUNT_OF(fontex.FaceName));
|
2015-10-09 22:42:18 +00:00
|
|
|
|
} else {
|
2015-10-09 23:52:20 +00:00
|
|
|
|
cprintf(L"Unrecognized argument: %ls\n", arg.c_str());
|
2015-10-09 22:42:18 +00:00
|
|
|
|
exit(1);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
cprintf(L"Setting to: nFont=%u dwFontSize=(%d,%d) "
|
|
|
|
|
L"FontFamily=0x%x FontWeight=%u "
|
|
|
|
|
L"FaceName=\"%ls\"\n",
|
|
|
|
|
static_cast<unsigned>(fontex.nFont),
|
|
|
|
|
fontex.dwFontSize.X, fontex.dwFontSize.Y,
|
|
|
|
|
fontex.FontFamily, fontex.FontWeight,
|
|
|
|
|
fontex.FaceName);
|
|
|
|
|
|
|
|
|
|
BOOL ret = SetCurrentConsoleFontEx(
|
|
|
|
|
GetStdHandle(STD_OUTPUT_HANDLE),
|
|
|
|
|
FALSE,
|
|
|
|
|
&fontex);
|
2015-10-09 23:52:20 +00:00
|
|
|
|
cprintf(L"SetCurrentConsoleFontEx returned %d\n", ret);
|
2015-10-09 22:42:18 +00:00
|
|
|
|
|
2015-10-07 04:51:12 +00:00
|
|
|
|
return 0;
|
|
|
|
|
}
|