I am trying to improve my graphics system written in Java to use sub-pixel anti-aliasing and was successful, with the exception of one remaining anomaly. This is the next question from my other question from yesterday .
The remaining problem is that setting the KEY_ANTIALIASING rendering hints to VALUE_ANTIALIAS_ON ignores KEY_TEXT_ANTIALIASING when it is set to AA (subpixel) AA. Can someone shed some light on this? I am currently forced to VALUE_ANTIALIAS_OFF before rendering the text and returning it after rendering the text (so another picture, like circles, etc., is equal to AA'd).
This problem has been proven using the standalone test program below. As you can see, if you run it, the circle will be painted AA when the font is gone, and vice versa. It would be nice if AA were set up to work for all of the painting.
Self 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); } }
java fonts rendering antialiasing
Lawrence dol
source share