JDK-8204527 : Ligatures not Rendering for TrueType Fonts
  • Type: Bug
  • Component: client-libs
  • Sub-Component: 2d
  • Affected Version: 8,9,10,11
  • Priority: P3
  • Status: Closed
  • Resolution: Not an Issue
  • OS: generic
  • CPU: x86_64
  • Submitted: 2018-06-04
  • Updated: 2018-07-13
  • Resolved: 2018-06-28
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.
Other
tbd_majorResolved
Description
ADDITIONAL SYSTEM INFORMATION :
I'm running a mac with OSX on the latest release of Java 10 (build 10.0.1+10), using NetBeans IDE 8.2 (Build 201609300101)

A DESCRIPTION OF THE PROBLEM :
NOTE: I have marked this as an OSX problem, but have also reproduced it on Windows environments

I've encountered a bug that appears when using TrueType fonts. Specifically those created in FontForge (although they appear when rendered outside of Java environments).

Here is a very simple font I've which activates the bug: https://drive.google.com/file/d/1I0mzw_cX-WFXddji0GHEu9AhoBDJ81OA/view?usp=sharing

If you load the font via another text program (notepad in Windows or TextEdit in OSX), typing capital "AB" will result in the correct behavior (see Expected Result) of a ligature for AB being rendered.

REGRESSION : Last worked in version 10.0.1

STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
1) Install linked font (in description) to local environment (only necessary if selecting font from OS based on family name)
2) Create font object via 
    - Font font = new Font("Untitled1", Font.PLAIN, 42);
    OR
    - Font font = Font.createFont(Font.TRUETYPE_FONT, new File(<PATH TO FONT>));
3) On a simple Swing form, create a JTextField and set its font to what you've just loaded.
4) Run the Form
5) In the JTextBox on the running form, type capital "AB" with no spaces

EXPECTED VERSUS ACTUAL BEHAVIOR :
EXPECTED -
As you type A, a crude "1" should be displayed. As you type B, a crude "3" should not be displayed. The "3" character is the ligature which represents a combination of A and B when typed together with no spaces.
ACTUAL -
As you type A, a crude "1" appears. As you type B, a crude "2" appears. No ligature for the two is displayed.

---------- BEGIN SOURCE ----------
// You must install the linked font to the local environment before this code will run correctly
// OR use the commented code with the path to the font (which you still must download)
import java.awt.Font;

public class TestFontBug extends javax.swing.JFrame {
    public TestFontBug() {
        initComponents();
	Font font = new Font("Untitled1", Font.PLAIN, 42);

        // ALTERNATE FONT LOADING METHOD (results will be the same)
        // Font font = Font.createFont(Font.TRUETYPE_FONT, new File(<PATH TO FONT>));
	
        jTextField1.setFont(font);
    }
                     
    private void initComponents() {

        jTextField1 = new javax.swing.JTextField();

        setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);

        jTextField1.setText("jTextField1");

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addGap(136, 136, 136)
                .addComponent(jTextField1, javax.swing.GroupLayout.PREFERRED_SIZE, 197, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap(67, Short.MAX_VALUE))
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addGap(108, 108, 108)
                .addComponent(jTextField1, javax.swing.GroupLayout.PREFERRED_SIZE, 122, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap(70, Short.MAX_VALUE))
        );

        pack();
    }                      

    public static void main(String args[]) {
        new TestFontBug().setVisible(true);
    }
               
    private javax.swing.JTextField jTextField1;
}
---------- END SOURCE ----------

CUSTOMER SUBMITTED WORKAROUND :
I have not found one.

FREQUENCY : always



Comments
Adding this code, ligatures appear : Map <TextAttribute, Object> map = new HashMap<>(); map.put(TextAttribute.LIGATURES, TextAttribute.LIGATURES_ON); font = font.deriveFont(map); the extent to which Swing supports this is another matter, but it renders correctly for me.
28-06-2018

> REGRESSION : Last worked in version 10.0.1 Ignore that above. It is wrong information. As to the issue, Java won't automatically do optional ligatures. You need to ask for it. See https://docs.oracle.com/javase/8/docs/api/java/awt/font/TextAttribute.html#LIGATURES
28-06-2018

Response from Submitter ----------------------- As soon as I saw what you were looking at, I realized that I had given you the wrong font. I was messing with the creation utility a bit and the one I sent you does not have ligatures at all. Here is the correct font: https://drive.google.com/open?id=1QWPfB8LIZsGwJCkNj1bBaW1hCk-wPm_h Here is a screen of what the sequence "ABC" looks like, with the ligature properly displaying (the cursor is in the center of the ligature character, as it represents two characters, itself): https://drive.google.com/file/d/1p-ww12Jxg3cfb-oU6m7f6A5_nnpFdlH6/view?usp=sharing And here is a screen of what the sequence "A BC" looks like (note the space): https://drive.google.com/file/d/1EReAEX91PMk1DpCP10_oc9mXG-bPa5Mp/view?usp=sharing Sorry about the mixup, and please let me know if there's anything else I can do to help! ----------------------- After installing new Font , provided by SUbmitter, issue is now reproducible in Windows and macOS with all JDK 8, 9, 10, 11. When setting same Font in 'Notepad, typing"AB" gives "3", where as in Java program it gives "12".
28-06-2018

Installed the provided font ('Untitled4.ttf') and then ran the test case in JDK 10.0.1+10. Behavior is same as in any Text Editor program (notepad in Windows or TextEdit in macOS). Typing 'A' displays '1' and then immediately typing 'B' displays '2'. PFA screenshots of ran test case in Windows 10 and macOS High Sierra (10.13.3) Also PFA for TextEdit in macOS. Above behavior is same in all JDK - 8b132, 8u172, 10.0.1 & 11-ea+13. From description expected result is not clear. "EXPECTED - As you type A, a crude "1" should be displayed. As you type B, a crude "3" should not be displayed. The "3" character is the ligature which represents a combination of A and B when typed together with no spaces. " Looks like Submitter is expecting '3' to be displayed when 'B' is typed after 'A'. Requested Submitter to clarify same.
07-06-2018