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

Layout is incorrect for rotated text

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Duplicate
    • Icon: P4 P4
    • tbd
    • 9
    • client-libs
    • 2d
    • 9
    • windows_10

      Text layout for a font with rotation transform produces incorrect results.
      Here's a small program that demonstrates the issue:

      import javax.swing.JComponent;
      import javax.swing.JFrame;
      import javax.swing.SwingUtilities;
      import javax.swing.WindowConstants;
      import java.awt.Font;
      import java.awt.Graphics;
      import java.awt.Graphics2D;
      import java.awt.font.GlyphVector;
      import java.awt.geom.AffineTransform;

      public class FontLayoutDrawingTest {
          public static void main(String[] args) {
              SwingUtilities.invokeLater(() -> {
                  JFrame frame = new JFrame();
                  frame.setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE);
                  frame.add(new MyComponent());
                  frame.setSize(200, 200);
                  frame.setVisible(true);
                  frame.setLocationRelativeTo(null);
              });
          }

          private static class MyComponent extends JComponent {
              @Override
              protected void paintComponent(Graphics g) {
                  Font font = new Font(Font.SERIF, Font.PLAIN, 30).deriveFont(AffineTransform.getQuadrantRotateInstance(1));
                  char[] text = new char[] {'A', 'B'};
                  Graphics2D g2d = (Graphics2D) g;
                  GlyphVector gv = font.layoutGlyphVector(g2d.getFontRenderContext(), text, 0, text.length, Font.LAYOUT_LEFT_TO_RIGHT);
                  g2d.drawGlyphVector(gv, 80, 50);
              }
          }
      }

      Running it using Java 8, produces expected result (RotatedLayout-java8.png). With Java 9, letters are overlapping on rendering (RotatedLayout-java9.png). Switching to ICU layout engine (by adding -Dsun.font.layoutengine=icu command line option) produces correct result.

            prr Philip Race
            dbatrak Dmitry Batrak
            Votes:
            0 Vote for this issue
            Watchers:
            3 Start watching this issue

              Created:
              Updated:
              Resolved: