简体   繁体   English

Java:如何在纯文本中对齐 UTF 杂项符号

[英]Java: how to align UTF Miscellaneous Symbols in plain text

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.我正在用 Java 创建一个基于终端的草稿应用程序,我想使用 UTF-8 中杂项符号中的实际草稿字符。 However, they seem to not align nicely with standard Latin-1 (ASCII) characters in my terminal:但是,它们似乎与我终端中的标准拉丁 1 (ASCII) 字符不太匹配:

    +---+---+---+---+---+---+---+---+---+---+
 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?我意识到这与渲染的特定字体有很大关系,但是有没有办法以垂直条以任何字体对齐的方式对齐这些字体?

That's good.那挺好的。 You can use a monospaced character on your terminal to correctly match any printed caracter.您可以在终端上使用等宽字符来正确匹配任何打印的字符。 This is courier new for example例如,这是新的快递

在此处输入图片说明

Unlike more widely used monospaced fonts such as Courier New which do not properly monospace some special characters, JuliaMono does what you need :与更广泛使用的等宽字体不同,例如Courier New不能正确等宽某些特殊字符, JuliaMono 可以满足您的需求

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. JuliaMono 是一种等宽字体,专为需要大量专业和技术 Unicode 字符的编程和其他文本编辑环境而设计。 It was intended as an experiment to be presented at the 2020 JuliaCon conference in Lisbon, Portugal.它旨在作为一项实验,在 2020 年葡萄牙里斯本 JuliaCon 会议上展示。

JuliaMono is: JuliaMono 是:

 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 .您可以从 GitHub 下载 zip 文件 After unzipping the download, there are 16 forms of the font (eg JuliaMono-LightItalic.ttf , JuliaMono-ExtraBoldItalic.ttf , etc.) that you can choose to install.下载解压后,有16种字体(如JuliaMono-LightItalic.ttfJuliaMono-ExtraBoldItalic.ttf等)可供选择安装。

I just installed JuliaMono-Regular.ttf , then selected it in Windows Notepad and pasted in your sample data.我刚刚安装了JuliaMono-Regular.ttf ,然后在 Windows 记事本中选择它并粘贴到您的示例数据中。 The monospacing worked fine;等距效果很好; Unicode's Miscellaneous Symbols were rendered with the same width as ASCII characters such as vertical bar. Unicode 的杂项符号以与 ASCII 字符(例如竖线)相同的宽度呈现。 Here's a screenshot:这是一个屏幕截图:

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.另一点:您没有提到您的环境,但是如果您使用的是 Windows 并且您从命令行运行您的应用程序,您可能还需要设置您的代码页。 Note in the screen shot below that my default code page is 437, and it cannot render the Miscellaneous Symbols .请注意,在下面的屏幕截图中,我的默认代码页是 437,它无法呈现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 :要解决这个问题,以及将您的字体设置为JuliaMono 的某些变体,还要确保使用chcp 65001将您的代码页设置为 UTF-8:

命令行

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM