Skip to main content

Is there a RenderingHint for ClearType/SubPixel rendering?

11 replies [Last post]
cowwoc
Offline
Joined: 2003-08-24

Hi,

Is there a RenderingHint associated with native (i.e. ClearType) sub-pixel rendering? Is there a way to read RenderingHints associated with an existing component in order to find out whether it has ClearType enabled?

If you take a look at http://www.netbeans.org/issues/show_bug.cgi?id=137845 and the relevant patch http://hg.netbeans.org/main/rev/06619e663be5 you will note how fragile the code has become. Netbeans tries to avoid specifying any anti-aliasing hints for fear of mistakenly disabling ClearType rendering.

Surely there is a better way...?

Thank you,
Gili

Reply viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.
Phil Race

java2d@JAVADESKTOP.ORG wrote:
> Fred,
>
> One thing I don't understand is why changing KEY_TEXT_ANTIALIASING from its original value to VALUE_TEXT_ANTIALIAS_ON would break anything. Shouldn't VALUE_TEXT_ANTIALIAS_ON look up the desktop preferred anti-aliasing and use that instead?
>
>
Wrong. If you read the JDK docs "ON" has been there since JDK 1.2 in
1998 and has always meant
do greyscale AA.
Java 2D does not pick up the desktop setting. AWT desktop properties is
what does that and
Swing uses that to tell 2D what to use.

> One thing I still don't understand is: what value (or values) are associated with:
>
> - The JDK sub-pixel rendering
> - Native sub-pixel rendering
>

There is no distinction. Its the same LCD_HRGB hint. What happens under
the covers
is an implementation issue.

-phil.

> the VALUE_TEXT_ANTIALIAS_* values don't make this distinction obvious at all :(
> [Message sent by forum member 'cowwoc' (cowwoc)]
>
> http://forums.java.net/jive/thread.jspa?messageID=297246
>
> ===========================================================================
> To unsubscribe, send email to listserv@java.sun.com and include in the body
> of the message "signoff JAVA2D-INTEREST". For general help, send email to
> listserv@java.sun.com and include in the body of the message "help".
>

===========================================================================
To unsubscribe, send email to listserv@java.sun.com and include in the body
of the message "signoff JAVA2D-INTEREST". For general help, send email to
listserv@java.sun.com and include in the body of the message "help".

stolsvik
Offline
Joined: 2006-09-17

> java2d@JAVADESKTOP.ORG wrote:
> > Fred,
> >
> > One thing I don't understand is why changing
> KEY_TEXT_ANTIALIASING from its original value to
> VALUE_TEXT_ANTIALIAS_ON would break anything.
> Shouldn't VALUE_TEXT_ANTIALIAS_ON look up the desktop
> preferred anti-aliasing and use that instead?
> >
> >
> Wrong. If you read the JDK docs "ON" has been there
> since JDK 1.2 in
> 1998 and has always meant
> do greyscale AA.

ON says
"Text antialiasing hint value -- text rendering is done with some form of antialiasing."

Read "some form" repeatedly until you realize that it isn't obvious that this hint refers to "greyscale AA" exclusively.

> Java 2D does not pick up the desktop setting. AWT
> desktop properties is
> what does that and
> Swing uses that to tell 2D what to use.
>
> > One thing I still don't understand is: what value
> (or values) are associated with:
> >
> > - The JDK sub-pixel rendering
> > - Native sub-pixel rendering
> >
>
> There is no distinction. Its the same LCD_HRGB hint.
> What happens under
> the covers
> is an implementation issue.

So, why not LCD_VRGB? or HBGR? This is one of the super-absurd logics of Java - how the heck is I supposed to know which type of display the user has, and in what direction that display is orientated?

What about a "PRETTIEST" hint?

fred34
Offline
Joined: 2004-06-19

I'm not sure I've understood correctly, as from Java 6 onwards, there is a key speciifcally for that in RenderingHints: http://java.sun.com/javase/6/docs/api/java/awt/RenderingHints.html#KEY_T....

Remember that Netbeans doesn't stipulate JDK6 so they may not be able to use the LCD sub-pixel anti-aliasing values in the source. To check if a component has the value enabled just consult the RenderingHints Hashmap from your friendly local Graphics2D dealership.

cowwoc
Offline
Joined: 2003-08-24

Fred,

One thing I don't understand is why changing KEY_TEXT_ANTIALIASING from its original value to VALUE_TEXT_ANTIALIAS_ON would break anything. Shouldn't VALUE_TEXT_ANTIALIAS_ON look up the desktop preferred anti-aliasing and use that instead?

One thing I still don't understand is: what value (or values) are associated with:

- The JDK sub-pixel rendering
- Native sub-pixel rendering

the VALUE_TEXT_ANTIALIAS_* values don't make this distinction obvious at all :(

fred34
Offline
Joined: 2004-06-19

There is an AWT desktop property that will enable JDK6 apps. to determine the desktop preferred status of anti aliasing on text. Look here: http://java.sun.com/javase/6/docs/api/java/awt/doc-files/DesktopProperti...

All the values with LCD in the name are the ones related to sub-pixel aliasing. Until 1.6_u10 drops, then there isn't native text rendering in Java. Kirill Grouchnikov has written loads on this subject. Google his "Pushing Pixels" blog and look up the entries on native-text rendering for specifics. Also, read this blog for detailed stuff on the JDK implementation of sub-pixel rendering: http://weblogs.java.net/blog/chet/archive/2005/06/phils_font_fixe.html

cowwoc
Offline
Joined: 2003-08-24

See, the thing is you keep on writing sub-pixel aliasing, but as far as I'm aware there are two implementations for that: JDK-based and native-based (ClearType) so it isn't immediately clear to me which one LCD_* refers to.

If you look at the comment section of Chet's blog you will find this:

[code]from the soon to be posted updated 2D FAQ :

Q. How can I specify the text antialiasing/font smoothing settings to be used by Swing in applications on Java SE 6?

A. This is generally is a question from users of KDE or Windows 2000 who would like to use LCD subpixel text. There's no programmatic way to do it in Java SE 6 (However if you know what you want you can set a system property :

java -Dawt.useSystemAAFontSettings=lcd
which request to use LCD subpixel text in the most common subpixel configuration There are a few more useful values for this property as follows :

"false" corresponds to disabling font smoothing on the desktop.
"on" corresponds to Gnome Best shapes/Best contrast (no equivalent Windows desktop setting)
"gasp" corresponds to Windows "Standard" font smoothing (no equivalent Gnome desktop setting)
"lcd" corresponds to Gnome's "subpixel smoothing" and Windows "ClearType"[/code]

but then when you look at http://java.sun.com/javase/6/docs/technotes/guides/2d/flags.html#aaFonts it simply does not say that. The former seems to imply that LCD_* maps to native renderings and ON maps to JDK-rendering.

Personally I find this very counter-intuitive. I expect the following:

KEY_TEXT_ANTI_ALIASING:

OFF: Anti-aliasing is off
ON: Anti-aliasing is on, using whatever algorithm is preferred by the desktop
DEFAULT: Anti-aliasing is on for JDK 1.6, off for 1.5
LCD_*: Anti-aliasing is on using a specific algorithm (used mainly for testing, I don't see normal applications needing to pick a specific algorithm)

then you'd have a separate key:

KEY_TEXT_ANTI_ALIASING_IMPLEMENTATION (again mostly for testing purposes):

JDK: Rendered by JDK, if available
OS: Rendered by OS, if available
DEFAULT: Whatever is preferred on the current JDK version

cowwoc
Offline
Joined: 2003-08-24

Sorry, a few small corrections :) I forgot to account for the fact that the desktop might support ClearType rendering but the user disables it.

KEY_TEXT_ANTI_ALIASING:

DEFAULT: Anti-aliasing is on for JDK 1.6 if desktop anti-aliasing is enabled, OFF for JDK 1.5
ON: Anti-aliasing is on, using whatever algorithm is preferred by the desktop. If the desktop anti-aliasing is disabled this falls back on JDK rendering.

Phil Race

java2d@JAVADESKTOP.ORG wrote:
> Sorry, a few small corrections :) I forgot to account for the fact that the desktop might support ClearType rendering but the user disabled them.
>
> KEY_TEXT_ANTI_ALIASING:
>
> DEFAULT: Anti-aliasing is on for JDK 1.6 if desktop anti-aliasing is enabled, OFF for JDK 1.5
>

It may not be clear to others - or perhaps you- but your comments above
refer to *Swing* behaviours. Not 2D.
2D's default on all (Sun) implementations to date is "OFF."

And for 1.5 there was no code in AWT for Swing to use to pick up desktop
properties.
Its all new in 1.6 - if you can call 1.6 new anymore, since its been out
for almost 2 years.
> ON: Anti-aliasing is on, using whatever algorithm is preferred by the desktop. If the desktop anti-aliasing is disabled this falls back on JDK rendering.
>
Wrong. the rendering hint value "ON" means greyscale AA. It does not
mean desktop default.
And on windows "ON" is not going to correspond to any windows desktop
setting.
For windows its either "OFF", "GASP" (== windows standard), or
"LCD_HRGB"(~=cleartype)
> [Message sent by forum member 'cowwoc' (cowwoc)]
>

-phil.

> http://forums.java.net/jive/thread.jspa?messageID=297469
>
> ===========================================================================
> To unsubscribe, send email to listserv@java.sun.com and include in the body
> of the message "signoff JAVA2D-INTEREST". For general help, send email to
> listserv@java.sun.com and include in the body of the message "help".
>

===========================================================================
To unsubscribe, send email to listserv@java.sun.com and include in the body
of the message "signoff JAVA2D-INTEREST". For general help, send email to
listserv@java.sun.com and include in the body of the message "help".

cowwoc
Offline
Joined: 2003-08-24

> java2d@JAVADESKTOP.ORG wrote:
> > DEFAULT: Anti-aliasing is on for JDK 1.6 if desktop
> anti-aliasing is enabled, OFF for JDK 1.5
> >
>
> It may not be clear to others - or perhaps you- but
> your comments above
> refer to *Swing* behaviours. Not 2D.
> 2D's default on all (Sun) implementations to date is
> "OFF."

> Java 2D does not pick up the desktop setting. AWT desktop properties is
> what does that and
> Swing uses that to tell 2D what to use.

Right, so 2D is really out of the picture for most of this stuff. We're just discussing AWT and Swing.

> Wrong. the rendering hint value "ON" means greyscale
> AA. It does not
> mean desktop default.

Why couldn't ON (from Java 1.2) mean grayscale AA up to 1.5 and in 1.6 become general AA? Isn't that a superset? Could it really break any practical form of backwards compatibility?

> And on windows "ON" is not going to correspond to any
> windows desktop
> setting.
> For windows its either "OFF", "GASP" (== windows
> standard), or
> "LCD_HRGB"(~=cleartype)

Thanks for the mapping. I was wondering about that. In any case, you wrote in another post that whether LCD_HRGB maps to JDK-rendering or ClearType rendering is a non-configurable implementation detail. Fair enough, but then shouldn't ON also map to an abstract concept of "anti-aliasing is on" and let the implementation detail what AA renderer is appropriate?

Gili

Phil Race

java2d@JAVADESKTOP.ORG wrote:
>
> Why couldn't ON (from Java 1.2) mean grayscale AA up to 1.5 and in 1.6 become general AA? Isn't that a superset? Could it really break any practical form of backwards compatibility?
>

It would be an incompatible change.
And what would 2D pick when you did say ON? greyscale is the closest
thing to "general AA" anyway.
And what would you then specify to get what previously meant ON?

If you want something new, then use a new value. Think of it another
way: "ON" should perhaps have
been named "GREYSCALE".

So all this was carefully considered long ago, and the implemented
behaviour seems the safest way forward.

-phil.

===========================================================================
To unsubscribe, send email to listserv@java.sun.com and include in the body
of the message "signoff JAVA2D-INTEREST". For general help, send email to
listserv@java.sun.com and include in the body of the message "help".

cowwoc
Offline
Joined: 2003-08-24

Fair enough, thanks Phil.

Is there a chance of augmenting the documentation with these details? That is, mention that whether JDK or native font rendering is used is an implementation detail (that cannot be configured) and that ON means grayscale anti-aliasing. I don't think the existing documentation does this justice.