JDK-8178025 : HiDPI with non-integer scale factor - SPANs in HTML are rendered overlapping each other
  • Type: Bug
  • Component: client-libs
  • Sub-Component: javax.swing
  • Affected Version: 9
  • Priority: P3
  • Status: Resolved
  • Resolution: Fixed
  • OS: other
  • CPU: x86
  • Submitted: 2017-04-04
  • Updated: 2019-05-21
  • Resolved: 2017-11-16
The Version table provides details related to the release that this issue/RFE will be addressed.

Unresolved : Release in which this issue/RFE will be addressed.
Resolved: Release in which this issue/RFE has been resolved.
Fixed : Release in which this issue/RFE has been fixed. The release containing this fix may be available for download as an Early Access Release or a General Availability Release.

To download the current JDK release, click here.
JDK 10
10 b34Fixed
Related Reports
Relates :  
Relates :  
Description
FULL PRODUCT VERSION :
java 9-ea
Java(TM) SE Runtime Environment (build 9-ea+163)
Java HotSpot(TM) 64-Bit Server VM (build 9-ea+163, mixed mode)

ADDITIONAL OS VERSION INFORMATION :
Microsoft Windows [Version 10.0.14393]

A DESCRIPTION OF THE PROBLEM :
When using a non-integer resolution (e.g. 225%) for a HiDPI display, the Swing HTML rendering incorrectly calculates the width of SPAN elements which results in SPANs being incorrectly positioned and overlapping with each other.

I assume this is a bug in the implementation of http://openjdk.java.net/jeps/263 as it worked correctly in Java 8.

REGRESSION.  Last worked in version 8u121

ADDITIONAL REGRESSION INFORMATION: 
java version "1.8.0_121"
Java(TM) SE Runtime Environment (build 1.8.0_121-b13)
Java HotSpot(TM) 64-Bit Server VM (build 25.121-b13, mixed mode)

STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
Run the attached code


EXPECTED VERSUS ACTUAL BEHAVIOR :
EXPECTED -
I expect the displayed text to show "A few words to get started before the bugoverlapping text"


ACTUAL -
The 'g' at the end of the word "bug" is rendered over the top of the 'o' in the start of "overlapping text"

REPRODUCIBILITY :
This bug can be reproduced always.

---------- BEGIN SOURCE ----------
package bugDemo;

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

public class Java9BugTest {
    public static void main(String[] args) {
        JLabel label = new JLabel("<html><span>A few words to get started before the bug</span><span>overlapping text</span></html>");
        JFrame frame = new JFrame("");
        frame.getContentPane().add(label, BorderLayout.CENTER);
        frame.setSize(500,500);
        frame.setVisible(true);
    }
}
---------- END SOURCE ----------


Comments
Fix available pending for review http://mail.openjdk.java.net/pipermail/swing-dev/2017-November/007899.html
06-11-2017

When a JLabel with an html text is created the GlyphPainter1.getSpan() uses a FontrenderedContext with transform scale 1. The FontRenderingContext with new transform when the JLabel is added to a window and the window is shown. BoxView spans should be recalculated. GlyphPainter1.getSpan() should use Utilities.getTabbedTextWidth(...) method with float x.
17-04-2017

This seems a regression in 9 as it works fine with 8u121. When checked with 8u121 b13 and 8u152 b02, rendering works fine as expected. However in 9 ea b163 the Swing HTML renders incorrectly with overlapped SPAN. (See attached screenshots) Referred JEP: http://openjdk.java.net/jeps/263 To confirm, run the attached test program. Result: ======= 8u121 b13: Ok 8u152 ea b02: OK 9 ea b163: FAIL
04-04-2017