Search code examples
c++windowscmd

Print Braille characters to cmd c++


For one programm I need to output Braille characters to a console.

I found a way to output unicode characters using code like:

#include <iostream>
#include "fcntl.h"
#include "io.h"

using namespace std;

int main() {
    _setmode(_fileno(stdout), _O_U16TEXT);
    wcout<<L"ĐĄßĞ"<<endl;
    return 0;
}

And changing font of cmd to Lucida Console.

However, there is a problem that Braille characters aren't displayed is such a way. Actually, I can't even copy and paste them to code, because they appear blank. In Linux everything works(I can see, copy and paste these characters), but I need Windows application.

I guess there is some posiblity to use codes of this characters, I tried this way, but had no success.

Can anybody help me with this task?


Solution

    1. You'll need to install a monospaced font that supports Unicode. To try this out, I used FreeMono.ttf from http://www.wazu.jp/gallery/Fonts_Braille.html.

    2. After installing the font, edit the registry to add the font to the console's list of fonts: HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Console\TrueTypeFont. There should be a 0 and 00 entry for Lucida Console and Consolas. Add another zero to the Value name for each font you want. I added 000 and set to FreeMono.

    3. Restart the console, then edit its properties to choose the font. On Windows 10, you may have to enabled "Legacy Mode" in the console properties and restart the console before the font shows up. After selecting it, you can turn legacy mode back off again.

    Here's the code I used:

    #include <iostream>
    #include "fcntl.h"
    #include "io.h"
    
    using namespace std;
    
    int main() {
        _setmode(_fileno(stdout), _O_U16TEXT);
        wcout<<L"\u2876\u2877\u2878"<<endl;
        return 0;
    }
    

    Output (screenshot):

    Screenshot of functional Braille output

    Note: The font I chose didn't display ASCII nicely, so I don't recommend it, but the Braille was fine.