Reposting from "Swing & AWT" forum since it was suggested that this is a better 
place.

It looks like the new native text rasterizer is not used when the current 
graphics composite is translucent. Here is the test app that i'm running on 
Vista SP1 with 6u10 b14:

[code]
package test;
 
import java.awt.*;
import java.util.*;
 
import javax.swing.*;
 
public class TextRenderingPanel extends JPanel {
 
        private static Map desktopHints(Graphics2D g2) {
                Toolkit toolkit = Toolkit.getDefaultToolkit();
                GraphicsDevice device = g2.getDeviceConfiguration().getDevice();
                Map desktopHints = (Map) toolkit
                                .getDesktopProperty("awt.font.desktophints");
                // It is possible to get a non-empty map but with disabled AA.
                if (desktopHints != null) {
                        Object aaHint = desktopHints
                                        
.get(RenderingHints.KEY_TEXT_ANTIALIASING);
                        if ((aaHint == RenderingHints.VALUE_TEXT_ANTIALIAS_OFF)
                                        || (aaHint == 
RenderingHints.VALUE_TEXT_ANTIALIAS_DEFAULT)) {
                                desktopHints = null;
                        }
                }
                return desktopHints;
        }
 
        @Override
        protected void paintComponent(Graphics g) {
                Graphics2D g2d = (Graphics2D) g.create();
                
                Map desktopHints = desktopHints(g2d);
                if (desktopHints != null && !desktopHints.isEmpty()) {
                        g2d.addRenderingHints(desktopHints);
                }
                
                g2d.setColor(Color.white);
                g2d.fillRect(0, 0, getWidth(), getHeight());
                g2d.setColor(Color.black);
                g2d.setFont(new Font("Segoe UI", Font.PLAIN, 12));
                g2d.drawString("Text rendering", 10, 30);
                g2d.setComposite(AlphaComposite.SrcOver.derive(0.5f));
                workaroundBug6576507(g2d);
                g2d.drawString("Text rendering", 10, 60);
                g2d.dispose();
        }
        
        public static void workaroundBug6576507(Graphics graphics) {
                Font font = graphics.getFont();
                font = font.deriveFont(font.getStyle(), font.getSize2D());
                graphics.setFont(font);
        }
 
 
        public static void main(String[] args) {
                SwingUtilities.invokeLater(new Runnable() {
                        @Override
                        public void run() {
                                JFrame frame = new JFrame("Text rendering");
                                frame.add(new TextRenderingPanel(), 
BorderLayout.CENTER);
                                frame.setSize(300, 200);
                                
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
                                frame.setLocationRelativeTo(null);
                                frame.setVisible(true);
                        }
                });
        }
 
}
[/code]


Running this you can see that the 'e's on the second line of text do not come 
from the same rasterizer as the 'e's on the first line of text. Is this the 
expected result, and if so, would i have to create a temporary image, render 
the full-opacity text there and then render that image back (with translucency) 
to get consistent rendering?

Note that I have to use deriveFont as the workaround for bug 6576507 as 
suggested in [1]. Doesn't look like the fix in JDK 7 was backported to 6u10.

Last thing - letter 'g' is one pixel narrower than in the "real" native 
rendering (from the title pane of the same frame).

Thanks
Kirill 

[1] http://forums.java.net/jive/thread.jspa?threadID=28226
[Message sent by forum member 'kirillcool' (kirillcool)]

http://forums.java.net/jive/thread.jspa?messageID=268874

===========================================================================
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".

Reply via email to