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

Improper kerning adding extra whitespace in some text

XMLWordPrintable

    • 2d
    • x86_64
    • windows_10

      A DESCRIPTION OF THE PROBLEM :
      The spacing between some letters has extra whitespace. For example, the word "Options" has extra space between the "O" and the "p" making it look like there is an actual space between the letters -> "O ptions".

      This is reproducible when using LCD antialiasing (horizontal or vertical depending on the orientation of your screen) when running with Java 9 through 12. It worked as expected in Java 8 and appears to have been addressed in Java 13 and later, but it would be good to have a backport to Java 11 as the LTS release.

      REGRESSION : Last worked in version 8u221

      STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
      Compile and run the ExtraWhitespace class (source code provided) with JDK 11 on Windows. The "Dialog" physical font should be mapped to "Arial" (the default). This is reproducible when using "Arial" directly as well.

      EXPECTED VERSUS ACTUAL BEHAVIOR :
      EXPECTED -
      Even spacing between letters in the words, especially between the "O" and "p".
      ACTUAL -
      Extra whitespace following the "O".

      ---------- BEGIN SOURCE ----------
      import java.awt.Font;
      import java.awt.RenderingHints;
      import java.util.Objects;
      import java.util.stream.Stream;
      import javax.swing.BoxLayout;
      import javax.swing.JFrame;
      import javax.swing.JLabel;
      import javax.swing.WindowConstants;

      public class ExtraWhitespace {
          public static void main(String... args) {
              JFrame frame = new JFrame("Extra Whitespace");
              frame.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
              frame.getContentPane().setLayout(new BoxLayout(frame.getContentPane(), BoxLayout.PAGE_AXIS));
              frame.add(new JLabel("JDK Version: " + Runtime.version().toString()));
              Stream.of(
                      RenderingHints.VALUE_TEXT_ANTIALIAS_DEFAULT,
                      RenderingHints.VALUE_TEXT_ANTIALIAS_ON,
                      RenderingHints.VALUE_TEXT_ANTIALIAS_GASP,
                      RenderingHints.VALUE_TEXT_ANTIALIAS_LCD_HRGB,
                      RenderingHints.VALUE_TEXT_ANTIALIAS_LCD_HBGR,
                      RenderingHints.VALUE_TEXT_ANTIALIAS_LCD_VRGB,
                      RenderingHints.VALUE_TEXT_ANTIALIAS_LCD_VBGR)
                      .map(ExtraWhitespace::createLabel)
                      .forEach(frame::add);

              frame.pack();
              frame.setVisible(true);
          }

          private static JLabel createLabel(Object aa) {
              JLabel label = new JLabel(String.format("Options - %s", Objects.toString(aa)));
              label.setFont(new java.awt.Font("Dialog", Font.BOLD, 11));
              label.putClientProperty(RenderingHints.KEY_TEXT_ANTIALIASING, aa);
              return label;
          }
      }
      ---------- END SOURCE ----------

      CUSTOMER SUBMITTED WORKAROUND :
      Use a different font either in the code or via a custom font configuration file.

      FREQUENCY : always


        1. Compare_ExtraWhitespace.png
          Compare_ExtraWhitespace.png
          30 kB
        2. ExtraWhitespace.java
          1 kB
        3. jdk11.0.5_internal_build_with_changeset_5536918629738b64b.PNG
          jdk11.0.5_internal_build_with_changeset_5536918629738b64b.PNG
          26 kB
        4. jdk13.png
          jdk13.png
          31 kB
        5. jdk14.png
          jdk14.png
          36 kB
        6. jdk8u221.png
          jdk8u221.png
          49 kB
        7. Observation_Version14.png
          Observation_Version14.png
          30 kB

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

              Created:
              Updated:
              Resolved: