How to use Open Type Fonts in Java?

HaBaLeS picture HaBaLeS · May 16, 2009 · Viewed 19.1k times · Source

Is there a way to read Open Type fonts in Java the same way as I do with TrueType fonts?

This works perfectly for TTF but I did not figure out yet how to do the same with Open Type fonts.

Font f = Font.createFont( Font.TRUETYPE_FONT,
new FileInputStream("f.ttf") );

Please note I cannot relay on installed fonts. I provide the font with my program but don't want to install it system wide.

Answer

christopheml picture christopheml · Jul 13, 2009

Java OpenType font support depends on your OS and JDK version.

Prior to Java 6, you can only use TrueType flavored OpenType fonts. With Java 6 you can use all OpenType fonts but you won't benefit from advanced typographic features like ligatures.