Skip to main content

b13 - Text antialiasing problems for TTF fonts (loaded via classloader)

6 replies [Last post]
nazmulidris
Offline
Joined: 2006-12-22

I've been using UpdateN b13 and I'm really impressed with the fantastic looking font rendering on Windows Vista! Great job on the implementation!

I've noticed one issue - for the Java app that I'm building, I load TTF files from my hard drive, via a classloader. When I create fonts that are loaded in this way, the antialising/rendering of text doesn't look right. So it looks great for "system loaded fonts", but for custom fonts that I load, the text doesn't look right. I can copy the same exact TTF that Vista uses, and load it via a classloader and text rendering doesn't look right.

Here's the code I use:

String fontFile = "fonts/Segoe UI.ttf";
InputStream is = ClassLoader.getSystemResourceAsStream(fontFile);
Font font = Font.createFont(Font.TRUETYPE_FONT, is);
is.close();

Do you know what's going on with the font rendering?

Also, I use SwingX components, and the font rendering on all of them is off... the default Swing text components look much better than their SwingX counterparts.

Thanks,
Nazmul

Reply viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.
trembovetski
Offline
Joined: 2003-12-31

Could you please post some screenshots of what you mean by "doesn't look right" (in png's, please)?

Dmitri

trembovetski
Offline
Joined: 2003-12-31

And a test case would be even better.

nazmulidris
Offline
Joined: 2006-12-22

Hi Dimitri

I've attached a Zip file which has PNG files as you requested, and the code that loads the fonts from the hard drive. I'm using Vista SP1 Enterprise, and the fonts that I load from the hard drive are the same TTF files that are in the Vista Fonts folder.

The FontUtils.java class loads some fonts (from the hard drive) and then sets UIDefaults for Swing components.

If you look inside the Zip file you will find the 2 PNG files. If you look at b13-systemfonts.png, this is the screenshot using 'system loaded' fonts - ie, I don't load these fonts in my code... they are available from Vista. Everything looks good here. In order to get this result, I've [b]disabled the code in FontUtils[/b] that actually loads the TTF files from the classloader.

If you look at b13-classloadedfonts.png, this is the screenshot using 'classloader loaded' fonts, from the hard drive. These are the same TTF files that are used by Vista, but when I load them 'manually', the font rendering is "off". If you compare the 2 PNG files side by side, you will see that the antialiasing is different...

Let me know if you need anything else.

Thanks,
Nazmul.

trembovetski
Offline
Joined: 2003-12-31

Thanks for the info, Nazmul.

According to our fonts engineer, this is by design: rendering of fonts created with
createFont goes through the built-in rasterizer instead of using the native one.

Dmitri

nazmulidris
Offline
Joined: 2006-12-22

Thanks Dimitri. So are there any plans to update the built-in rasterizer to more closely match ClearType?

In my code, I can check to see what OS the app is running on to make sure that certain fonts are available, before trying to load them from disk...

Again, I'm really impressed with the native font rasterization. It looks great!!! I can't use any VM other than b13 because of it :).

Take care
Nazmul.

trembovetski
Offline
Joined: 2003-12-31

> So are there any plans to update the built-in rasterizer to more closely match ClearType?

This is an ongoing process, there are bugs filed against specific issues.

Good to hear that you like the new font rendering in 6u10!

Dmitri