user2505059
user2505059

Reputation: 23

Java Custom Font Distortion

I am writing an application which includes a .ttf file for the fonts of the GUI. Loading the font seems no problem, however when using deriveFont() method to edit the size the font seems to be distorted (e.g. not on the same line, parts missing from letters, skewing,..).

Why is this? Is there a way round?

Code to load the font:

InputStream is = getClass().getResourceAsStream("/fonts/lg.ttf");
GraphicsEnvironment ge = GraphicsEnvironment.getLocalGraphicsEnvironment();
leagueGothic =  Font.createFont(Font.TRUETYPE_FONT, is);
ge.registerFont(leagueGothic);

And then changing the size with deriveFont()

label.setFont(leagueGothic.deriveFont(Font.PLAIN, scale(50, 'x'));

scale(int, char) is just a method to change the size proportional to the size of the application window, it returns an int.

Upvotes: 2

Views: 277

Answers (1)

trashgod
trashgod

Reputation: 205775

In your call to deriveFont(), the method scale(int, char) "it returns an int." It should probably return a float, as required here for the size parameter.

Upvotes: 2

Related Questions