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

Wrong glyphs are rendered on Windows when subpixel antialiasing is enabled

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Unresolved
    • Icon: P4 P4
    • tbd
    • 8u152, 9.0.1
    • client-libs
    • None
    • 2d
    • windows

      Steps to reproduce:
      1) Install Source Code Pro font from https://github.com/adobe-fonts/source-code-pro/archive/2.030R-ro/1.050R-it.zip
      (install all fonts from TTF subfolder)
      2) Set system locale to Russian
      (on Windows 10 it's done in Control Panel -> Region -> Administrative -> Language for non-Unicode programs -> Change system locale...,
      reboot is required)
      3) Run the sample program with source given below.

      Expected result: '123' digits are rendered in opened window (see attached renderingWithUSLocale.png).
      Actual result: different glyphs are rendered (see attached renderingWithRussianLocale.png).

      The issue is reproduced with latest Java 8 (1.8.0_152) and 9 (9.0.1) release builds.

      ---Sample program source code start---

      import javax.swing.*;
      import java.awt.*;

      public class FontDrawingTest {
          public static void main(String[] args) {
              GraphicsEnvironment.getLocalGraphicsEnvironment().getAllFonts();
              SwingUtilities.invokeLater(() -> {
                  JFrame frame = new JFrame();
                  frame.add(new MyComponent());
                  frame.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
                  frame.setSize(200, 200);
                  frame.setLocationRelativeTo(null);
                  frame.setVisible(true);
              });
          }

          private static class MyComponent extends JComponent {
              private final Font font = new Font("Source Code Pro", Font.ITALIC, 24);
              private final String text = "123";

              @Override
              protected void paintComponent(Graphics g) {
                  ((Graphics2D) g).setRenderingHint(RenderingHints.KEY_TEXT_ANTIALIASING,
                                                    RenderingHints.VALUE_TEXT_ANTIALIAS_LCD_HRGB);
                  g.setFont(font);
                  g.drawString(text, 70, 80);
              }
          }
      }

      ---Sample program source code end---

        1. renderingWithRussianLocale.png
          2 kB
          Dmitry Batrak
        2. renderingWithUSLocale.png
          2 kB
          Dmitry Batrak

            prr Philip Race
            dbatrak Dmitry Batrak
            Votes:
            0 Vote for this issue
            Watchers:
            5 Start watching this issue

              Created:
              Updated: