1
votes

On a Windows (10) box, why can I print the 'black flag' (U+2691) character in certain places but not others (cmd.exe in particular)?

Update with proposed hints in comments (no answers yet): - [From Kevin] CMD.exe Unicode support is dubious (unspecified, but write off the issue I am having as strange CMD.exe behavior) - [From Mark] The process should write to the ConsoleAPI instead of stdout. - [From Mr. Lister] Change the font.

I changed the font in Webstorm. It was using monospaced, and displayed the flag properly. I switched to Consolas, Lucida Sans, and Courier New and it worked in all of them. I looked at the list of supported unicode chars for Lucida Console and indeed, U+2691 is not on there. So Webstorm might have some fallback mechanism to support the character.

I ran ConEmu, and set the base font to Lucida Console, and Alternative font to DejaVu Sans, which I downloaded from here. I had to adjust the Unicode range manually, setting it to 2013-3000. And voila, the black flag showed. So although part one is now (kindof) solved, I still don't really know what is going on with fonts vs graphics and code pages here. I think the codepage is a red herring when dealing with some unicode... So please, if someone has anything definitive, I would love a proper answer. ;-)

Note, I have the cmd.exe font set to Lucida Console and Current Code Page to (UTF-8) 65001. I have also tried other fonts...and chcp 1252. And yes, I have read the Spolsky post, which is excellent. I think what I was missing is what Kevin said in the comment (cmd.exe does not have proper Unicode support) and what Mark said about bypassing stdout. This explains cmd.exe but would love to know more about VS vs VS Code vs NP++...

I can see the character fine in chrome:

http://graphemica.com/⚑
http://graphemica.com/%E2%9A%91

I can see it fine in one of these:

  • Office (Word, Outlook)
  • WebStorm
  • Visual Studio

However, I cannot see it here (shows up as a box):

  • Notepad++
  • Visual Studio Code
  • cmd.exe

If I run this in node:

console.log('\u2691:', '\u2691');
console.log('Flag:', '⚑')

It just dumps boxes (which when I copy and paste in here are fine).

Then there are other characters like: heavy check mark (U+2714)

http://graphemica.com/%E2%9C%94 http://graphemica.com/

Which 'show up' in Visual Studio Code (which could not show the flag) but wont show up in cmd.exe.

There appear to be a lot of moving parts here: Unicode, char codes, code pages, fonts, and lots more.

Can someone help me sort this out? What exactly is going on here?

  1. Why does the character display in some places and not in the other?

  2. Is there anything I can do to show the characters in cmd.exe?

1
Start here and know that cmd.exe does not have proper Unicode support.Kevin
Showing Unicode characters in cmd.exe requires using the console API directly and bypassing standard output.Mark Ransom
Ths issue is with the font. Lucida Console does not contain the ⚑ or ✔ characters. If you must use cmd.exe, choose a font that does. Or check with charmap.exe which characters Lucida Console contains and use one of those.Mr Lister
To answer your comments, some programs are better in displaying characters than others. For instance, graphical programs do this by switching to another font. Text mode programs have no such functionality!Mr Lister
@MrLister is right. You need to choose appropriate font manually to be used by cmd, Notepad etc. (e.g. DejaVu Sans Mono contains much more character glyphs than commonly used Courier or Lucida Console monospace fonts).JosefZ

1 Answers

1
votes

OK, it appears as if @josefZ got me the closest to the answer, so @josefZ if you cut and paste my answer into your own, I will delete mine. ;-)

These were the answer I was looking for (I still wish there was more about font fallback and font vs code page relationships):

It appears that the reason you cannot get a U+2691 is that the Font does not support it, not a code page issue (at least in my case).

Apparently some programs have backup fonts for pseudographics.

  • WebStorm was not configured to do so (I had no secondary font enabled) but it does so internally.

  • Visual Studio Code did not have this setup, but when I switched to Deja Vu Mono, it displayed fine.

Specifically, to allow you to use the black flag in the cmd.exe console: 1. Download the Deja Vu Mono font. 2. Unzip and install it (select all, right click, choose install) 3. Follow these instructions to make it available in cmd.exe. 4. Go to preferences of cmd.exe and choose the font.

Alternatives: 1. Use ConEmu and set the pseudographics font to Deja Vu Mono. 2. Don't forget to manually set the unicode range to include the range needed (2691, in this case, but I set it to: Pseudographics: 2013-3000)

Hope this helps.