JDK-8040627 : [macosx] Text drawn at an angle in a JComponent renders incorrectly.
  • Type: Bug
  • Component: client-libs
  • Sub-Component: java.awt
  • Affected Version: 7u40
  • Priority: P3
  • Status: Closed
  • Resolution: Duplicate
  • OS: os_x
  • Submitted: 2013-09-26
  • Updated: 2015-02-16
  • Resolved: 2015-02-16
The Version table provides details related to the release that this issue/RFE will be addressed.

Unresolved : Release in which this issue/RFE will be addressed.
Resolved: Release in which this issue/RFE has been resolved.
Fixed : Release in which this issue/RFE has been fixed. The release containing this fix may be available for download as an Early Access Release or a General Availability Release.

To download the current JDK release, click here.
JDK 9
9Resolved
Related Reports
Duplicate :  
Duplicate :  
Description
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.
Comments
- this is an issue reported against 7(7u), - there are now affected version 9 filed for this issue - 7u issues are transferred to Sustaining Nevertheless if someone have a report against 9 - please reopen and add affectedVersion 9 or 7u specific escalations might be reopen to Sustaining
10-08-2014

- this is an issue reported against 7(7u), - there are now affected version 9 filed for this issue - 7u issues are transferred to Sustaining Nevertheless if someone have a report against 9 - please reopen and add affectedVersion 9 or 7u specific escalations might be reopen to Sustaining
10-08-2014

not a regression in 8 / 9
16-05-2014

not a regression in 8 / 9
16-05-2014