Ligature issue in TextLayout

The issue is:

  • I create a TextLayout from a standard font on MacOS and draw it,
  • then if I have two letters ‘f’ one after each other, for both letters just one common glyph is created:

Please note that both f’s are joined graphically together, then it is a small gap and next two coupled f’s appear. The typeface name reported for the font is Sans-Serif in sharp brackets. If I change font for something else like standard Arial etc. then it is ok:

It happens for two consecutive f’s only. God knows if that can appear in other cases :slight_smile:

No bug. :slight_smile: Those are called “ligatures” and it is a “feature” of fonts. Some fonts have them; some fonts don’t.

1 Like

Thank you, great, now I know :slight_smile:

The question now is how to know what chars are within a glyph with a ligature. I assume that glyphCode has something to do with it?

That’s a great question. On the Mac, you can use FontBook to look at the character sets, or to try out some sample text with various fonts. Common ligatures are “fi”, “fl”, “ff”, “ffi”, “ffl” “->”, “<-” etc.

Yes, I have to look into this… Basically, I just want to click on some glyph to put a caret in a correct position - and it is simple when number of glyphs corresponds to stringRange of glyph-runs, which is the case for texts without ligatures.

Indeed, these appear for this font:

Screenshot 2023-08-29 at 21.28.59

I see that glyphCodes for them are ordered like 0x04FD, 0x04FE, 0x04FF etc. A whole new world to discover :upside_down_face:

After some quick research, I believe that TextLayout is kind of modern approach to font rendering as it uses direct engines from OS. Using GlyphArrangement instead eliminates problems with ligatures (because one glyph = one char) but there are problems with some languages and fonts. I am referring now to this old discussion:

But if I stay with text rendering and edition using TextLayout, then the problem mentioned above arises: how to get a correct caret position within a set of glyphs with ligatures? From what I see on macOS there is a function just for that: CTFontGetLigatureCaretPositions, but it means forking JUCE and adding extra methods to TextLayout::Glyph etc. And I feel it can be even more complicated. Please correct me if I am wrong?

@stephenk
Have you figured out how to disable ligatures? I see an old topic where your asked about it. I investigated CTFontGetLigatureCaretPositions and it doesn’t give any results. According to the docs: “This function might not be able to produce positions if the font does not have the appropriate data, in which case it will return 0.” Apparently, this is the case :slight_smile: , so my idea is to disable ligatures and still use native font renderings.

I have not. In my case, the only solution was to edit my embedded font to remove the ligatures that I didn’t want. There are other posts on here asking similar things and no one has ever figured out how to disable ligatures or if it is even possible.

I’m not sure what you are trying to do, whether you need to handle text for multiple different fonts, or whether you want to use one particular font for your application. If you want to settle on a font to use, you can edit it to remove ligatures.

I implemented a text editor with capabilities lacking in the regular JUCE TextEditor (different fonts, colours, formatting) to upgrade existing apps and to be used in the future. It is already working but now this ligature issue appeared, and without correct caret positioning it is just useless. I don’t have time to implement a completely new solution based on Harfbuzz etc., so right now it seems that using GlyphArrangment with all its shortcomings is the way to go.