且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

如何在Java中使用OpenType字体?

更新时间:2023-02-21 10:02:22

我不认为有在java中打开类型字体的支持(不是免费的atleast),iText声称有这样的支持,几个月前试过了,它不起作用,对我来说是一个叫做FontForge的程序,我用它来创建一个ttf otf,然后我用。$ ​​b $ b

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.

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.