views:

65

answers:

2
+1  Q: 

C# console font

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
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
Thanks! Once upon a time, text seemed so simple...
Dave Markle
+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
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
@Dervin: The OP is trying to do something that isn't directly supported.
Reed Copsey
I do not think so as in C# every string is string of unicode characters.
Mojmi
@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
@Reed Copsey: but e.g. Console.Write('\u2563'); works just fine..
Mojmi
@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
I upvoted because it's true, however there is also a unicode code page (65001).
Vilx-
@Vilx: There is - and it will work, mostly. You can make this work, but as I said, it's problematic at times...
Reed Copsey
@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
@Mojmi: The code page can differ on every system. It's typically based on the locale of the system.
Reed Copsey
@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
@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
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