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

Consolas font displayed incorrectly in Swing

XMLWordPrintable

    • 2d
    • x86_64
    • linux_ubuntu

      A DESCRIPTION OF THE PROBLEM :
      It seems that the "Consolas" font is displayed incorrectly in Swing
      (JTextField, JButton, etc.) due to different font metrics
      between old T2K and new (FreeType?) font engine.
      This can be reproduced on both Linux and Windows.

      Test result:
      https://imgur.com/a/uvwQzWF

      FontMetrics for new Font("Consolas", Font.BOLD, 32) as printed in the test code are:

      In OpenJDK 9/10/11-ea:
      ascent=24, descent=9, height=38

      In Oracle JRE 9/10:
      ascent=27, descent=6, height=38

      This problem does not occur in Oracle JRE 11-ea
      when running with -Dsun.java2d.font.scaler=t2k option (Windows).

      EXPECTED VERSUS ACTUAL BEHAVIOR :
      EXPECTED -
      Correct vertical text position
      ACTUAL -
      Text shifted up

      ---------- BEGIN SOURCE ----------
      import java.awt.*;
      import javax.swing.*;

      public class Test extends JFrame {

      Test() {
      super("Test");
      setDefaultCloseOperation(EXIT_ON_CLOSE);

      JButton b = new JButton("qq Consolas Font Test yy");
      b.setFont(new Font("Consolas", Font.BOLD, 32));
      add(b);

      pack();
      setVisible(true);
      }

      public static void main(String[] args) {
      SwingUtilities.invokeLater(Test::new);
      }

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

      CUSTOMER SUBMITTED WORKAROUND :
      Use older "Lucida Console" font on Windows

      FREQUENCY : always


        1. results.png
          results.png
          62 kB
        2. Test.java
          0.4 kB

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

              Created:
              Updated: