Mobile app version of vmapp.org
Login or Join
Jessie844

: How to account for a space in OpenType ligature? Let's say that I want to replace the character's " ab" with a new character ("_AB"); is it possible to account for this space so that the

@Jessie844

Posted in: #Fonts #Opentype #Typefaces

Let's say that I want to replace the character's " ab" with a new character ("_AB"); is it possible to account for this space so that the word "cab" would not include this new character?

feature liga {
sub _ a b by _AB;
} liga;

10.03% popularity Vote Up Vote Down


Login to follow query

More posts by @Jessie844

3 Comments

Sorted by latest first Latest Oldest Best

 

@Berryessa866

In my experience, using space in any feature (including defining context) leads to problems with many typesetting programs, as many handle the spaces themselves instead of using your font’s space character. For example, for justified texts, your typesetting program will use sligthly larger spaces instead of your font’s ones.

One way to solve this is to use a contextual lookup, which instructs the following:


If ab is preceded by some glyph other than space, do nothing.
Otherwise, replace ab with AB.


Note that this will also replace ab with AB if it occurs at the beginning of a line, which may or may not be desired.

In OpenType, I suppose this looks like this (note that I never coded OpenType directly and did not test this):
@all_but_space = [A B C D E …];

feature clig {
ignore sub @all_but_space a' b';
sub a' b' by AB;
} clig;

10% popularity Vote Up Vote Down


 

@Berryessa866

Creating a ligature that actually includes a space isn't ideal since spaces are often handled independently of your font (think word-spacing). The liga feature is for ligatures that should be used in normal conditions too, so what you're doing is a bit of a workaround.

A better option is to use contextual ligatures (feature: clig). This means you can design a normal ab ligature without worrying about the space, but tell the font only to use it when proceeded by a space.

You write the feature exactly the same as a normal ligature, except you write the whole context string and mark the glyphs to be substituted with a single straight quote. In your case that would look like this:

feature clig {
sub space a' b' by AB;
} clig;


There is a good explination of contextual alternates here (they use calt as an example but the concept is the same): Glyphs App — Contextual Substitutions

EDIT: As pointed out by @Wrzlprmft the fact that spaces are handled independently can cause problems (in my limited testing it seems everything works fine in design programs, not so much in others). A better option may be to use the ignore keyword to create an exception (as explained by @Wrzlprmft ).

There are more techniques described here (including more complex methods using lookups to account for swashes etc): The OpenType Cookbook — Common Techniques

10% popularity Vote Up Vote Down


 

@Berumen635

Never mind, I just figured this out. For anyone else who is interested:

feature liga {
sub space a b by _AB;
} liga;

10% popularity Vote Up Vote Down


Back to top | Use Dark Theme