views:

74

answers:

2

I have an english Windows 2003 server with asiatic language support activated. The two only fonts available for the command window (cmd settings) are raster and lucida console. Neither the one nor the other display the Kanji correctly (displayed as question mark).

Is there a solution to get them displayed? Is there some transformation I must do in my application before writing out to the console?

I am writing UTF8 out at the moment, what works well also for some non ASCII characters (like öäüß). The source code writing to the console has the correct data (the Kanji can be viewed in the debugger correctly). If it matters, I am writing the app in C#.

+2  A: 

If you find a font that will display the Kanji character set, you can add that font to the cmd Settings by adding values under this Registry key:

HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Console\TrueTypeFont\

Values:

Name: 00 Data: Consolas

I've done this before but found this reference on SuperUser: http://superuser.com/q/55318

Hope this helps

paludarium
Good tip. Unfortunately it didn't work out for me and the Kanjis. Note that it only fixed fonts like "Courier New" appear in the selection for the console. Setting not fixed fonts in the registry has no effect. I think it is maybe due to some links in the fonts. In the case of "Arial Unicode MS" it switched to "Mincho" in the character map when I select the Kanji range... Strange stuff :-)
jdehaan
On the one machine Consolas was not available. I tested on another one and this font seems really to work well. Just the legal impact on the font use (reserved for VS Studio licensees) is a bit problematic... At least on the development machine It works. I just have to find a free font that does the same.
jdehaan
`HKEY_CURRENT_USER\Console` also provides interesting tweaking possibilities
jdehaan
It really turns out that despite right encoding, the console could not always display the chars correctly (ending with boxes or interrogation marks) depending on the font used. So the font setting is essential for the stuff to work properly.
jdehaan
Thank you for the points, being new here I really need them.
paludarium
+1  A: 

How is your application writing output? The C byte-based stdio calls like printf won't support UTF-8 on Windows unless you have specifically set the console to use UTF-8 encoding by saying chcp 65001 && somecommand (and even then there are problems).

Without chcp, the console will be using the Windows installation's default code page, in this case cp1252, and writing in kanji will be impossible even if the console font you're using has glyphs for it.

If you want to write Unicode to the console reliably you would have to use character-based interfaces like wprintf.

bobince
+1, thanks for this hint too, it seems indeed to be a codepage issue in the end. I thought cmd.exe was a unicode program but actually it appears not to be. The things that can be tuned in the registry (see answer from paludarium) show how to bind the codepage to the actual used font... I begin to see light at the end of the tunnel!
jdehaan
`cmd.exe` *can* display Unicode characters, but only if the process it is running passes it Unicode, via `wprintf` or Win32 `WriteConsoleW`. Most command-line software, however, uses the C stdio byte-based output functions like `printf`, so you'll be limited by the codepage. It is very unfortunate that on Windows the system default codepage can never be 65001 (UTF-8), and that there are some serious bugs with setting `chcp 65001` at all. Every other OS has standardised on UTF-8, allowing any old byte-based console app to do something sensible with Unicode.
bobince
`Console.OutputEncoding = Encoding.UTF8;` AND setting the font to "Consolas" works out. However I get weird errors on the font size when I go to the console font configuration again...
jdehaan
I hope you don't mind too much I accorded the accept to paludarium. Actually both combined answers are correct, but I had to make a choice. I've chosen the one with the lesser SO score.
jdehaan