No modern font is complete without them, and Glyphs helps you build them. In this first installment about OpenType features, we’ll explore the very basics and what Glyphs can automate for you.
What features do
OpenType features can do two things: substitute glyphs and reposition glyphs. In this tutorial, we’ll focus on substitution. Please note that I said glyphs, not characters. What is the difference, you ask? In short, characters are what you type, glyphs are what you see. Type designers are type designers because they create new glyphs when they draw letters, they rarely create characters by adding new keys to keyboards and submitting new encodings to the Unicode consortium. And sure enough, OpenType features cannot magically change the text the user had entered, i.e., the characters. But what features can do, is change how that text is displayed, i.e., choose from the glyphs you have in your font.
Ligatures are a classic example. They replace a sequence of two or more glyphs with one glyph. Font geeks call this a ‘many-to-one’ or ‘ligature substitution’. When the user types the characters, glyphs with the corresponding Unicode values will appear on their screen. If those glyphs match a certain predefined sequence, the ligature feature will swap them for the ligature glyph.
Adding a ligature
Of course, you will only add a ligature if that single ligature glyph actually looks or works better than the individual glyphs. Don’t make your font worse with a bad or illegible ligature. But for the purpose of this tutorial, let’s assume that the sequence of two f’s followed by a k could use a better representation with a ligature in our font.
There are many ways to add glyphs to your font, but we can create a ligature glyph quickly with Glyph > Add Glyphs… (Cmd-Shift-G). In the dialog that appears, you type the glyph name for our ligature,
Yes, the naming convention for ligatures is the individual glyph names connected with underscores. More about that later. But once you have that, press the OK button, and the new ligature glyph will appear in your font, pre-filled with components of the individual glyphs
Decompose them with Glyph > Decompose Components (Ctrl-Cmd-D) and fiddle around with the paths until you get a nice ligated version of those three letters. You will notice that the ligature inherits the kerning groups of the outermost letters, and, even better, metrics keys. That means that you can sync the sidebearings with the original first and last letters with Glyph > Update Metrics (Ctrl-Cmd-M).
Hey, what do you want, it’s my first font, and I am proud of it.
In any event, now we have a ligature glyph in our font. But we don’t have a ligature key on our keyboard, so we cannot type it. In other words, there is no ‘ffk’ character. So, in order to access our beautiful ligature glyph, the user needs to activate the proper OpenType feature. Which also means that we need to add that OpenType feature to our font before we give it to our users.
Adding a feature
Choose File > Font Info (Cmd-I) and switch to the Features tab. It should look like this:
On the left, you get an overview of prefixes, features and classes. On the right, you get two text fields. The top text field is for your feature code, the bottom text field is for notes or saving chunks of code you temporarily deactivate and perhaps want to reuse later. Above the top text field you find two checkboxes, one to automatically generate features, the other one to disable the feature.
So, all we need now is a feature. Click the plus button next to the word ‘FEATURES’, and we pick one of the ligature features from the searchable list menu that appears. Hint hint, start typing ‘li…’:
liga, the feature tag for ‘Standard Ligatures’. According to Microsoft, this feature ‘replaces a sequence of glyphs with a single glyph which is preferred for typographic purposes.’ Sounds good.
If you have done everything right, your Font Info window will look like this now:
When you build a feature, you actually put together a set of rules. Rules define what gets substituted with what. Here is what such a rule looks like:
sub f f k by f_f_k;
Let’s go through that, bit by bit:
- First, we have the keyword sub, which defines the kind of rule we are dealing with. As mentioned above, this can either be a substitution or a positioning rule. And
subclearly denotes a substitution rule.
- Secondly, since we have a substitution, we need the sequence of glyphs that are to be replaced. In this case, we have three glyphs:
f, followed by another
f, followed by
k. Please note that these are the actual glyph names, so ä would be spelled out as
adieresis, ñ as
- If we didn’t put the keyword by after the sequence, it wouldn’t be clear what is to be replaced by what. Imagine our code line was
sub f f k f_f_k, then it might as well be that
f fwas to be replaced by the sequence
by, we tell the font what comes instead. Remember the naming convention for ligatures: the names of the individual letters connected by underscores. In our case, we have the three letters f, f and k molded into one, so it’s called
- And now, very super-important: each rule takes a semicolon at its end. Easy, you may say, but this actually is the number one source of errors. So in case your features don’t work, chances are you forgot the semicolon.
When we type our rule into our
liga feature, Glyphs will offer us autocompletion:
This can be a life saver if you end up with very long glyph names in your font. You will also see that Glyphs tries to be helpful with syntax coloring for making names and keywords stand out. And if you are not sure whether that name is really referencing the glyph you intended here, you can Opt-click the glyph name and take a quick peek:
Of course, you can put several rules after each other, like this:
sub f k by f_k; sub f h by f_h; sub f i by fi; sub f l by fl; sub f f k by f_f_k; sub f f h by f_f_h; sub f f i by f_f_i; sub f f l by f_f_l;
You might have noticed that the names fi and fl don’t adhere to the naming convention. That’s because those two glyph names existed before the naming convention was there, and now it’s too late to fix it. Historically grown, never mind. Also, you can write all rules into a single line, if you prefer to do so. As long as you don’t forget about the semicolons, everything will work out fine.
Testing and fixing code
Want to see if you did everything right? Hit the Compile button at the bottom of the window, and Glyphs will make your code available in one of the Edit tabs of the main window. There, you can test your feature by choosing it from the Features pop-up menu at the bottom left:
… and start typing with your Text tool (T):
Good, the ligature works!
Of course, you should only put rules into your feature if you actually have all the referenced glyphs in your font. Because if you don’t, Glyphs will complain loudly but rightfully:
If this happens, the warning symbols will guide you to what needs to be fixed. Clicking on the warning will give you a more detailed description, so you have a better idea of what is going on. Occasionally, the warning shows a tool symbol. In those cases, when you click on it, you are also offered a suggested fix for the issue:
If you click on the Fix button in this case, Glyphs will insert the missing semicolon for you. Other fixes include corrections for mistyped keywords or suggestions for glyph names. If there is too much to fix, and errors are preventing you from exporting the font, but you need a quick test export, you can disable a broken feature with the active checkbox at the top.
In case you are unsure what the OpenType feature in question is intended for, click the Spec button in the top right, and you are taken to the official definition of the feature on the Microsoft page. You do need a working internet connection for this, of course.
And now, to your great disappointment, I have to admit that we did all this for nothing. Why? Because, if you stick to the naming convention mentioned before, Glyphs can create ligature features automatically. You can trigger automatic generation with the circled arrow button.
It will throw most ligature rules into
dlig (discretionary ligatures), but you can force them into
liga if you add a
.liga suffix to the names of the ligature glyphs, e.g.,
f_f_k.liga. But Glyphs can automate more than just
dlig, and you may end up with a whole bunch of automated features once you click the Update button:
You’ll find a list of recognized glyph names and name suffixes in the appendix of the Glyphs Handbook.
When you automated your code, you probably noticed that Glyphs prefixed your substitution rules with this line:
lookupflag IgnoreMarks RightToLeft;
According to the spec, lookup flags ‘indicate to a text-processing client certain processing options to use when substituting or positioning glyphs.’ Whatever that means.
Well, in short, a lookup flag will tell the feature to pay attention to certain conditions when it goes looking for that sequence of glyphs to replace. When you have lookup flag
IgnoreMarks active, glyphs will skip over any combining accents in your sequence of glyphs. So if you have this:
lookupflag IgnoreMarks; sub f f k by f_f_k.liga;
… then the ligature will even work when a user types f-acutecomb-f-k. Because if we ignore combining marks in that sequence, which is exactly what the lookup flag stipulates, we get our magic sequence of glyphs again: f-f-k.
And lookup flag
RightToLeft means that the subsequent rules only apply to RTL writing direction, which is what you want for Arabic and Hebrew text, of course.
There are more lookup flags available, but these two strike me as the most frequent and important ones, so I will stop here. Just one more little trick. If you are like me, and cannot remember the exact code for lookup flags, click on the Snippets button in the bottom right corner of the Features window:
And it will insert a line declaring all possible lookup flags in your feature code. Correctly spelled, of course. Then, simply delete the ones you do not need, and that’s it. Have a nice day.
In the realm of simple substitutions, there is not only many-to-one. There are other types as well. The OpenType specification knows them as ‘GSUB lookup types’. GSUB stands for glyph substitution, and a lookup is a collection of rules of the same kind. Ligature substitutions (many-to-one) are GSUB lookup type 4.
If you replace one glyph with one other glyph (one-to-one), we have a ‘single substitution’, also known as GSUB lookup type 1. An example for this is this rule that typically appears in the
frac (Fractions) feature:
sub slash by fraction;
If you replace one glyph with multiple glyphs (one-to-many), the spec calls them a ‘multiple substitution’ or GSUB lookup type 2. Multiple substitutions are frequent in South and Southeast Asian scripts. In Latin, they may be used for fixing legacy ligature encodings in
ccmp (Glyph Composition and Decomposition). Here are some famous examples:
sub fi by f i; sub fl by f l; sub napostrophe by apostrophemod n; sub Dz by D z; sub Dzcaron by D zcaron; sub dz by d z; sub dzcaron by d zcaron; sub DZ by D Z; sub DZcaron by D Zcaron;
And then there is the ‘alternate substitution’ or GSUB lookup type 3. It is a special case of a one-to-one substitution, but can pick from a range of glyphs. Randomly? No, not necessarily, that depends on the implementation in the text processing app. A good example is the
ornm (Ornaments) feature that gives the user access to a range of ornamental glyphs as a substitution for the
sub bullet from [a.ornm b.ornm c.ornm d.ornm e.ornm];
Note that instead of
by, the rule uses
from. And after the
from keyword, the glyph names are between square brackets
[ ]. Glyph names listed inside brackets are called a ‘class’ of glyphs. We need classes every time we need to refer to a whole bunch of glyphs in one spot. You can read classes as ‘any of these glyphs here’. More about classes in the upcoming feature tutorials.
Or, if that is too geeky for you, the wonderful Tal Leming maintains the OpenType Cookbook. Simon Cozens wrote a concise Introduction to OpenType Programming. There is also a good Introduction to OpenType Features by Martin Wenzel and Christoph Köberlin.
Then, a good question is how to access and use OT features in fonts, because the users of your font will ask you about it. Google Fonts has a good rundown of Implementing OpenType features on the web, and many websites have help pages on how to select and apply features, such as Using Fonts with Special Features by Creative Market, explaining usage in Adobe apps and Microsoft Word; or FontSpring’s How to Access Opentype Features in InDesign, in Illustrator, or in Photoshop.
Update 2015-07-02: updated for Glyphs 2.
Update 2018-07-24: updated links and added links in Resources.
Update 2019-03-28: updated link for Adobe's specification.
Update 2019-04-09: updated link for the Glyphs manual.
Update 2022-07-21: updated title, related articles, minor formatting.
Update 2022-07-23: updated links, added Adding a ligature, Testing and fixing code, Lookup flags, More substitutions, renamed headlines, partial rewrite and updates for Glyphs 3.