0

I have bundled a .ttf font inside a JAR archive which I load with a routine along this lines:

[snip]
is = IdeUiUtil.class.getResourceAsStream(fontName);
font = Font.createFont(Font.TRUETYPE_FONT, is);
font = font.deriveFont(style, size);
[snip]

UPDATE: The font is used in the title of a TitledBorder, and will eventually also be used in a couple of JLabels.

The problem is, that on a Window platform it looks all jaggy. On linux, it's nicely anti-aliased. What do I have to do so it's anti-aliased on windows as well?

exhuma
  • 20,071
  • 12
  • 90
  • 123
  • This is a rather old question, but I came exactly across the same one. If I load a font from an input stream (and registering it on the GraphicsEnvoronment), that font is not anti aliased, no matter what kind of rendering hints are used. Especially if that font is not loaded at runtime but just available under the system fonts, that one IS anti aliased.It seems this is a bug in Java. – It's Leto Aug 03 '14 at 07:53

1 Answers1

0

If you are drawing with Graphics, you should use:

Graphics2D g2d = (Graphics2D)getGraphics();
g2d.setRenderingHint(RenderingHints.KEY_TEXT_ANTIALIASING, RenderingHints.VALUE_TEXT_ANTIALIAS_ON);

... but this is not specific to bundling a font : it applies to all fonts used with the Graphics object.

There is a hack to apply this to a panel, but I'm not sure it's up to date.

Damien
  • 3,060
  • 1
  • 25
  • 29
  • for a recent JDK, there is also a hint on Stackoverflow : http://stackoverflow.com/q/179955/438970 – Damien Feb 28 '11 at 16:25
  • Well, AA seems to be enabled on everything except the TitledBorder on which I set the loaded font. I also tried to set this font onto other components (JLabels in this case), and noticed that they were as well not anit-aliased. If I use a system Font, like 'Arial', the components are rendered properly. But I will give your hint a go... – exhuma Feb 28 '11 at 16:32