JDK-8228763 : Improper kerning adding extra whitespace in some text
  • Type: Bug
  • Component: client-libs
  • Sub-Component: 2d
  • Affected Version: 9,11.0.4
  • Priority: P3
  • Status: Closed
  • Resolution: Duplicate
  • OS: windows_10
  • CPU: x86_64
  • Submitted: 2019-07-23
  • Updated: 2019-08-09
  • Resolved: 2019-08-08
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 14
14Resolved
Related Reports
Duplicate :  
Relates :  
Relates :  
Description
A DESCRIPTION OF THE PROBLEM :
The spacing between some letters has extra whitespace. For example, the word "Options" has extra space between the "O" and the "p" making it look like there is an actual space between the letters -> "O ptions".

This is reproducible when using LCD antialiasing (horizontal or vertical depending on the orientation of your screen) when running with Java 9 through 12. It worked as expected in Java 8 and appears to have been addressed in Java 13 and later, but it would be good to have a backport to Java 11 as the LTS release.

REGRESSION : Last worked in version 8u221

STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
Compile and run the ExtraWhitespace class (source code provided) with JDK 11 on Windows. The "Dialog" physical font should be mapped to "Arial" (the default). This is reproducible when using "Arial" directly as well.

EXPECTED VERSUS ACTUAL BEHAVIOR :
EXPECTED -
Even spacing between letters in the words, especially between the "O" and "p".
ACTUAL -
Extra whitespace following the "O".

---------- BEGIN SOURCE ----------
import java.awt.Font;
import java.awt.RenderingHints;
import java.util.Objects;
import java.util.stream.Stream;
import javax.swing.BoxLayout;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.WindowConstants;

public class ExtraWhitespace {
    public static void main(String... args) {
        JFrame frame = new JFrame("Extra Whitespace");
        frame.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
        frame.getContentPane().setLayout(new BoxLayout(frame.getContentPane(), BoxLayout.PAGE_AXIS));
        frame.add(new JLabel("JDK Version: " + Runtime.version().toString()));
        Stream.of(
                RenderingHints.VALUE_TEXT_ANTIALIAS_DEFAULT,
                RenderingHints.VALUE_TEXT_ANTIALIAS_ON,
                RenderingHints.VALUE_TEXT_ANTIALIAS_GASP,
                RenderingHints.VALUE_TEXT_ANTIALIAS_LCD_HRGB,
                RenderingHints.VALUE_TEXT_ANTIALIAS_LCD_HBGR,
                RenderingHints.VALUE_TEXT_ANTIALIAS_LCD_VRGB,
                RenderingHints.VALUE_TEXT_ANTIALIAS_LCD_VBGR)
                .map(ExtraWhitespace::createLabel)
                .forEach(frame::add);

        frame.pack();
        frame.setVisible(true);
    }

    private static JLabel createLabel(Object aa) {
        JLabel label = new JLabel(String.format("Options - %s", Objects.toString(aa)));
        label.setFont(new java.awt.Font("Dialog", Font.BOLD, 11));
        label.putClientProperty(RenderingHints.KEY_TEXT_ANTIALIASING, aa);
        return label;
    }
}
---------- END SOURCE ----------

CUSTOMER SUBMITTED WORKAROUND :
Use a different font either in the code or via a custom font configuration file.

FREQUENCY : always



Comments
I would also like to add that as per my observation the issue is getting resolved in jdk11 by applying the changeset in the bug-8217731(changeset # 55369:18629738b64b) in windows 7 but the fix is not working for windows 10. Please find the attached image(Compare_ExtraWhitespace.png) which shows result in jdk 11.0.4 (without any changes)-left side and result in 11.0.5 internal build which has changeset 55369:18629738b64b imported(right side in the image) .Both the screens are from Windows 7 and shows that the issue is resolved after backporting the fix. I have also attached the image jdk11.0.5_internal_build_with_changeset_5536918629738b64b.PNG which is taken from windows 10 with the changeset imported in jdk11uCPU but still has extra space between O and P which means issue is not resolved even after backporting the fix in windows 10. So the summary is that backporting of fix JDK-8217731 resolves the issue in windows 7 but not in windows 10. Please correct me if my understanding is wrong.
09-08-2019

To make the test case compatible for JDK 8u221 ,I commented the line # 16 (frame.add(new JLabel("JDK Version: " + Runtime.version().toString())); ) as this line is just used to print the version and doesn't play any role in the functionality. I found that the spacing is proper in JDK 8u221. But I see some difference in space between O and P in jdk 13 and 14 in the fourth and fifth line. Please refer the attached images for jdk 8u221, jdk13 and jdk14 . Please let me know if my observation or understanding is wrong.
09-08-2019

NB https://bugs.openjdk.java.net/browse/JDK-8217731 is already labeled with 11-bp indicating my intention to backport.
08-08-2019

> This issue is not a duplicate one and exists in latest version 14 as well. PFA the screenshot from 14 version. Please support this comment with some data. There is an attached image from JDK 14 which looks quite OK to me. I am specifically looking at the "Op" spacing. The submitter themselves say the problem they are complaining about is fixed in 13, so whatever you are seeing must be something else. What are you comparing it with ? Provide the image from 8 for comparison. But I am quite suspicious since the test case uses a JDK 9 API Runtime.version() and also the client property setting to set the AA mode also doesn't work on 8 .. It uses functionality added in 9 under https://bugs.openjdk.java.net/browse/JDK-6302464 Also you need to be aware that JDK 9 and later supports hi-dpi so if you are running at > 96 dpi then YES the spacing will necessarily be different because the font size is different. In the absence of supporting evidence and the fact that this test case can't have been run on 8, I don't see a reason to keep it open and closing as a duplicate was the right decision.
08-08-2019

This issue is not a duplicate one and exists in latest version 14 as well. PFA the screenshot from 14 version.
08-08-2019