-
Notifications
You must be signed in to change notification settings - Fork 166
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Double byte characters are printed twice #41
Comments
I think you mean double-width characters rather than double-byte characters. The first three characters are three bytes in UTF-8. (Note to myself, mostly: The first three characters are: U+3044 U+308D U+306F.) The problem originally didn't reproduce for me, but I managed to reproduce it by switching my system locale to "Japanese (Japan)." To do this, open the Control Panel, search for "Region" or "Region and Language" and open the Administrative tab. Then, in the "Language for non-Unicode programs" box, change the system locale to Japanese. I noticed that after doing this, the available fonts for the console change. With Windows 7 English, the options were:
With a Japanese locale, the options are:
However, winpty still successfully changes the font to Lucida Console, even though it isn't an available option. I tested using With my original system locale of English, the Japanese characters were single-width in the Windows Console. After changing the system locale, the characters become double-width, even with Lucida Console, where they're rendered as a featureless box. The obvious guess is that double-width characters take up two console cells, so Windows reports the same Unicode codepoint for each cell. That could create a problem (i.e. how does winpty detect two Japanese characters in the English locale versus a single Japanese character in the Japanese locale?). I'll need to do some more investigating. |
The TrueType Japanese font is known as MS Gothic. |
Nevermind. According to https://msdn.microsoft.com/en-us/library/cc194788.aspx, these ideas are equivalent in a double-byte character set, such as Shift-JIS. The commit that broke things was probably 72557cb. The fix will probably involve examining the |
Thanks, it looks your guess is correct. The following patch did it here (Win10 and CP932 codepage): diff --git a/agent/Terminal.cc b/agent/Terminal.cc
index d1cdfd4..5b0622a 100644
--- a/agent/Terminal.cc
+++ b/agent/Terminal.cc
@@ -143,6 +143,8 @@ void Terminal::sendLine(int line, CHAR_INFO *lineData, int width)
length = termLine.size();
m_remoteColor = color;
}
+ if (lineData[i].Attributes & COMMON_LVB_TRAILING_BYTE)
+ continue;
// TODO: Is it inefficient to call WideCharToMultiByte once per
// character?
char mbstr[16]; |
Hmm, it seems that this patch is not enough. One apparent issue is a character "ー" (U+30FC) . I could temporary fix this by disabling the call to m_console->setSmallFont() in Agent constructor and let it use MS Gothic in my environment, but apparently it is not a satisfactory thing to do... |
I'll probably make the choice of font depend upon the code page. There's a table in the registry at The code page can change while the console is open (e.g. I'm currently documenting everything I've learned from studying how the console works with code pages and fonts. It's full of complications. For example, |
Apparently the situation is more complicated than this. In Raster Font and MS Gothic, U+30FC is always drawn/rendered as full-width. In Lucida Console and Consolas, the character is always drawn/rendered as half-width. In terms of the data model (e.g. ReadConsoleOutputW, selection), the character is half-width or full-width depending upon the font size and OS version. I tested Lucida Console, Consolas, and MS Gothic, with all font sizes between 1px tall and 50px tall. Results:
winpty currently picks Lucida Console 6px as its first choice, which is in the broken list for all the OS versions I tested. If I'm careful to use 5px or 7px for MS Gothic, then winpty should handle U+30FC correctly on all OS versions. If I instead choose 6px MS Gothic, it will fail on Win8 up to Win10 new mode. In the Windows console properties dialog, when I choose MS Gothic, there is a box listing possible font sizes. It's interesting that the first font sizes in that box overlap with the sizes that don't work: 6, 8, 10, 12, 14, 16, 18, 20, 24. This Windows behavior makes no sense to me. At least the new console in Win10 works. I wonder if there are other characters with this problem. |
@nu774 What version of Windows are you using? |
I'm using Windows 10. |
Like this:
I guess this is caused by a recent commit on this year. Didn't happen previously.
The text was updated successfully, but these errors were encountered: