gpt4 book ai didi

java - 获取异常 FontFormatException Unsupported sfnt resources/fonts/OpenSansEmoji.ttf

转载 作者:塔克拉玛干 更新时间:2023-11-01 22:25:09 27 4
gpt4 key购买 nike

我在资源/字体文件夹中有 OpenSansEmoji.ttf 和其他字体,如 Proxima Nova Regular.otf,对于 Proxima Nova Regular.otf/Proxima Nova Alt Light.ttf,它没有给我异常(exception),OpenSansEmoji.otf 也没有,但是对于 OpenSansEmoji.ttf,它给了我以下异常,我该怎么办?

 Feb  25, 2015 10:37:31 AM java2d.utils.FontUtils getFont
SEVERE: null
java.awt.FontFormatException: Unsupported sfnt resources/fonts/OpenSansEmoji.ttf
at sun.font.TrueTypeFont.init(TrueTypeFont.java:522)
at sun.font.TrueTypeFont.<init>(TrueTypeFont.java:191)
at sun.font.SunFontManager.createFont2D(SunFontManager.java:2460)
at java.awt.Font.<init>(Font.java:614)
at java.awt.Font.createFont(Font.java:1023)
at java2d.utils.FontUtils.getFont(FontUtils.java:53)
at java2d.CrushCard.drawMessageString(CrushCard.java:311)
at java2d.CrushCard.createCrushCard(CrushCard.java:134)
at java2d.Java2D.main(Java2D.java:43)

我的代码在这里

  try {
FontUtils.registerFonts(fonts);
} catch (IOException | FontFormatException ex) {
Logger.getLogger(Java2D.class.getName()).log(Level.SEVERE, null, ex);
}



public static void registerFonts(List<String> paths) throws IOException, FontFormatException {

for (String path : paths) {
String fName = "resources/fonts/" + path;
GraphicsEnvironment ge = GraphicsEnvironment.getLocalGraphicsEnvironment();
ge.registerFont(Font.createFont(Font.TRUETYPE_FONT, new File(fName)));
}
}

最佳答案

根据维基百科,http://en.wikipedia.org/wiki/SFNT是一种字体的容器格式,由 TrueType 等使用。但是,Java 不支持所有 SFNT 字体,仅支持 TrueType。

来自 sun.font.TrueTypeFont javadoc:

TrueTypeFont is not called SFntFont because it is not expected to handle all types that may be housed in a such a font file.

基本上这意味着您的字体虽然以 .ttf 文件结尾,但实际上不是 TrueType,您不能使用它。可能是它是 OpenTypeFont,Java 不支持它。您可以尝试转换字体;谷歌显示了许多可能性。

关于java - 获取异常 FontFormatException Unsupported sfnt resources/fonts/OpenSansEmoji.ttf,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28711720/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com