0

I want to start by saying I know how to print Unicode characters to console using _setmode(_fileno(stdout), _O_U16TEXT). The problem I have is with printing Unicode characters that are "non-standard". For example, when I try to print ▁ ▂ ▃ ▄ ▅ ▆ ▇ █ ▇ ▆ ▅ ▄ ▃ ▁ using wprintf, it returns this:

Picture showing output were all but half and full blocks are question marks

The project is set to "Unicode Character Set" and visual studio is showing the characters fine when showing them from file.

I found the answer and put it below

Norzka
  • 47
  • 3
  • 10
  • I would guess that the characters are not encoded correctly in your string literal. – john Jul 22 '22 at 18:16
  • 2
    BTW there is no such thing as a non-standard Unicode character. Unicode is a standard. What are the code points for the characters you are trying to print? – john Jul 22 '22 at 18:17
  • Is this what you were looking for wchar_t? –  Jul 22 '22 at 18:22
  • @john the code points in hex are `\x2581 \x2582 \x2583 \x2584 \x2585 \x2586 \x2587 \x2588 \x2587 \x2586 \x2585 \x2584 \x2583 \x2582 \x2581`. and I know there isn't a "non-standard" unicode character but it just seemed as if it was characters which are specialized or something like that – Norzka Jul 22 '22 at 19:01
  • @apetrai I used wstring and also direct print which both use wchar_t – Norzka Jul 22 '22 at 19:01
  • 1
    **1st** do you mean `\u2581 \u2582 \u2583 …` [escape sequences](https://en.cppreference.com/w/cpp/language/escape) instead of `\x2581 \x2582 \x2583 …`? **2nd** choose another font for your terminal, e.g. https://github.com/microsoft/cascadia-code – JosefZ Jul 23 '22 at 13:48
  • 1
    yes, I mean `\u` instead of `\x`. – Norzka Jul 24 '22 at 15:47

2 Answers2

4

Although Unicode is a standard, not all glyphs are supported by all fonts.

For example, the glyph "▅" at code point U+2585 (Lower five eighths block) is not present in majority of Windows console fonts (like Consolas, Courier New, Lucida Console). See also: Why isn't there a font that contains all Unicode glyphs?

You could instead configure your console to use either MS Gothic or NNimSun font. However, be prepared for other oddities then (for example, it seems MS Gothic displays a yen sign "¥" instead of a backslash "\", see: Why is Windows 10 displaying \ ‎as ‎¥ on the command line?).

heap underrun
  • 1,846
  • 1
  • 18
  • 22
  • 2
    This "not all glyphs are present in all fonts" is supposed to be handled via font fallback, however even the new Windows Terminal doesn't (yet) support it. Very relevant: https://github.com/microsoft/terminal/issues/2664 – Ben Voigt Jul 22 '22 at 19:15
  • Would there be any way to force to be a different font on start up so the program is portable and doesn't require the user to set anything up – Norzka Jul 22 '22 at 19:17
  • 1
    @Noscka [`SetCurrentConsoleFontEx()`](https://learn.microsoft.com/en-us/windows/console/setcurrentconsolefontex) – Remy Lebeau Jul 23 '22 at 00:50
0

From what I have found so far. there is no easy work around except for using another font which does include those characters. What I ended up doing was just editing the font using Fontlab. If anyone else ends up follow my footsteps. once you finish editing:

  1. change the font name unless you want to overwrite the existing font (wouldn't recommend)
  2. EXPORT AS TTF

I don't know why but when exporting as otf, the console shows the wrong characters.

Norzka
  • 47
  • 3
  • 10