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

Font Glyph spacing wrong with Windows highdpi scaling and certain font sizes

    XMLWordPrintable

Details

    • 2d
    • x86_64
    • windows_10

    Description

      ADDITIONAL SYSTEM INFORMATION :
      Windows 10
      Java 18ea, also tested with Java 16 and 11

      A DESCRIPTION OF THE PROBLEM :
      When using a Java Swing Application on Windows with display scaling enabled, the spacing between characters is not correct with some font sizes.
      The example uses the Tahoma font with size 11, but the bug also occurs with other fonts.

      With Tahoma, Size 11 the space between the characters 't' and 'i' and 'D' and 'e' is too large, when viewed on a display scaled to 125%.

      This bug may also occur with different scaling factors and font sizes, but using font size 11 with 125% causes the most apparent issues.

      STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
      Launch the provided example on Windows and change the display scaling from 100% to 125% (or move the application to a scaled display).

      EXPECTED VERSUS ACTUAL BEHAVIOR :
      EXPECTED -
      The spacing between glyphs for font size 11 would look the same as with 100% scaling, but larger
      ACTUAL -
      The spacing between character 't' and 'i' gets significantly larger, so it almost looks like an extra space is inserted.
      The spacing between 'D' and 'e' also gets significantly larger.

      Note that the text with font size 12 does not seem to be effected

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

      import javax.swing.Box;
      import javax.swing.JFrame;
      import javax.swing.JLabel;

      public class TestDPI {

      public static void main(String[] args) {
      JFrame frame = new JFrame();
      frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

      JLabel txtField = new JLabel();

      JLabel txtField2 = new JLabel();

      txtField.setText("Size 11: ititit Detail");
      txtField.setFont(new Font("Tahoma", Font.PLAIN, 11));

      txtField2.setText("Size 12: ititit Detail");
      txtField2.setFont(new Font("Tahoma", Font.PLAIN, 12));

      Box box = Box.createVerticalBox();
      box.add(txtField);
      box.add(txtField2);

      frame.add(box);

      frame.pack();
      frame.setVisible(true);
      }
      }
      ---------- END SOURCE ----------

      CUSTOMER SUBMITTED WORKAROUND :
      Not using Font size 11 when expecting users to use Windows display scaling.

      FREQUENCY : always


      Attachments

        1. Capture_100%.PNG
          Capture_100%.PNG
          2 kB
        2. Capture_125%.PNG
          Capture_125%.PNG
          3 kB
        3. Capture_150%.PNG
          Capture_150%.PNG
          4 kB
        4. Capture_175%.PNG
          Capture_175%.PNG
          5 kB
        5. TestDPI.java
          0.7 kB

        Activity

          People

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

            Dates

              Created:
              Updated: