FULL PRODUCT VERSION :
java version "1.7.0_40"
Java(TM) SE Runtime Environment (build 1.7.0_40-b43)
Java HotSpot(TM) 64-Bit Server VM (build 24.0-b56, mixed mode)
ADDITIONAL OS VERSION INFORMATION :
Mac OS X 10.7.5
EXTRA RELEVANT SYSTEM CONFIGURATION :
Mid-2012 15" MacBook Pro and Mid-2012 13" MacBook Air
A DESCRIPTION OF THE PROBLEM :
When drawing text using Graphics2D.drawString at an angle in a JComponent by using AffinteTranform to apply a rotation, the text renders incorrectly. The baseline of the text rotates in the opposite direction from the specified angle, while the individual characters counter-rotate in the correct direction. At an angle of zero radians, the text renders correctly. It also renders correctly at Pi radians. At all other angles, it does not render correctly.
REGRESSION. Last worked in version 6u43
REGRESSION : Additional Information
The bug also existed under Apple's version of Java 1.6. However, in that JVM, the bug only existed when using the call
UIManager.setLookAndFeel(UIManager.getCrossPlatformLookAndFeelClassName());
When using Apple's look-and-feel, the bug did not exist. On JDK 1.7 with Oracle's implementation, the bug exists regardless of selected look-and-feel.
The bug did not appear in Apple's JVM 1.5 or earlier.
STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
The test program always produces the incorrrectly rendered text.
EXPECTED VERSUS ACTUAL BEHAVIOR :
EXPECTED -
In the test program, I expect the text and the line to be in alignment. The text should be centered on the line with the text proceeding radially outwards as if were a strike-through.
ACTUAL -
In actuality, the baseline of the text rotates in the opposite direction as the specified angle, while the individual letters counter-rotate the correct direction. For angles other than 0, pi/2, pi, and pi*3/4, the letters no longer share a common baseline. For pi/2 and pi*3/4 radians, the text actually renders backwards (in reverse order, (not mirror image).
I can supply a screen shot of the behavior if that would be helpful.
ERROR MESSAGES/STACK TRACES THAT OCCUR :
There are no errors produced, just incorrect rendering of the text.
REPRODUCIBILITY :
This bug can be reproduced always.
---------- BEGIN SOURCE ----------
import java.awt.*;
import java.awt.geom.*;
import javax.swing.*;
public class AffineTest extends JComponent
{
public AffineTest ()
{
setPreferredSize(new Dimension (200, 200));
JFrame frame = new JFrame ("Affine Test");
frame.getContentPane().add (this, BorderLayout.CENTER);
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.pack();
frame.setVisible(true);
}
protected void paintComponent (Graphics _g)
{
AffineTransform at;
Graphics2D g2;
int w, h;
double angle;
g2 = (Graphics2D)_g;
w = getWidth ();
h = getHeight ();
g2.setColor (Color.white);
g2.fillRect (0, 0, w, h);
for (angle=0.0; angle<360.0; angle += 45.0)
{
at = g2.getTransform();
g2.translate(w/2.0, h/2.0);
g2.rotate(Math.toRadians(angle));
g2.setColor(Color.black);
// text and line segment should be in alignment - they are not
g2.drawLine(0, 0, (w/2-10), 0);
g2.drawString ("Test", w/4, 5);
g2.setTransform(at);
}
}
public static void main (String [] _args)
{
new AffineTest();
}
}
---------- END SOURCE ----------
CUSTOMER SUBMITTED WORKAROUND :
I have not found a workaround.