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

Synthetically Bolded Fonts are Stretched Vertically under rotation.

    XMLWordPrintable

Details

    • 2d
    • b110
    • x86_64
    • windows_7

    Description

      FULL PRODUCT VERSION :
      Java(TM) SE Runtime Environment (build 1.8.0_45-b15)
      Java HotSpot(TM) 64-Bit Server VM (build 25.45-b02, mixed mode)

      ADDITIONAL OS VERSION INFORMATION :
      Windows 7 (Microsoft Windows [Version 6.1.7601])

      A DESCRIPTION OF THE PROBLEM :
      "Arial Unicode MS" font is not rendered correctly when following conditions happen,

      1) "Arial Unicode MS" font, bold style
      2) Anti-aliasing is on
      2) Rotated at an angle close to multiple of 90 degrees from CCM.

      The text high is stretched a lot.

      STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
      Run the attached java code and check the font rendered on the screen

      EXPECTED VERSUS ACTUAL BEHAVIOR :
      EXPECTED -
      The text on the right should be look similar to the left but in bold style.
      ACTUAL -
      The high of the right text is stretched a lot.

      REPRODUCIBILITY :
      This bug can be reproduced always.

      ---------- BEGIN SOURCE ----------
      package javarenderbug;

      import java.awt.Font;
      import java.awt.Graphics;
      import java.awt.Graphics2D;
      import java.awt.RenderingHints;
      import java.awt.font.TextLayout;
      import javax.swing.JFrame;
      import javax.swing.JPanel;

      /**
       * Text rendering bug - not correctly rendering 'Arial Unicode MS' font with Bold and anti-aliasing on.
       */
      public class JavaRenderBug {

      public static void main(String[] args) {
          
      //Java(TM) SE Runtime Environment (build 1.8.0_45-b15)
      //Java HotSpot(TM) 64-Bit Server VM (build 25.45-b02, mixed mode)
          System.out.println(System.getProperties());
          
          final JFrame frame = new JFrame();
          frame.setSize(600, 600);
          frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
          
      // Specific Font
          final Font plain = new Font("Arial Unicode MS", Font.PLAIN, 22);
          final Font bold = new Font("Arial Unicode MS", Font.BOLD, 22);
          
          final JPanel panel = new JPanel(){
            
            /**
             * @see javax.swing.JComponent#paintComponent(java.awt.Graphics)
             */
            @Override
            protected void paintComponent(Graphics g) {
              
              String txt = "Gerbera";

      // Rotate 1 degree CCW
      ((Graphics2D)g).rotate(Math.toRadians(-1));

      // Anti-Aliasing On
      ((Graphics2D)g).setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);

              // Ok.
              // For the PLAIN font, the text painted by g.drawString and the text layout are the same.
              g.setFont(plain);
              g.drawString(txt, 50, 150);

              
              TextLayout tl = new TextLayout(txt,
                  plain,
                  g.getFontMetrics(plain).getFontRenderContext());
              tl.draw((Graphics2D) g, 50, 200);
              
              
              
              // Not Ok.
              // For the BOLD font, the text painted by g.drawString and the text layout are NOT correct, the same as drawGlyphVector() (not shown).
              g.setFont(bold);
              g.drawString(txt, 150, 150);
              
              tl = new TextLayout(txt,
                  bold,
                  g.getFontMetrics(bold).getFontRenderContext());
              // Letters are overlapping..
              tl.draw((Graphics2D) g, 150, 200);
            }
          };
          frame.getContentPane().add(panel);
          frame.setVisible(true);
        }
      }

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

      CUSTOMER SUBMITTED WORKAROUND :
      Instead of draw the text directly with g2d, create the outline of the text and draw the outline shape with g2d. This workaround is very slow though (~26 times).

      Attachments

        Issue Links

          Activity

            People

              prr Philip Race
              webbuggrp Webbug Group
              Votes:
              0 Vote for this issue
              Watchers:
              6 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved: