I think that what was mentioned at the BOF was that often A-A text would look too "light" and in 1.5 we set a different flag in the rasteriser (at JDK build time) that applies a different grid-fitting strategy which helped alleviate that problem somewhat. Looking at this test using (say point size 8) it looks like 1.5 is marginally clearer than 1.4.2. I believe there is still room for improvement as the improvement is just marginal. We still blur some stems across pixels that superficially look as if they could be fitted to be a single pixel position.
But ultimately, point size 8 (at 72 dpi which is what Java 2D uses if you don't tell it otherwise) is pretty small text, and on my 1600x1200 CRT I can barely read that text. WordPad doesn't even let me choose a font remotely that small.
I also compared 6 pt font using your code and creating an AWT Label which uses windows native text APIs. In that case the 2D rendering is unquestionably much clearer than the windows one. So its not all bad. Note I specified Dialog, not Arial as AWT components don't support specifying anything other than the logical fonts but it amounts to the same thing as Arial is used for Dialog.
-phil.
Olof Andersson wrote:
Hi all, I'm building an app with a zoomable interface and I'm getting quite poor results when rendering text(AttributedStrings, actually) when the font size gets small. I know this topic was briefly discussed during the Java2D BOF at this years JavaOne, and the problem was put down to a bug that probably wouldn't get fixed until the release of 1.5. Any news on this issue? Is it a platform-specific problem(I'm running 1.4.2 on win2k)? Tips for workarounds to increase rendering quality would be greatly appreciated!
Here's a code snippet that shows the problem. Run the applet, change fontsize by right-clicking and watch a significant change in quality between fontsize 11 and 10.
import java.awt.*; import java.awt.event.*; import java.applet.*; import java.awt.font.*; import java.text.*; import javax.swing.*;
public class FontSizeTest extends Applet { private boolean isStandalone = false; int fontSize = 12; AttributedString attributedString; TextLayout textLayout; String theString = "How come font size < 11 looks crappy?";
//Construct the applet public FontSizeTest() { addMouseListener(new MouseAdapter() { public void mouseReleased(MouseEvent e) { if(e.isPopupTrigger()){ JPopupMenu pM = new JPopupMenu(); JMenu fontSizeMenu = new JMenu("Set font size"); for(int i = 5; i < 16; i++){ final int fs = i; fontSizeMenu.add(new AbstractAction("Font size " + fs){ public void actionPerformed(ActionEvent e){ fontSize = fs; attributedString = null; textLayout = null; repaint(); } }); } pM.add(fontSizeMenu); pM.show(FontSizeTest.this,e.getX(), e.getY()); } } }); }
public void paint(Graphics g){ Dimension d = getSize(); int w = d.width; int h = d.height; Graphics2D g2 = (Graphics2D) g; g2.setRenderingHint(RenderingHints.KEY_TEXT_ANTIALIASING, RenderingHints.VALUE_TEXT_ANTIALIAS_ON); g2.setColor(Color.black); g2.fillRect(0, 0, w, h); drawString(g2); }
private void drawString(Graphics2D gr){ if(attributedString == null || textLayout == null){ attributedString = new AttributedString(theString); attributedString.addAttribute(TextAttribute.UNDERLINE, TextAttribute.UNDERLINE_ON); attributedString.addAttribute(TextAttribute.FOREGROUND, Color.white); attributedString.addAttribute(TextAttribute.BACKGROUND, Color.black); attributedString.addAttribute(TextAttribute.FONT, new Font("Arial", Font.BOLD, fontSize)); textLayout = new TextLayout(attributedString.getIterator(), gr.getFontRenderContext()); } textLayout.draw(gr, (int)(getWidth()/2 - textLayout.getBounds().getWidth()/2), getHeight()/2); }
//Main method public static void main(String[] args) { FontSizeTest applet = new FontSizeTest(); applet.isStandalone = true; Frame frame; frame = new Frame(); frame.setTitle("Font size test"); frame.add(applet, BorderLayout.CENTER); applet.init(); applet.start(); frame.setSize(400,320); Dimension d = Toolkit.getDefaultToolkit().getScreenSize(); frame.setLocation((d.width - frame.getSize().width) / 2, (d.height - frame.getSize().height) / 2); frame.setVisible(true); frame.addWindowListener(new WindowAdapter() { public void windowClosing(WindowEvent e) { System.exit(0); } }); } }
Thanks, Olof
=========================================================================== To unsubscribe, send email to [EMAIL PROTECTED] and include in the body of the message "signoff JAVA2D-INTEREST". For general help, send email to [EMAIL PROTECTED] and include in the body of the message "help".
=========================================================================== To unsubscribe, send email to [EMAIL PROTECTED] and include in the body of the message "signoff JAVA2D-INTEREST". For general help, send email to [EMAIL PROTECTED] and include in the body of the message "help".
