-
Bug
-
Resolution: Fixed
-
P4
-
8u121, 9, 10
-
b23
-
os_x
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.
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.