1

I am outputting unicode characters to the console on Windows and the output is as expected when I manually change the font to Lucidia Grande. But my question is, how can Python, Ruby etc ... output unicode characters to the Windows console using the default font? I thought the default font didn't support all of the unicode characters?

Francis
  • 107
  • 3
  • 10

1 Answers1

1

how can Python, Ruby etc ... output unicode characters to the Windows console using the default font?

They can't and don't display all Unicode characters. The default console font aka “Raster Fonts” maps to a .fon file with glyphs for the characters in your locale's DOS code page. For Western European installs that is code page 850. You do get some accented letters and other non-ASCII characters in this code page, but anything else from wider Unicode will be displayed as ?.

In reality even if you change to a vector font you are still limited to a single code page when you run programs that use the MS C runtime's implementation of the standard library I/O functions (which Python and Ruby do). You get more of a choice in that you can use chcp to change to a wider range of code pages than “Raster Fonts” has support for, but you still can't get all of Unicode this way.

(In principle you should be able to chcp 65001 to get UTF-8, but there are serious bugs in the Windows implementation of this that usually make it unusable. Or chcp 65000 for UTF-16, but as that's not an ASCII superset it tends to break stdio apps including Python/Java etc.)

bobince
  • 498,320
  • 101
  • 621
  • 807
  • Hi, I used the GetConsoleCp() function and found the code page to be 850 which, as you said earlier has some accents. So why then when I try to cout the letter "á" do I get this a weird letter? Here's a link to a screenshot so you can see. [link](https://dl-web.dropbox.com/get/screenshot.png?_subject_uid=295255838&w=AAB7mNwAHgEPW5RU8TB4yF4M8dfc1-p0eQBq1UU9AjEpug) Inbetween the two 850's is supposed to be the letter "á" but as you'll see its not. Is there any way around this? Thanks! – Francis May 19 '14 at 13:41
  • 1
    Screenshot link is broken but my guess is your source code is probably itself compiled with the wrong encoding. To avoid source encoding problems you could write it as eg `std::cout << '\xA0'` (as `á` is byte 160 in cp850). – bobince May 19 '14 at 14:18
  • Thanks for your answer. It outputs correctly now. Just one question. How do I use the SetConsoleOutputCP() function? Because every time I use it the code page doesn't actually change to the one I set it to. Thanks! – Francis May 19 '14 at 15:24
  • For information about interaction between Python and Windows console, see http://stackoverflow.com/a/17901210/2626157. As said in the answer this has nothing to do with fonts. – user87690 Jul 30 '14 at 10:31