2 // Test half-width vs full-width characters.
10 #include "TestUtil.cc"
12 static void writeChars(const wchar_t *text) {
14 const int len = wcslen(text);
16 BOOL ret = WriteConsoleW(
17 GetStdHandle(STD_OUTPUT_HANDLE),
18 text, len, &actual, NULL);
19 trace("writeChars: ret=%d, actual=%lld", ret, (long long)actual);
22 static void dumpChars(int x, int y, int w, int h) {
24 const COORD bufSize = {w, h};
25 const COORD bufCoord = {0, 0};
26 const SMALL_RECT topLeft = {x, y, x + w - 1, y + h - 1};
27 CHAR_INFO mbcsData[w * h];
28 CHAR_INFO unicodeData[w * h];
29 SMALL_RECT readRegion;
31 ret = ReadConsoleOutputW(GetStdHandle(STD_OUTPUT_HANDLE), unicodeData,
32 bufSize, bufCoord, &readRegion);
35 ret = ReadConsoleOutputA(GetStdHandle(STD_OUTPUT_HANDLE), mbcsData,
36 bufSize, bufCoord, &readRegion);
40 for (int i = 0; i < w * h; ++i) {
41 printf("(%02d,%02d) CHAR: %04x %4x -- %02x %4x\n",
43 (unsigned short)unicodeData[i].Char.UnicodeChar,
44 (unsigned short)unicodeData[i].Attributes,
45 (unsigned char)mbcsData[i].Char.AsciiChar,
46 (unsigned short)mbcsData[i].Attributes);
50 int main(int argc, char *argv[]) {
52 setWindowPos(0, 0, 1, 1);
53 setBufferSize(80, 38);
54 setWindowPos(0, 0, 80, 38);
57 const wchar_t text1[] = {
58 0x3044, // U+3044 (HIRAGANA LETTER I)
59 0x2014, // U+2014 (EM DASH)
60 0x3044, // U+3044 (HIRAGANA LETTER I)
61 0xFF2D, // U+FF2D (FULLWIDTH LATIN CAPITAL LETTER M)
62 0x30FC, // U+30FC (KATAKANA-HIRAGANA PROLONGED SOUND MARK)
63 0x0031, // U+3031 (DIGIT ONE)
64 0x2014, // U+2014 (EM DASH)
65 0x0032, // U+0032 (DIGIT TWO)
66 0x005C, // U+005C (REVERSE SOLIDUS)
67 0x3044, // U+3044 (HIRAGANA LETTER I)
76 const wchar_t text2[] = {
77 0x0032, // U+3032 (DIGIT TWO)
78 0x3044, // U+3044 (HIRAGANA LETTER I)
86 dumpChars(0, 0, 17, 1);
87 dumpChars(2, 0, 2, 1);
88 dumpChars(2, 0, 1, 1);
89 dumpChars(3, 0, 1, 1);
90 dumpChars(78, 1, 2, 1);
91 dumpChars(0, 2, 2, 1);
96 const wchar_t text3[] = {
97 0x30FC, 0x30FC, 0x30FC, 0xFF2D, // 1
98 0x30FC, 0x30FC, 0x30FC, 0xFF2D, // 2
99 0x30FC, 0x30FC, 0x30FC, 0xFF2D, // 3
100 0x30FC, 0x30FC, 0x30FC, 0xFF2D, // 4
101 0x30FC, 0x30FC, 0x30FC, 0xFF2D, // 5
102 0x30FC, 0x30FC, 0x30FC, 0xFF2D, // 6
103 0x30FC, 0x30FC, 0x30FC, 0xFF2D, // 7
104 0x30FC, 0x30FC, 0x30FC, 0xFF2D, // 8
105 0x30FC, 0x30FC, 0x30FC, 0xFF2D, // 9
106 0x30FC, 0x30FC, 0x30FC, 0xFF2D, // 10
107 0x30FC, 0x30FC, 0x30FC, 0xFF2D, // 11
108 0x30FC, 0x30FC, 0x30FC, 0xFF2D, // 12
116 const COORD bufSize = {80, 2};
117 const COORD bufCoord = {0, 0};
118 SMALL_RECT readRegion = {0, 0, 79, 1};
119 CHAR_INFO unicodeData[160];
120 BOOL ret = ReadConsoleOutputW(GetStdHandle(STD_OUTPUT_HANDLE), unicodeData,
121 bufSize, bufCoord, &readRegion);
123 for (int i = 0; i < 96; ++i) {
124 printf("%04x ", unicodeData[i].Char.UnicodeChar);