Contextual alternates in FontLab

AgataWycichowska's picture


Building a handwritten typeface and need contextual alternates.

I've read Thomas Phinney's article ( and understand how it works, just have a question how to place the glyphs as sets?

Any help greatly appreciated!


Karl Stange's picture

Do you mean adding them to classes?

AgataWycichowska's picture

Thanks for your reply.
Yes – I've made opentype classes and changed the code to "class1" "class2" etc but this doesn't work. Can I rename the classes to "calt1" "calt2" etc instead?

Sorry if my question is stupid, this is really frying my brain!

Karl Stange's picture

Not a stupid question at all, I have only just figured out some of this stuff and it is not necessarily clear. I have found it helpful to map the classes in a separate document.

Yes, you will want to rename the classes to match what you put in the features, so 'calt1:' and 'calt2:' would work. You will also need to ensure that the number of characters in one match the other. There are no doubt more complex approaches but hopefully this will work when you compile the features.

I have found it very helpful to open a font that already has these features and see how the classes have been named and structured.

AgataWycichowska's picture

You're right – it's giving me the error message that it doesn't have the same number of elements as the replacement class. I guess making up additional characters to fill the spaces is the solution!

Karl Stange's picture

Having looked at a fairly complex font (EB Garamond) it looks like you only need to match the number of elements if you are doing a direct replace in the calt feature. If you are instead, for example, replacing everything in a specific class with a specified character then the classes only need contain the relevant characters being replaced.

AgataWycichowska's picture

Yes I thought I could separate the classes to make it work.
Or, I can write something like sub a.1 a.1 with a.2 etc. but that will be a lot of writing.

Thanks for showing me the example – looks very complex indeed.

Mark Simonson's picture

You can use any name you want for classes. They are only for your convenience and won't be present in the generated font.

When FontLab opens a font (.otf or .ttf), it decompiles the OT tables, and since there are no class names stored in the font, it gives them arbitrary names like calt1, calt2, etc. based on which features reference them.

You don't have to do the same. There's nothing to stop you from using more descriptive names for classes, like "normalQ" and "fancyQ" or whatever, and it will make your feature code much easier to understand.

Mark Simonson's picture

Note however that only certain characters may be used in class names (a-z, A-Z, 0-9, _, and period). Also, FontLab uses _ at the beginning of a class name to indicate a kerning class. Also, class names can't contain more than 30 characters.

Syndicate content Syndicate content