2

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.

Vivek Vermani
  • 1,934
  • 18
  • 45
  • [can you test with](http://stackoverflow.com/questions/18461331/ttf-and-otf-versions-of-source-sans-pro-are-differently-displayed-in-swing-nimb/18462739#18462739) – mKorbel Feb 17 '14 at 22:55

1 Answers1

2

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.

trashgod
  • 203,806
  • 29
  • 246
  • 1,045