Hi, I cannot find out which font the console app uses by default? Is it guaranteed that everyone has that font (when running this .NET app)? Want to display some unicode chars and need to be sure they are present within that font. Thanks
+1
A:
You can tell what font is being used by reading the registry value "0" from this key:
HKLM\Software\Microsoft\Windows NT\CurrentVersion\Console\TrueTypeFont
Dave Markle
2010-10-19 19:03:58
That's only the default console font for locales that don't have exceptions. Some languages define other values. For example if you have a Windows install with the East Asian internationalisation files installed, you'll see the value `932`: `*MS ゴシック`, `*MS Gothic`. This means that when the system codepage is 932 (the Windows shift-JIS knock-off), as it is on a Japanese system, the font will be MS Gothic instead of the font listed in `0`. When you change the codepage with `chcp` you can even see it switch fonts.
bobince
2010-10-20 01:34:57
Thanks! Once upon a time, text seemed so simple...
Dave Markle
2010-10-20 03:07:16
+3
A:
I strongly recommend avoiding the Console if you want to use Unicode characters. There are many issues with trying to get the Console to display Unicode correctly.
Unicode is not directly supported in Console output. The best option is typically to set the console's code page, which will require P/Invoke.
That being said, a GUI solves all of these issues, in a much nicer fashion. If you need Unicode output, I'd recommend a simple GUI.
Reed Copsey
2010-10-19 19:04:47
You can vote this down - but wait until you actually try to write unicode to the console - it's incredibly problematic... Even if you specify a TrueType font for the Console, the code page in effect tends to mess up unicode output.
Reed Copsey
2010-10-19 19:07:44
@Dervin: The OP is trying to do something that isn't directly supported.
Reed Copsey
2010-10-19 19:08:01
@Mojmi: True. And every string in C# uses Unicode characters. However, the Console is using a native API (http://msdn.microsoft.com/en-us/library/ms682087(VS.85).aspx) that predates C#, and doesn't support unicode output directly.
Reed Copsey
2010-10-19 19:09:34
@Mojmi: It depends on the character, and whether it's handled in the currently selected code page. There are only 256 characters at a time that "work just fine". Read the link I posted in my question, and it will explain the issue.
Reed Copsey
2010-10-19 19:12:42
I upvoted because it's true, however there is also a unicode code page (65001).
Vilx-
2010-10-19 19:14:23
@Vilx: There is - and it will work, mostly. You can make this work, but as I said, it's problematic at times...
Reed Copsey
2010-10-19 19:15:30
@Reed Copsey: Well on the link I cannot see the issue exactly. But if I try specific character, can I be sure it will be displayed on different PCs as well if there has to be .NET installed? Or the code page can be different too
Mojmi
2010-10-19 19:25:27
@Mojmi: The code page can differ on every system. It's typically based on the locale of the system.
Reed Copsey
2010-10-19 19:26:11
@Reed Copsey: Thanks. Well, that is not good for me..But still there are lot of C# text games using unicode characters and working fine. Maybe they just rely on the the same culture of the system
Mojmi
2010-10-19 19:28:41
@Mojmi: Yeah - it'll *probably* work everywhere. If you want to make sure that things always work, and need unicode, a GUI really is nicer...
Reed Copsey
2010-10-19 19:35:43
The native-UTF-16-string `WriteConsoleW` interface does work for all characters and codepages. It's just the byte-string `WriteConsoleA` interface (and the MS C runtime's implementation of the stdio `printf`-etc functions that rely on `WriteConsoleA`) that end up in ‘ANSI’ with all its horrid system codepage problems. (And `chcp 65001` to get UTF-8 doesn't *quite* completely work, though it's good enough for many uses.) However, even if you can write Unicode there are still big problems with fonts; locales can use different default console fonts, so you can't really rely on anything.
bobince
2010-10-19 23:17:31