Java Solaris Communities Sun Store Join SDN My Profile Why Join?
 
Bug Database
Bug Detail
Quick Lists
Top 25 Bugs
Top 25 RFE's
Recently Closed Bugs
Printable Page Printable Page


Bug Database
Bug ID: 6679308
Votes 0
Synopsis Poor text rendering on translucent image.
Category java:classes_2d
Reported Against
Release Fixed 7(b28), 6u10(b22) (Bug ID:2160482)
State 10-Fix Delivered, Verified, bug
Priority: 3-Medium
Related Bugs
Submit Date 24-MAR-2008
Description
The test below from   xxxxx@xxxxx   shows that text on a translucent
image renders poorly.


import java.awt.Color;
import java.awt.Dimension;
import java.awt.Font;
import java.awt.Graphics;
import java.awt.Graphics2D;
import java.awt.RenderingHints;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;
import java.awt.image.BufferedImage;
import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.SwingUtilities;

/**
 * @author Chris Campbell
 */
public class TextTest2 extends JPanel {

    private boolean useImage = false;

    public TextTest2() {
        setBackground(new Color(0.3f, 0.3f, 0.3f));
        addMouseListener(new MouseAdapter() {
            @Override
            public void mouseClicked(MouseEvent arg0) {
                useImage = !useImage;
                repaint();
            }
        });
    }

    private void drawText(Graphics2D g) {
        g.setRenderingHint(RenderingHints.KEY_TEXT_ANTIALIASING,
                           RenderingHints.VALUE_TEXT_ANTIALIAS_ON);
        g.setColor(Color.WHITE);
        g.setFont(new Font("sansserif", Font.PLAIN, 70));
        g.drawString("Hello!", 20, 200);
        g.setFont(new Font("sansserif", Font.PLAIN, 12));
        g.drawString("Hello!", 20, 230);
        g.setFont(new Font("sansserif", Font.PLAIN, 10));
        g.drawString("Hello!", 20, 250);
    }

    @Override
    public void paintComponent(Graphics g) {
        int w = getWidth();
        int h = getHeight();
        g.setColor(getBackground());
        g.fillRect(0, 0, w, h);
        if (useImage) {
            BufferedImage img = new BufferedImage(w, h, BufferedImage.TYPE_INT_ARGB_PRE);
            Graphics2D g2 = img.createGraphics();
            drawText(g2);
            g.drawImage(img, 0, 0, null);
            g2.dispose();
        } else {
            drawText((Graphics2D)g);
        }
    }

    @Override
    public Dimension getPreferredSize() {
        return new Dimension(280, 380);
    }

    public static void main(String[] args) {
        SwingUtilities.invokeLater(new Runnable() {
            public void run() {
                JFrame frame = new JFrame();
                TextTest2 test = new TextTest2();
                frame.add(test);
                frame.pack();
                frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
                frame.setLocationRelativeTo(null);
                frame.setVisible(true);
            }
        });
    }
}
Posted Date : 2008-03-24 22:29:31.0
Work Around
N/A
Evaluation
  xxxxx@xxxxx   identified that problem was in the glyph blending loop
which produced premultiplied results, but then used it in a way that assumed
non-premultiplied results. This bug has been around since at least 1.4.
Also the SPARC VIS loops turn out to have very similar issues.
Posted Date : 2008-03-24 22:29:31.0
Comments
  
  Include a link with my name & email   

Submitted On 23-APR-2009
antialiased lines and circles render poorly on translucent backgrounds too



PLEASE NOTE: JDK6 is formerly known as Project Mustang