Java,unicode和字体
时间:2020-03-06 14:48:27 来源:igfitidea点击:
我查看了Java文档,并在网上搜索有关Java对具有特定字体(例如Monospace)的国际字符的支持的信息,但未能获得明确的具体答案。
在Java 1.4和Java 1.5 / 1.6之间进行了更改。例如,在Java 1.4中,如果将JTextArea上的字体设置为Monospace,它将无法处理外来字符(改为获取矩形),但是在Java 1.5 / 1.6中,它似乎可以正常工作。
这些差异/改进的支持是否在任何地方都有明确记录?
谢谢
解决方案
来自国际化增强功能:
Multilingual Text Rendering To render multilingual text, using logical fonts, 2D now takes advantage of installed host OS fonts for all supported writing systems. For example, if you run in a Thai locale environment, but have Korean fonts installed, both Thai and Korean are rendered. The JRE now also automatically detects physical fonts that are installed into its lib/fonts/fallback directory and adds these physical fonts to all logical fonts for 2D rendering. Use of Unicode APIs on Windows AWT now uses the Unicode APIs on Windows 2000/XP. As a result, some of its components can handle text without being restricted by Windows locale settings. For example, AWT text components can accept and display text in the Devanagari writing system regardless of the Windows locale settings. (emphasis mine)
这些字符有多"外来"?大多数基于拉丁语的字体至少可以处理ISO-8859-1上半部分中的重音字母和其他字符,但是我认为我们不能合理地依靠它来支持其他任何内容。
最好的选择通常是让用户从支持的字体列表中进行选择,我们可以从底层操作系统中检索这些字体。如果无法做到这一点,或者我们不愿意这样做,可以采用CSS方法:遍历可接受的字体列表,并使用找到的第一个字体。
要填充列表,只需使用Google表示"程序员字体"或者"等宽字体"。我从不喜欢Java的任何逻辑字体,尤其是Monospace,它在Windows机器上是Courier或者Courier New。几年前,我不再使用它。