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.
createFont(Font. TRUETYPE_FONT, new File("A. ttf"))); After this step is done, the font is available in calls to getAvailableFontFamilyNames() and can be used in font constructors.
OTF is more likely to be a “better” font, as it supports more advanced typesetting features (smallcaps, alternates, ligatures and so on actually inside the font rather than in fiddly separate expert set fonts).
The easiest way to do that is to hit command+T or alt+t on windows then select the “Opentype” tab on the window that pops up. You can also go to Window>Type>Opentype.
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.
I don't think there is Open Type Font support in java (not free atleast), iText claimed to have such support, tried it a few month ago and it didn't work, what worked for me is a program called FontForge which I used to create a ttf from the otf which I then used.
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