Java Font Rendering: Must general AA really be turned off for subpixel AA?
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.contro开发者_Python百科l);
}
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);
}
}
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.10
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).
精彩评论