Displaying unicode chess pieces in Windows-console

烈酒焚心 提交于 2019-12-05 15:24:31
M.M

I was able to display the chess pieces correctly. The main issue is that the default console font does not include the glyphs for the chess pieces. You can fix that by installing DejaVu Sans Mono as the console font.

After doing that, there are two possible approaches (I am using MinGW-w64).

Using UTF-16

HANDLE cons = GetStdHandle(STD_OUTPUT_HANDLE);
wchar_t p[] = L"Queen: \u265B.\n";
// wprintf(p);
DWORD n;
WriteConsoleW(cons, p, wcslen(p), &n, NULL );

Note that the wprintf doesn't work. I believe this is because MS's console routines are terrible , and MinGW routes through those.

Using UTF-8

SetConsoleOutputCP(65001);        // Command prompt UTF-8 code page
char q[] = "King: \xE2\x99\x94.\n";
printf(q);

Cygwin note: Cygwin seems to behave differently depending on whether you have Raster Font or a TTF font chosen. With DejaVu Sans Mono used for Cygwin also, both options displayed correctly.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!