如何在Java中查找某个字体是否正确安装在机器上 [英] How to find, with Java, if a certain font is installed correctly on a machine
问题描述
现在我的一些程序显示英文和中文,如下所示:Enter |输入(这里的汉字也意味着进入),但是如果用户没有在他的机器上正确安装中文字体,他会看到这样的:Enter | [] [],我的问题是:在Java中如何检测这些字符是否会在某台机器上正确显示,如果没有,只显示Enter,如果是,则显示Enter |输入。
/ p>
java.awt.GraphicsEnvironment.getAvailableFontFamilyNames()
可以给你一个当前系统上安装的可用字体列表。您也可以使用 java.awt.GraphicsEnvironment.getAllFonts()
来获取 java.awt.Font
对象。然后,可以使用 java.awt.Font.canDisplay(int)
来检查是否可以显示一个Unicode字符在该字体中( int
是多字节字符的整数表示形式)。 I have a PC notebook running Win Vista, when I first bought it, certain Chinese fonts won't show up, I could only see rectangles, but I played with the control setting for a while, changed some properties, and now it shows Chinese fonts correctly, but I don't remember what I did.
Now some of my programs displays both English and Chinese, something like this : "Enter | 输入" (The Chinese here also means enter), but if a user doesn't have Chinese fonts installed properly on his machine, he will see something like this : "Enter | [][]", my question is : in Java how to detect if those characters will show up correctly on a certain machine, if not, just display "Enter", if it is, show "Enter | 输入".
Frank
java.awt.GraphicsEnvironment.getAvailableFontFamilyNames()
can give you a list of the available fonts installed on the current system. You could also use java.awt.GraphicsEnvironment.getAllFonts()
to get java.awt.Font
objects.
Then, you can use java.awt.Font.canDisplay(int)
to check whether a Unicode character can be displayed in that font (where the int
is the integer representation of the multibyte character).
这篇关于如何在Java中查找某个字体是否正确安装在机器上的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!