Skip to main content

Phil's Font Fixes

Posted by chet on June 6, 2005 at 4:09 PM PDT

The bits are in: we've just integrated LCD Text support
in J2SE! You can download the latest
Mustang build
and check it out (we integrated this feature into build 39,
which should be live now).

Phil Race was hard at work over the last several months implementing
this stuff. Here's what he had to say about it:

One of the most frequently requested features has been for the JDK to
support subpixel text which optimises for LCD displays using
the subpixel striping to increase the text resolution.
Because of the way its applied and configured by users its
considered a form of text antialiasing.

On 31st May the
RFE for this

had reached number 6 on the BugParade RFE list with 378 votes.

The good news is this is now implemented and in mustang build 39.

The main reason for implementing this is to help the Swing
native Look and Feel classes for Windows and Gnome/GTK in
their emulation of the respective platform font rendering.
mustang b39 now supports all the text antialiasing
modes needed to support this.

At the same time as implementing this, the Windows Look
and Feel and the GTK Look and Feel have also been updated
to track the user's desktop preferences and update in real time
as the end user changes these.

Additionally the default Java Look and Feel aka "Metal" now
reads the user desktop text antialiasing preferences on start up
and applies them to the JDK fonts. When used together with the
Metal "Ocean" theme (which uses plain fonts instead of bold)
introduced in JDK 5, the result is quite pleasing to the eye.

In a nutshell what this means is that whether you use Metal,
Windows or GTK Look and Feel, you will get the same antialiasing
behaviour for fonts in Java applications as in native applications.
You don't have to do anything. It just works out of the box.

This is the first delivery of this work, and there's more that
can be done, but it hits the big need of fixing these Swing
L&Fs.

There's fairly little new API involved, although some
more is expected later, for example in Swing to provide authors
of custom L&Fs access to the same information as Metal.

For those interested in the details the new API in b39 is all in Java2D.
There are 5 new values for java.awt.RenderingHints.KEY_TEXT_ANTIALIASING
which are supported on all platforms:

  • VALUE_TEXT_ANTIALIAS_LCD_HRGB
  • VALUE_TEXT_ANTIALIAS_LCD_HBGR
  • VALUE_TEXT_ANTIALIAS_LCD_VRGB
  • VALUE_TEXT_ANTIALIAS_LCD_VBGR
  • VALUE_TEXT_ANTIALIAS_GASP

The first four correspond to the 4 possible different LCD subpixel
configurations.
Native GTK apps support all 4 of these
On Windows in native apps you need at least XP to get LCD text support,
whereas JDK supports it on all OSes. Also Microsoft only supports HRGB
on XP and added HBGR in XP SP1.
So JDK's support here is more complete than Microsoft's.

The final oddly named hint value is used by JDK to precisely emulate
what windows "standard" font smoothing does. That's what everyone
with a CRT needs/uses. Its a little confusing to a lot of people
as it doesn't mean all text is antialiased. It uses a table in
the font (called the 'gasp' table, hence the name) provided by
the font designer which stipulate the sizes at which smoothing should
be done, and often that means text is not antialiased.

There are a very few other API tweaks but these are the most
interesting ones.

If anyone wants to try this out, download mustang build 39 and look
at the SwingSet2 demo. Also the Font2DTest demo has been updated to
let you set any of the new hints and view the effects with any
font or text of your choice.

(Note: All of the following pictures looked horrible in both browsers that I tried, related to automatic image scaling in those
applications. The images looked fine on a different system, so they may look fine for you as well, but if they look odd, try disabling automatic image resizing or just saving the images and loading them with a local image viewing application instead.)

Or you could just look at these PNG screenshots of the JTable demo tab from
the SwingSet2 demo. Without LCD text:



and with LCD text:

Here is a screenshot which shows side by side the same fonts
being rendered by Windows WordPad accessory and a small JDK
app which uses the same fonts and text.
The fonts used here are ones typically seen in windows apps.

Similarly, here's a snapshot comparing some of the more common fonts
seen in Gnome apps on Linux side by side with the JDK rendering of
these fonts.
The Gnome text was rendered on Fedora Core3 in the "gedit" application.
Since gedit can only use one font at a time, the text was snapshotted
and stitched together using gimp for ease of comparison.

Note : these images are prepared for viewing on a "HRGB" LCD display.
That's by far the most common. If you are using a CRT don't expect
to see much improvement. Also if your LCD display isn't connected
by a DVI connector you'll not get the best experience either.
A VGA connector just doesn't have the precise addressibility needed
to get good results from this.

So that's all the important news about it: check it out, download it, play
with it, tell us what you think.

Now, the less important but more interesting part, at least to this
graphics geek: how does it work? There's information out there
on the web so you can chase this down if you want more details, but
the basics of LCD text involve details of how the eye perceives color,
and how we can use that physical reality, along with the physical construction
of LCD monitors, to display a higher-quality anti-aliasing effect.
I originally hoped to cover this geeky topic here, but
when I crossed the 400th line of text, I realized that it was more of an
article than a blog entry. I'm working on that article now and hope to
publish it sometime next week; stay tuned...

In the meantime, download the release
and play with it; we think you'll like it.

Related Topics >>