corretto-8
corretto-8 copied to clipboard
Displaying swing text with a big font size is broken
Describe the bug
I have found a problem with displaying text using swing. If a font size is big enough, text is displayed in the wrong way. The size of font to reproduce the problem is different for different fonts, it usually has to be above 1000. The problem is shown on the screenshots.
To Reproduce
I have written very simple application which can be used to reproduce the problem. There is a code:
public static void main( String[] args )
{
JFrame f = new JFrame();// creating instance of JFrame
JLabel jLabel = new JLabel();
jLabel.setFont( new Font( "Dialog", Font.PLAIN, 710 ) );
jLabel.setText( "test" );
jLabel.setBounds( 130, 100, 3100, 1100 );// x axis, y axis, width, height
f.add( jLabel );// adding button in JFrame
f.setSize( 3100, 1100 );// 400 width and 500 height
f.setLayout( null );// using no layout managers
f.setVisible( true );// making the frame visible
}
Expected behavior
Text should be displayed correctly
Screenshots
Platform information
OS: Windows 10
Version: Corretto 265
Additional context
Problem not appear in Java Amazon Corretto <= 1.8.222 (also in case font size = 12000)
Problem appear in Java Amazon correcto >= 1.8.232 (also in 1.8.265)
I have also tested it using AdoptOpenJDK 265 and text was displayed correctly
I suspect the problem may be connected with this issue: https://github.com/corretto/corretto-8/issues/148
Best Regards Konrad
Thank you for this report. We are looking into it.
I just ran the same program on a MacOS Mojave 10.14.6 platform with
OpenJDK Runtime Environment Corretto-8.265.01.1 (build 1.8.0_265-b01) OpenJDK 64-Bit Server VM Corretto-8.265.01.1 (build 25.265-b01, mixed mode)
and I was not able to reproduce the problem. What platform are you running on?
I'm sorry. I see from your report that you are running Windows 10. I'll need to find a way to test that.
We have reproduced the problem and now understand the cause of the problem. One of our engineers shared the following:
I do get what is going on with Corretto. Call for getGlyphMetricsNative lands here: https://github.com/corretto/corretto-8/blob/develop/src/jdk/src/share/native/sun/font/freetypeScaler.c#L661 Which makes a call to Java_sun_font_FreetypeFontScaler_getGlyphImageNative which will hit the MAX_DIM limit and return null, causing the getGlyphMetricsNative to return 0 This affects all JDKs, but it seems some changes in how it is built (or other things) might make the fonts be rendered with slightly different sizes. For example, Adopt works, but only because we are setting the font size to 710. If we increase the font size to 715, then even Adopt will fail and assign 0 for the e width. And also, we see the issue on the e only because it is the wider. If we keep increasing the size, the s will eventually hit that MAX_DIM and also return null, causing the last t to collapse into it. For Corretto, this value seems to be 787. If we keep increasing, even the t will hit that MAX_DIM.
We are exploring a fix. In the meanwhile, understanding what is causing this problem may help you invent a workaround.
JDK-8233097 has been approved for openjdk8u272