Uploaded image for project: 'JDK'
  1. JDK
  2. JDK-8067268

rotated text is incorrectly rendered

    Details

    • Type: Bug
    • Status: Closed
    • Priority: P3
    • Resolution: Duplicate
    • Affects Version/s: 7u55, 8
    • Fix Version/s: None
    • Component/s: client-libs
    • Labels:
    • Subcomponent:
      2d
    • CPU:
      x86
    • OS:
      os_x

      Description

      FULL PRODUCT VERSION :
      java version "1.7.0_55"
      Java(TM) SE Runtime Environment (build 1.7.0_55-b13)
      Java HotSpot(TM) 64-Bit Server VM (build 24.55-b03, mixed mode)


      ADDITIONAL OS VERSION INFORMATION :
      Darwin dodge1m1.llnl.gov 12.5.0 Darwin Kernel Version 12.5.0: Sun Sep 29 13:33:47 PDT 2013; root:xnu-2050.48.12~1/RELEASE_X86_64 x86_64


      A DESCRIPTION OF THE PROBLEM :
      Text rendered with a font produced by rotation using an AffineTransform only renders correctly at rotation angles of 0 and pi. At all other angles the characters are rotated in the opposite direction from the angle to which the string was rotated. The result is unreadable.

      REGRESSION. Last worked in version 6u43

      ADDITIONAL REGRESSION INFORMATION:
      java version "1.7.0_55"
      Java(TM) SE Runtime Environment (build 1.7.0_55-b13)
      Java HotSpot(TM) 64-Bit Server VM (build 24.55-b03, mixed mode)

      STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
      Compile and execute the supplied code on the specified OS. For what it's worth, I have found the problem also exists on Mac OS with JDK 8.*, but is not present on Windows with any JDK I have tried.

      EXPECTED VERSUS ACTUAL BEHAVIOR :
      EXPECTED -
      This code will display a JFrame with a JPanel on which will be painted 5 string e.g. "Text at 0", Text at 45", "Text at 90", "Text at 135" "Text at 180".
      Each String will be rendered at the referenced rotation angle.
      ACTUAL -
      The panel is display with the five strings displayed. However, only the Strings "Text at 0", and "Text at 180" are rendered correctly. The other strings are rendered with the individual characters at the correct rotation angle but with the entire string rotated to the minus of the intended rotation angle.

      ERROR MESSAGES/STACK TRACES THAT OCCUR :
      There are no error messages.

      REPRODUCIBILITY :
      This bug can be reproduced always.

      ---------- BEGIN SOURCE ----------
      import java.awt.BorderLayout;
      import java.awt.Color;
      import java.awt.Font;
      import java.awt.Graphics;
      import java.awt.Graphics2D;
      import java.awt.geom.AffineTransform;
      import javax.swing.JFrame;
      import javax.swing.JPanel;
      import javax.swing.SwingUtilities;

      public class ATest {

          public static void main(String[] args) {
              
              SwingUtilities.invokeLater(new Runnable() {

                  @Override
                  public void run() {
                      JFrame frame = new JFrame();
                      frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
                      frame.getContentPane().add(new TestPanel(), BorderLayout.CENTER);
                      frame.setSize(800, 800);
                      frame.setVisible(true);
                  }
              });
              
          }

          static class TestPanel extends JPanel {


              @Override
              protected void paintComponent(Graphics g) {
                  super.paintComponent(g);
                  Graphics2D g2d = (Graphics2D) g;
                  Font oldFont = g2d.getFont();
                  Color oldColor = g2d.getColor();

                  g2d.setColor(Color.black);
                  
                  AffineTransform at = new AffineTransform();
                  for (int j = 0; j < 5; ++j) {
                      // Create new rotated font
                      double theta = j * Math.PI / 4.0;
                      at.setToRotation(theta);
                      Font rotatedFont = oldFont.deriveFont(at);
                    
                      g2d.setFont(rotatedFont);

                      // Render text
                      g2d.drawString(String.format("Text at %4.0f", Math.toDegrees(theta)), 10+ j * 150, 20+ j * 150);
                  }

                  // restore old values
                  g2d.setColor(oldColor);
                  g2d.setFont(oldFont);
              }

          }

      }
      ---------- END SOURCE ----------

      CUSTOMER SUBMITTED WORKAROUND :
      I have found no work around.

        Attachments

          Issue Links

            Activity

              People

              • Assignee:
                serb Sergey Bylokhov
                Reporter:
                webbuggrp Webbug Group
              • Votes:
                0 Vote for this issue
                Watchers:
                2 Start watching this issue

                Dates

                • Created:
                  Updated:
                  Resolved: