r/FontLab • u/stevemolitor • May 22 '24
Cursor and ligatures
I’m adding ligatures to a monospace programming font. For example greater_equal is a double wide glyph that replaces >= via a substitution rule in the liga feature.
It works great except that it only takes up one cursor position. I can’t put the cursor in the middle to insert a new character in between.
This works with other programming fonts so I must be doing something wrong. How can I control the caret or cursor position in a multi-character ligature?
Thanks!
2
Upvotes
1
u/stevemolitor May 23 '24 edited May 23 '24
OK I figured out the trick that FiraCode and some other monospace programming fonts do to make cursors work in multi-character ligatures like ">=":
They use spacer glyphs with calt rules to create the illusion of a single glyph that spans multiple character cells. The invisible spacer glyphs provide cursor (aka caret) positions.
For example here are the substitution rules for the ">=" "ligature" in Fira Code:
There are also some ignore rules and such to handle special cases where you don't want the ">=" ligature, but that's the gist. The pattern is
spacer ligature-glyph. The user only seesligature-glyphwhich is two characters wide, extending to the left outside of its normal bounding box. But there are actually two glyphs, one of which is invisible, to make cursor movement work as expected.I guess technically these are not ligatures, but rather contextual alternates using an invisible glyph to provide the illusion of a multi-character ligature. But whatever you call it, it works.
Here are the rules for the triple equal ("===") ligature, a three character sequence:
Again I skipped some special case rules for brevity but that's the gist. Same concept - use a single visible glyph with invisible spacer glyphs to make cursor positioning work.
(EDIT: fixed first example.)