0

I'm creating a terminal based draughts application in Java, and I'd like to use the actual draughts characters from the Miscellaneous Symbols in UTF-8. However, they seem to not align nicely with standard Latin-1 (ASCII) characters in my terminal:

    +---+---+---+---+---+---+---+---+---+---+
 0  |   | ⛂ |   | ⛂ |   | ⛂ |   | ⛂ |   | ⛂ |
    +---+---+---+---+---+---+---+---+---+---+
 1  | ⛂ |   | ⛂ |   | ⛂ |   | ⛂ |   | ⛂ |   |
    +---+---+---+---+---+---+---+---+---+---+
...

 9  | ⛀ |   | ⛀ |   | ⛀ |   | ⛀ |   | ⛀ |   |
    +---+---+---+---+---+---+---+---+---+---+

I realize this has a lot to do with the particular font this is rendered in, but is there a way to align these in such a way that the vertical bars would align in any font?

Mr. Wrong
  • 500
  • 7
  • 21
  • Don't think it's possible to do this in _any_ font because lots of them are not fixed-width. That said, since you are doing this in a terminal, I think it's reasonable to assume the user will use a [monospaced font](https://en.wikipedia.org/wiki/Monospaced_font). – jingx Oct 24 '21 at 19:58
  • The font used above is already monospaced, which is why I was surprised to find the higher UTF-8 symbols not aligning. – Mr. Wrong Oct 24 '21 at 20:15
  • Sorry, I misread what you meant by "any font". Come to think about it, not every font has all the characters, especially these extended symbols. IIUC there is a fallback font that catches all characters not found in the primary. Now this gets into terminal settings though... – jingx Oct 25 '21 at 01:28

1 Answers1

1

Unlike more widely used monospaced fonts such as Courier New which do not properly monospace some special characters, JuliaMono does what you need:

JuliaMono is a monospaced typeface designed for programming and in other text editing environments that require a wide range of specialist and technical Unicode characters. It was intended as an experiment to be presented at the 2020 JuliaCon conference in Lisbon, Portugal.

JuliaMono is:

free

distributed with a liberal licence

suitable for scientific and technical programming as well as for general purpose hacking

full of Unicode goodness

easy to use, simple, unquirky, friendly, and approachable

available for MacOS, Unix, and Windows

You can download the zip file from GitHub. After unzipping the download, there are 16 forms of the font (e.g. JuliaMono-LightItalic.ttf, JuliaMono-ExtraBoldItalic.ttf, etc.) that you can choose to install.

I just installed JuliaMono-Regular.ttf, then selected it in Windows Notepad and pasted in your sample data. The monospacing worked fine; Unicode's Miscellaneous Symbols were rendered with the same width as ASCII characters such as vertical bar. Here's a screenshot:

Use of Julia Mono

One other point: you don't mention your environment, but if you are on Windows and you run your application from the command line you will probably need to set your code page as well. Note in the screen shot below that my default code page is 437, and it cannot render the Miscellaneous Symbols. To fix that, as well as setting your font to some variation of JuliaMono, also ensure that your code page is set to UTF-8 using chcp 65001:

CommandLine

skomisa
  • 16,436
  • 7
  • 61
  • 102
  • The reason I didn't specify my OS is that it is irrelevant since soving it for myself is not solving it for my users, which could use any OS. – Mr. Wrong Oct 30 '21 at 08:28
  • 1
    You should make that very clear in your question in that case. I've answered your question for a Windows environment, where it is essential to use `chcp` for the Miscellaneous Symbols to render in addition to an appropriate font. The situation may be different for other operating systems. – skomisa Oct 30 '21 at 17:21