• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • paul wheaton
  • Paul Clapham
  • Ron McLeod
Sheriffs:
  • Jeanne Boyarsky
  • Liutauras Vilda
Saloon Keepers:
  • Tim Holloway
  • Carey Brown
  • Roland Mueller
  • Piet Souris
Bartenders:

Font Ligatures Ignored in Swing Display Objects

 
Ranch Hand
Posts: 74
6
Netbeans IDE Python Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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,
 
Bartender
Posts: 15743
368
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
When you use the standard font, does the ligature render correctly?

I suspect this has nothing to do with the font, you've probably encoded your ligature wrongly.
 
Draque Thompson
Ranch Hand
Posts: 74
6
Netbeans IDE Python Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Bartender
Posts: 15743
368
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
Draque Thompson
Ranch Hand
Posts: 74
6
Netbeans IDE Python Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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?
 
Draque Thompson
Ranch Hand
Posts: 74
6
Netbeans IDE Python Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Bartender
Posts: 15743
368
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I see.

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?
 
Draque Thompson
Ranch Hand
Posts: 74
6
Netbeans IDE Python Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
Draque Thompson
Ranch Hand
Posts: 74
6
Netbeans IDE Python Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.

https://drive.google.com/file/d/1I0mzw_cX-WFXddji0GHEu9AhoBDJ81OA/view?usp=sharing
 
Draque Thompson
Ranch Hand
Posts: 74
6
Netbeans IDE Python Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
UPDATE:

It looks like this is actually a bug to how Java decodes ligatures in very particular circumstances. I've filed a bug report with Oracle and will update here when there's more to post.
 
Stephan van Hulst
Bartender
Posts: 15743
368
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
No. It seems that JTextField just doesn't take ligatures in fonts into account.

In contrast to what I said in my very first response, this isn't an encoding issue, because the text is encoded the same way in your application and in the text editor.

I don't think this is a bug. JTextField just doesn't deal with ligatures. You might want to search online for third party Swing components, or you can see if JavaFX handles ligatures correctly.
 
Draque Thompson
Ranch Hand
Posts: 74
6
Netbeans IDE Python Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
FOUND IT.

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.

1) There is an old bug (https://bugs.openjdk.java.net/browse/JDK-8139741) which prevents ligatures from being respected when using the pattern



Instead, the font ligatures will only be respected if it is loaded from a binary location:



2) Once the font is loaded from binary, ligatures must be set via TextAttributes like so:



When loading fonts directly from the OS, I've taken to finding the actual font file on the system and loading it as a binary. It's cumbersome, but it functions.
 
Marshal
Posts: 28425
102
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Well. Who would have expected that? Thanks for posting the result of your research, and for doing so I gave you not one but TWO cows.
 
reply
    Bookmark Topic Watch Topic
  • New Topic