views:

331

answers:

2

I have been attempting to enhance my GUI system written in Java to use subpixel antialiasing and have been successful, except for one remaining anomaly. This is a follow on to my other question from yesterday.

The remaining problem is that setting rendering hints KEY_ANTIALIASING to VALUE_ANTIALIAS_ON causes KEY_TEXT_ANTIALIASING to be ignored when it is set to an LCD (subpixel) AA value. Can anyone shed some light on this? Currently I am forced to VALUE_ANTIALIAS_OFF before rendering text and turn it back on after rendering text (so that other painting, like circles, etc, is AA'd).

This problem is proven by the self-contained test program below. As you can see if you run it, the circle is painted with AA when the font isn't, and vice versa. It would be nice to have AA preconfigured to work for all painting.


Self Contained Test Program

import java.awt.*;
import java.awt.event.*;

public class AwtTestFrame1c extends Panel {

AwtTestFrame1c() {
    setBackground(SystemColor.control);
    }

public void paint(Graphics gc) {
    Graphics2D                          g2d = (Graphics2D)gc;
    int                                 py=0;

    py=paintText(g2d,py,RenderingHints.VALUE_TEXT_ANTIALIAS_LCD_HRGB,true );
    py=paintText(g2d,py,RenderingHints.VALUE_TEXT_ANTIALIAS_LCD_HRGB,false);
    }

private int paintText(Graphics2D dgc, int py, Object val, boolean aa) {
    char[]                              txt=("The quick brown fox jumped over the lazy dog ("+val+", General AA: "+aa+")").toCharArray();

    if(aa        ) { dgc.setRenderingHint(RenderingHints.KEY_ANTIALIASING,RenderingHints.VALUE_ANTIALIAS_ON ); }
    else           { dgc.setRenderingHint(RenderingHints.KEY_ANTIALIASING,RenderingHints.VALUE_ANTIALIAS_OFF); }
    if(val !=null) { dgc.setRenderingHint(RenderingHints.KEY_TEXT_ANTIALIASING,val);                           }
    dgc.setFont(font);

    dgc.drawOval(5,py+5,15,15);
    dgc.drawChars(txt,0,txt.length,30,py+line-5);

    return (py+line);
    }

static private final Font                      font=new Font("SansSerif",Font.PLAIN,16);
static private final int                       line=25;

static public void main(String[] args) {
    Frame                               wnd=new Frame("AWT Antialiased Text Sample");

    wnd.addWindowListener(new WindowAdapter() {
        public void windowClosing(WindowEvent e) {
            System.exit(0);
            }
        });
    wnd.add(new AwtTestFrame1c());
    wnd.setSize(new Dimension(1000, 300));
    wnd.setVisible(true);
    }

}
+1  A: 

I was updating VirtualBox, so I took pictures. I may just be seeing the host's rendering, but I suspect it is also implementation dependent.

Ubuntu 9.10AwtTestFrame Ubuntu Mac OS X 10.5AwtTestFrame Mac Windows 7AwtTestFrame WIn

trashgod
Good thanks; here you can see that where subpixel AA is used (note the tell-tale color artifacts) the circle is not AA, but where the circle is AA, the text is standard AA instead of subpixel.
Software Monkey
Aha! At least now I see the problem. Sorry I don't have the answer :-)
trashgod
A: 

A bit of poking around found this: bug 6263951.

Apparently the bustage is fixed in b17? I'm not exactly sure how to interpret the bug report.

Definitely broken here on 1.6.0_17-b04 (MacOS X 10.5).

spong
Hmmm. Certainly describes the same problem. I am not sure how to interpret the fix version either - maybe Java 7 build 17? The bug report is from 2005 and it's certainly still doing this in Java 6_18. Seems strange that it took them 5 years to fix this, since it's a bit of a pain to work around.
Software Monkey
Accepting this because (a) it seems the answer to my question is "yes", and (b) the bug report seems to answer when the fix will be available (that is, eventually, when and if Java 7 ever comes out).
Software Monkey