JDK-8013469 : Rotated text is drawn to the opposite direction on Mac OS X
  • Type: Bug
  • Component: client-libs
  • Sub-Component: 2d
  • Affected Version: 7u13,7u21,8
  • Priority: P3
  • Status: Resolved
  • Resolution: Duplicate
  • OS: os_x
  • Submitted: 2013-04-04
  • Updated: 2014-11-17
  • Resolved: 2013-04-30
Related Reports
Duplicate :  
Description
FULL PRODUCT VERSION :
java version  " 1.7.0_13 " 
Java(TM) SE Runtime Environment (build 1.7.0_13-b20)
Java HotSpot(TM) 64-Bit Server VM (build 23.7-b01, mixed mode)

ADDITIONAL OS VERSION INFORMATION :
Mac OS X 10.7.5

A DESCRIPTION OF THE PROBLEM :
Rotated String is drawn to the opposite direction on Mac OS X.
When we rotate graphics by g.rotate(-Math.PI / 2) and g.drawString( " ABC " ),  " B "  should be drawn upper  " A " .  But  " B "  is drawn under  " A " .   " C "  is drawn under the  " B " .

REGRESSION.  Last worked in version 6u31

STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
1. Run the program to test
2. Check the shown window.

EXPECTED VERSUS ACTUAL BEHAVIOR :
EXPECTED -
90 degrees rotated  " ABC123 "  should be shown.
ACTUAL -
Rotated  " 321CBA "  is shown at the wrong position.

REPRODUCIBILITY :
This bug can be reproduced always.

---------- BEGIN SOURCE ----------
import java.awt.Font;
import java.awt.Graphics;
import java.awt.Graphics2D;

import javax.swing.JFrame;
import javax.swing.SwingUtilities;

public class RotatedStringFrame extends JFrame {
@Override
public void paint(Graphics g) {
Graphics2D g2 = (Graphics2D) g;
g2.setFont(new Font(Font.SERIF, Font.PLAIN, 24));
g2.rotate(-Math.PI / 2.0);
g2.drawString( " ABC123 " , -200.0f, 40.0f);
}

public static void main(String[] args) {
SwingUtilities.invokeLater(new Runnable() {
@Override
public void run() {
RotatedStringFrame frame = new RotatedStringFrame();
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.setSize(200, 400);
frame.setVisible(true);
}
});
}
}

---------- END SOURCE ----------

CUSTOMER SUBMITTED WORKAROUND :
We can avoid this bug by using drawString(AttributedStringIterator) instead of drawString(String).
Comments
CUSTOMER SUBMITTED WORKAROUND : Setting anti-aliasing as a rendering hint to true, seems to solve the problem. The code below can be used to do so: g2d.setRenderingHint(RenderingHints.KEY_TEXT_ANTIALIASING, RenderingHints.VALUE_TEXT_ANTIALIAS_ON);
29-04-2013