I have discretionary ligature glyphs for A_T, T_T, T_L, and L_E. Right now I can type out the word RATTLE, and the A_T and L_E ligatures both work fine (as in the screenshot).
But I would actually like to “prioritize” the T_T ligature, meaning that the glyphs would be R, A, T_T, and L_E.
I 'm not exactly sure how prioritize the T_T, or what I documentation I should be looking for, or even if I’m thinking about this the right way. I’m comfortable writing Python, so if that’s the way to do this, just let me know. Any help would be great!
I have a similar issue but with liga.
I have the ligatures “greater_hyphen” and “hyphen_hyphen_hyphen,” and I want to prioritize “hyphen_hyphen_hyphen” over “greater_hyphen.”
What should I do? I´m completely lost on this topic
When you have a text >--- and those ligature rules
sub hyphen hyphen hyphen by hyphen_hyphen_hyphen;
sub greater hyphen by greater_hyphen;
the greater_hyphen ligature will always take precedence because it matches “earlier” in the input string. To avoid that, you need to use separate lookups, or use ignore sub rules:
lookup TRIPLE_HYPHEN {
sub hyphen hyphen hyphen by hyphen_hyphen_hyphen;
} TRIPLE_HYPHEN;
lookup OTHER {
sub greater hyphen by greater_hyphen;
# ...
} OTHER;
or
sub hyphen hyphen hyphen by hyphen_hyphen_hyphen;
ignore sub greater' hyphen' hyphen hyphen;
sub greater hyphen by greater_hyphen;
Another caveat is that the substitutions are not necessarily stored in the font in the same order as in the Glyphs file. To combine the two examples above, if this is the glyph order:
and this is the feature code, trying to order the substitutions to achieve the desired result:
sub hyphen hyphen hyphen by hyphen_hyphen_hyphen;
sub greater hyphen by greater_hyphen;
sub T T by T_T;
sub A T by A_T;
sub L E by L_E;
sub T L by T_L;
… when we inspect the font with OTMaster, the actual order of substitutions is sorted by target glyph and glyph order:
The OpenType spec does not require such sorting, it even explicitly states:
The order in the Ligature offset array defines the preference for using the ligatures. For example, if the “ffl” ligature is preferable to the “ff” ligature, then the Ligature array would list the offset to the “ffl” Ligature table before the offset to the “ff” Ligature table.
I think the sorting is required be FEA spec, though:
A contiguous set of ligature rules does not need to be ordered in any particular way by the font editor; the implementation software must do the appropriate sorting. So:
sub f f by f_f;
sub f i by f_i;
sub f f i by f_f_i;
sub o f f i by o_f_f_i;
will produce an identical representation in the font as:
sub o f f i by o_f_f_i;
sub f f i by f_f_i;
sub f f by f_f;
sub f i by f_i;
Another case where FEA tries to outsmart the font designer.
There are places where sorting makes sense: in single subs, the order doesn’t matter but ordered GIDs are easier to store. But in this case, it influences the behavior, so it seems that sticking the order in the code makes more sense.
Yes, different lookup types are an issue, but that is not the one here since they are all ligature substitution. The real issue is that FEA spec want to be “helpful” but without giving a way to disable it.
I actually think that the automatic reordering is a good thing. Otherwise, rules like
sub f f by f_f;
sub f i by f_i;
sub f f i by f_f_i;
sub o f f i by o_f_f_i;
look sensible and descriptive, but the last two rules would never fire as they would be blocked by the first two rules. Automatic reordering makes every rule count.
But there are a million ways someone can write rules that will never be applied because another rule blocks them:
lookup foo {
sub a' b by c;
sub a' d by e;
} foo;
The second substitution will never be applied because the OpenType layout engine stops applying rules at the first match. So I don’t see why this particular case is so important to be handled automatically and without any sane way to override it.
Same here, I try to avoid implicit lookups as much as possible because they often mask subtle bugs in the feature code, and the rules for creating them is not always obvious.