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

Segoe UI font not rendered correctly in dialogs with transparent background

XMLWordPrintable

    • 2d
    • b01
    • x86_64
    • windows_10

      ADDITIONAL SYSTEM INFORMATION :
      Windows 10
      OpenJDK 11.0.8 and OpenJDK 15.0.1

      A DESCRIPTION OF THE PROBLEM :
      When drawing a String in an undecorated dialog with a transparent background with the font family 'Segoe UI' the String looks distorted (quasi bold) in comparison to the String drawn in a normal frame.
      This seems to be a problem with the text antialiasing. This worked correctly in OpenJDK 11.0.2 and is broken at least since OpenJDK 11.0.4.

      REGRESSION : Last worked in version 11

      STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
      Run the attached source code example to see the problem

      EXPECTED VERSUS ACTUAL BEHAVIOR :
      EXPECTED -
      The String rendered in the window opened when pressing the button looks the same as the String rendered under the button.
      ACTUAL -
      The String rendered in the window opened when pressing the button looks different from the String rendered under the button (looks quasi bold).

      ---------- BEGIN SOURCE ----------
      import javax.swing.BoxLayout;
      import javax.swing.JFrame;
      import javax.swing.JWindow;
      import javax.swing.WindowConstants;
      import java.awt.Button;
      import java.awt.Color;
      import java.awt.Component;
      import java.awt.Container;
      import java.awt.Font;
      import java.awt.Graphics;
      import java.awt.Graphics2D;
      import java.awt.RenderingHints;

      public final class AwtSample {
        private static final Font FONT_SEGOE_UI = new Font("Segoe UI", Font.PLAIN, 13);

        public static void main(String[] args) {
          JFrame frame = new JFrame("Sample");
          frame.setSize(500, 200);
          frame.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);

          Button button = new Button("Click me");
          button.setBackground(Color.WHITE);
          button.addActionListener(__ -> {
            JWindow dialog = new JWindow();
            dialog.setSize(110, 110);
            dialog.setLocationRelativeTo(button);
            dialog.setBackground(new Color(255, 255, 255, 0));

            Component canvas = createCanvas();
            dialog.add(canvas);

            dialog.setVisible(true);
          });

          Container contentPane = frame.getContentPane();
          contentPane.setBackground(Color.WHITE);
          contentPane.setLayout(new BoxLayout(contentPane, BoxLayout.Y_AXIS));
          contentPane.add(button);
          contentPane.add(createCanvas());

          frame.setVisible(true);
        }

        private static Component createCanvas() {
          Component canvas = new Component() {
            @Override
            public void paint(Graphics g) {
              ((Graphics2D) g).setRenderingHint(RenderingHints.KEY_TEXT_ANTIALIASING, RenderingHints.VALUE_TEXT_ANTIALIAS_LCD_HRGB);
              super.paint(g);
              g.setFont(FONT_SEGOE_UI);
              g.drawString("Test", 12, 50);
            }
          };
          canvas.setSize(100, 100);
          return canvas;
        }
      }
      ---------- END SOURCE ----------

      FREQUENCY : always


        1. AwtSample.java
          2 kB
        2. Capture_1.JPG
          Capture_1.JPG
          34 kB
        3. Capture_11_0_5.JPG
          Capture_11_0_5.JPG
          23 kB
        4. Capture_11_0_5.PNG
          Capture_11_0_5.PNG
          5 kB
        5. Capture_11_0_6.JPG
          Capture_11_0_6.JPG
          32 kB
        6. Capture_11_0_6.PNG
          Capture_11_0_6.PNG
          20 kB
        7. Capture.JPG
          Capture.JPG
          50 kB
        8. Capture.png
          Capture.png
          13 kB

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

              Created:
              Updated:
              Resolved: