Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Retrieving font name from font file in Java [closed]

Is there any Java API to get the font name from a font file (TTF)?

like image 226
srini Avatar asked Dec 28 '22 12:12

srini


1 Answers

Sure, the java.awt.Font class will handle this task just fine. Here's how:

Font f = Font.createFont(Font.TRUETYPE_FONT, new FileInputStream("font.ttf"));
String name = f.getName();

(I tried it on one of the ttf-fonts on my system and it works as intended.)

like image 106
aioobe Avatar answered Jan 04 '23 23:01

aioobe