corretto-8 icon indicating copy to clipboard operation
corretto-8 copied to clipboard

Displaying swing text with a big font size is broken

Open Konradkurcaba opened this issue 4 years ago • 6 comments

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

corretto_265 corretto_222

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

Konradkurcaba avatar Aug 05 '20 09:08 Konradkurcaba

Thank you for this report. We are looking into it.

kdnilsen avatar Aug 06 '20 00:08 kdnilsen

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?

kdnilsen avatar Aug 06 '20 02:08 kdnilsen

I'm sorry. I see from your report that you are running Windows 10. I'll need to find a way to test that.

kdnilsen avatar Aug 06 '20 02:08 kdnilsen

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.

kdnilsen avatar Aug 07 '20 17:08 kdnilsen

Hi,

It seems this problem is also reported as JDK-8233097

alvdavi avatar Aug 11 '20 22:08 alvdavi

JDK-8233097 has been approved for openjdk8u272

alvdavi avatar Aug 12 '20 17:08 alvdavi