I have OpenSansEmoji.ttf and another fonts like Proxima Nova Regular.otf in the resources/fonts folder,for Proxima Nova Regular.otf / Proxima Nova Alt Light.ttf it is not giving me exception and neither for OpenSansEmoji.otf but for OpenSansEmoji.ttf it is giving me following exception what should I do?
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)
My code is here
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)));
}
}
According to Wikipedia, http://en.wikipedia.org/wiki/SFNT is a container format for fonts, used by TrueType among others. However, Java doesn't support all SFNT fonts, only TrueType.
From the 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.
Basically this means that your font, while having a .ttf file ending, isn't actually TrueType and you can't use it. It could be that it is an OpenTypeFont, which isn't supported by Java. You could try converting the font; google shows a number of possibilites.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With