private static int LengthInBufferCells(char c, uint codePage) { int num; if (ConsoleControl.IsAvailableFarEastCodePage(codePage)) { IntPtr intPtr = (IntPtr)0; IntPtr intPtr1 = (IntPtr)0; bool flag = false; ConsoleControl.TEXTMETRIC tEXTMETRIC = new ConsoleControl.TEXTMETRIC(); try { num = ConsoleControl.LengthInBufferCellsFE(c, ref intPtr, ref intPtr1, ref flag, ref tEXTMETRIC); } finally { if (intPtr != (IntPtr)0 && intPtr1 != (IntPtr)0) { ConsoleControl.NativeMethods.ReleaseDC(intPtr, intPtr1); } } return num; } else { return 1; } }
internal static int LengthInBufferCells(string str, int offset) { int num; uint consoleOutputCP = ConsoleControl.NativeMethods.GetConsoleOutputCP(); if (ConsoleControl.IsAvailableFarEastCodePage(consoleOutputCP)) { IntPtr intPtr = (IntPtr)0; IntPtr intPtr1 = (IntPtr)0; bool flag = false; ConsoleControl.TEXTMETRIC tEXTMETRIC = new ConsoleControl.TEXTMETRIC(); int num1 = 0; try { int length = str.Length; for (int i = offset; i < length; i++) { char chr = str[i]; num1 = num1 + ConsoleControl.LengthInBufferCellsFE(chr, ref intPtr, ref intPtr1, ref flag, ref tEXTMETRIC); } num = num1; } finally { if (intPtr != (IntPtr)0 && intPtr1 != (IntPtr)0) { ConsoleControl.NativeMethods.ReleaseDC(intPtr, intPtr1); } } return num; } else { return str.Length - offset; } }
/* [DllImport("GDI32.dll", CharSet=CharSet.Unicode)] internal static extern bool GetTextMetrics(IntPtr hdc, out ConsoleControl.TEXTMETRIC tm); */ internal static bool GetTextMetrics(IntPtr hdc, out ConsoleControl.TEXTMETRIC tm) { ConsoleControl.TEXTMETRIC rtm = new ConsoleControl.TEXTMETRIC(); rtm.tmDefaultChar = Char.MinValue; tm = rtm; return true; }