Skip to content

Commit c84dd17

Browse files
committed
Merge pull request #1 from PowerShell/newDev
add CJK support
2 parents d3bf9ea + f1717f2 commit c84dd17

File tree

3 files changed

+389
-75
lines changed

3 files changed

+389
-75
lines changed

PSReadLine/ConsoleLib.cs

Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,27 @@ public static extern int ToUnicode(uint uVirtKey, uint uScanCode, byte[] lpKeySt
5858

5959
[DllImport("user32.dll", CharSet = CharSet.Unicode, SetLastError = true)]
6060
public static extern short VkKeyScan(char @char);
61+
62+
[DllImport("kernel32.dll", SetLastError = false, CharSet = CharSet.Unicode)]
63+
public static extern uint GetConsoleOutputCP();
64+
65+
[DllImport("User32.dll", SetLastError = false, CharSet = CharSet.Unicode)]
66+
public static extern int ReleaseDC(IntPtr hwnd, IntPtr hdc);
67+
68+
[DllImport("kernel32.dll", SetLastError = true, CharSet = CharSet.Unicode)]
69+
public static extern IntPtr GetConsoleWindow();
70+
71+
[DllImport("User32.dll", SetLastError = true, CharSet = CharSet.Unicode)]
72+
public static extern IntPtr GetDC(IntPtr hwnd);
73+
74+
[DllImport("GDI32.dll", SetLastError = true, CharSet = CharSet.Unicode)]
75+
public static extern bool TranslateCharsetInfo(IntPtr src, out CHARSETINFO Cs, uint options);
76+
77+
[DllImport("GDI32.dll", SetLastError = true, CharSet = CharSet.Unicode)]
78+
public static extern bool GetTextMetrics(IntPtr hdc, out TEXTMETRIC tm);
79+
80+
[DllImport("GDI32.dll", SetLastError = true, CharSet = CharSet.Unicode)]
81+
public static extern bool GetCharWidth32(IntPtr hdc, uint first, uint last, out int width);
6182
}
6283

6384
public delegate bool BreakHandler(ConsoleBreakSignal ConsoleBreakSignal);
@@ -119,6 +140,56 @@ public override string ToString()
119140
}
120141
}
121142

143+
[StructLayout(LayoutKind.Sequential)]
144+
public struct FONTSIGNATURE
145+
{
146+
//From public\sdk\inc\wingdi.h
147+
148+
// fsUsb*: A 128-bit Unicode subset bitfield (USB) identifying up to 126 Unicode subranges
149+
internal uint fsUsb0;
150+
internal uint fsUsb1;
151+
internal uint fsUsb2;
152+
internal uint fsUsb3;
153+
// fsCsb*: A 64-bit, code-page bitfield (CPB) that identifies a specific character set or code page.
154+
internal uint fsCsb0;
155+
internal uint fsCsb1;
156+
}
157+
158+
[StructLayout(LayoutKind.Sequential)]
159+
public struct CHARSETINFO
160+
{
161+
//From public\sdk\inc\wingdi.h
162+
internal uint ciCharset; // Character set value.
163+
internal uint ciACP; // ANSI code-page identifier.
164+
internal FONTSIGNATURE fs;
165+
}
166+
167+
[StructLayout(LayoutKind.Sequential, CharSet = CharSet.Unicode)]
168+
public struct TEXTMETRIC
169+
{
170+
//From public\sdk\inc\wingdi.h
171+
public int tmHeight;
172+
public int tmAscent;
173+
public int tmDescent;
174+
public int tmInternalLeading;
175+
public int tmExternalLeading;
176+
public int tmAveCharWidth;
177+
public int tmMaxCharWidth;
178+
public int tmWeight;
179+
public int tmOverhang;
180+
public int tmDigitizedAspectX;
181+
public int tmDigitizedAspectY;
182+
public char tmFirstChar;
183+
public char tmLastChar;
184+
public char tmDefaultChar;
185+
public char tmBreakChar;
186+
public byte tmItalic;
187+
public byte tmUnderlined;
188+
public byte tmStruckOut;
189+
public byte tmPitchAndFamily;
190+
public byte tmCharSet;
191+
}
192+
122193
public struct CHAR_INFO
123194
{
124195
public ushort UnicodeChar;

0 commit comments

Comments
 (0)