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

[macos] Wrong rendering of string containing surrogate pairs

    XMLWordPrintable

Details

    • Bug
    • Resolution: Fixed
    • P4
    • 10
    • 8u121, 9, 10
    • client-libs
    • 2d
    • b23
    • os_x

    Description

      Rendering of a string can produce unexpected results on macOS (first character not rendering) if the string contains a surrogate pair. To reproduce the issue, run the following sample program:

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

      public class DrawTextTest {
          public static void main(String[] args) {
              SwingUtilities.invokeLater(() -> {
                  JFrame f = new JFrame();
                  f.add(new MyComponent());
                  f.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
                  f.setSize(150, 100);
                  f.setLocationRelativeTo(null);
                  f.setVisible(true);
              });
          }

          private static class MyComponent extends JComponent {
              @Override
              protected void paintComponent(Graphics g) {
                  g.drawString("Hello", 50, 30);
                  g.drawString("Hello" + new String(Character.toChars(0x1D400)), 50, 60);
              }
          }
      }

      It’s expected to see the word ‘Hello’ rendered correctly on both lines. Instead, on the second line, a box is rendered in place of ‘H’ letter (see attached image, obtained by running the program using build 9-ea+156).

      The issue can be reproduced with latest Java 8 (8u121) and 9 (9-ea+156) builds.

      Attachments

        Activity

          People

            dbatrak Dmitry Batrak
            dbatrak Dmitry Batrak
            Votes:
            0 Vote for this issue
            Watchers:
            3 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved: