100字范文,内容丰富有趣,生活中的好帮手!
100字范文 > java 找不到字体_从Java中的TTF文件加载一些TrueType字体会导致FontFormatException

java 找不到字体_从Java中的TTF文件加载一些TrueType字体会导致FontFormatException

时间:2019-05-19 09:38:43

相关推荐

java 找不到字体_从Java中的TTF文件加载一些TrueType字体会导致FontFormatException

我试图从我的系统上的TTF文件创建一个

java.awt.Font实例,但只有一些字体能够加载而不会出错.下面的代码是我在网上找到的一些测试代码.在我的系统上运行时,它能够成功加载285种字体(例如Arial.ttf),但是在83种字体上失败(例如AmericanTypewriter.ttf).

所有错误都是FontFormatException形式:找不到没有嵌入原因的字体名称.

java.awt.Font和格式兼容性是否存在已知问题?经过谷歌搜索后我找不到任何东西.

public static void main(String[] args) {

String rootPath = "/Library/Fonts";

File root = new File(rootPath);

if (root.canRead()) {

String[] fontFiles = root.list();

Font font = null;

for (String fontFile : fontFiles) {

try {

System.out.println(fontFile);

font = Font.createFont(Font.TRUETYPE_FONT, new File(root + "/" + fontFile));

System.out.println(font);

} catch (Exception e) {

e.printStackTrace();

}

}

}

}

我的环境是Java 7,OS X Mavericks(10.9.1).

java version "1.7.0_40"

Java(TM) SE Runtime Environment (build 1.7.0_40-b43)

Java HotSpot(TM) 64-Bit Server VM (build 24.0-b56, mixed mode)

这里的任何帮助将不胜感激.

java 找不到字体_从Java中的TTF文件加载一些TrueType字体会导致FontFormatException:找不到字体名称...

本内容不代表本网观点和政治立场,如有侵犯你的权益请联系我们处理。
网友评论
网友评论仅供其表达个人看法,并不表明网站立场。