Python Q - replacing last glyph in each word

HaleyFiege's picture

Hey, I was wondering if anyone could help me with a python script. I'm making a script font, and would like to substitute out the final glyph in each word (with one that has a finishing flourish).

I remember seeing something like that here before, but I can't find it now :(

Mark Simonson's picture

Python? Do you mean coding an OpenType feature?

If so, it goes like this:

Make a few groups:

@any_letter = [ a list of all letters from your font that could be part of a word ] ;

@not_final = [ a list of the non-final glyph forms ] ;

@final = [ a list of the final glyph forms (same order, same number of glyphs) ] ;

Here is the feature code, which should be put in the calt feature:

feature calt {

lookup fix_finals {
ignore sub @not_final' @any_letter ;
sub @not_final' by @final ;
} fix_finals ;

} calt ;

The "ignore" part means skip the rest if another letter follows. If no letter follows, then the substitution happens.

Mark Simonson's picture

By the way, the groups can be made either in the OT editor in FontLab, either just before the feature code, or in the lower pane of the OT editor panel. Or, you can use the Classes panel, select "New OpenType Class" from the pop-up, and use this syntax:

group_name: list of glyphs

I prefer putting it all in the OT editor. Seems easier to manage.

HaleyFiege's picture

Thanks Mark :)

HaleyFiege's picture

So it's working when I test in the fontlab opentype tester window, but not when I use it in Indesign or Illustrator. Is there a feature in opentype I have to turn on for this to work? (all my other scripts are working though)

Or did I do something wrong :(

Mark Simonson's picture

Is this the only feature in the font? There is a bug in InDesign where it ignores a feature if it is the only one.

If that's not the case, it could be that you have contextual alternates unchecked in InDesign.

It's also possible that you are not including OT features when you generate the font. There is a checkbox for this in the preferences.

Syndicate content Syndicate content