I've run into a problem that has me really scratching my head when dealing with Swing objects in java (and JFX as well, but I'll worry about that later...).
Here is the code that I am using to open fonts in my program. It's pretty standard.
My problem is that when I actually go to use these fonts, ligatures within them are not respected when typing. One of the core features of my program allows users to load custom fonts, many of which have specialized ligatures. These are being ignored by Java, and I'm not sure what I am doing wrong. If the user types two characters that should reduce to a single ligature, the second character just appears normally, with no transformation taking place. When I load the fonts into any other program or text editor I'm seeing the ligatures be respected exactly as I would anticipate.
I've stripped down code where I'm actually setting the font in a few places to the absolute bare bones and I'm seeing the (wrong) behavior even in places where I'm doing something as simple as:
Is there some setting on import that I am missing? Or that needs to be globally flipped on the 2D graphics object? Any assistance would be really appreciated. Thanks,
I don't believe that is the case for a number of reasons.
1) When I install the fonts in question, the ligatures appear correctly in writing programs (tested across multiple OSes)
2) This is happening with multiple fonts
3) This has been reported by multiple users
I'm not sure what my users are using to create their ligatures, but I got a flood of complaints about this one issue months out from when I made a release. So I think that there was some Java update that broke how it's respecting ligatures in at least some way.
Stephan van Hulst
posted 1 year ago
Your first two points only support what I've already said: You probably encode or normalize the string wrongly.
Can you enter an offending string into your application, and then copy it from the GUI and paste it in a new post in this topic, without making any alterations?
Please also explain what you're seeing, and what you want the string to look like.
The fonts are custom linguistic scripts, so copy/pasting them directly won't work. Below are screen captures of what I'm seeing within my program and in a typical text editor. I've simply hit 'q' multiple times, which when occurring twice in a row should be represented as a ligature. In the second case, I copy/pasted from the first into a text editor. Notice that since there are an odd number of the character typed, only the first two collapsed into the ligature, leaving the last (correctly) displaying as its basic form.
Here's what I'm seeing in my program (ligatures not respected):
And here's what I'm seeing in a text editor (ligatures respected):
As you can see, when two of the character seen in the first image exist next to one another, each pair should collapse into a symbol with a dot beneath it. It's the fact that the ligatures are respected outside of Java that makes me think that there's some setting that I need to hit within my program to make them be respected. This happens even when I use 100% vanilla text JTextField objects after loading the font normally (as in the initial post).
You mention that I might be encoding the string incorrectly, but this is direct user input when they are typing in fields. Is there something that I need to do there which affects its encoding?
Additionally, check this test out. Here, I am just using Times New Roman, loaded directly from the OS. If you look closely at the "fl" combination there, you'll see that only the text editor is respecting the ligature character which is to render when 'f' and 'l' appear directly next to one another in Times New Roman.
Ligatures are clearly not being respected between the Java application and the external text editor here, and I'm really puzzling over what could be causing this. I'm running on the latest Java 10 version as of now.
Stephan van Hulst
posted 1 year ago
Can you please copy and paste the text from both editors (no matter how they render), and can you tell us what font and font format you're using?
Both of the texts below are Ang-Yultz (a user's custom font that they've sent in to help me track the bug):
Copied from PolyGlot (broken): qqqqq
Copied from alternate text editor (working): qqqqq
The font is True Type font, and was created using Font Forge. I'm unfortunately not able to post the font itself here because the user is not ready to release it yet.
I'm thinking that the problem lies between FontForge itself and Java. Either FF is encoding ligatures incorrectly, or there's something in Java that is not reading them correctly in a case that's created in FF generated true type fonts.
Also, as an addendum, fonts that are created in FontForge and which use ligatures work 100% correctly through OSes that I've tested with (Windows and OSX). I'm linking to a very basic font that I've created. Capital A, B, and C are all encoded as a sloppy '1', '2', and '3'. The ligature for AB is represented as C. So if you type "AB" in this font, is should display a sloppy looking '3' glyph.
Ok. So. This one was frustrating, as I had been correctly setting the TextAttributes, while loading fonts via a method which is plagued by a long standing bug.. Ligatures are supposed to be represented in JTextFields and JTextAreas, but under certain circumstances, they will not be. There are two things to keep in mind.