Substitute the first letter of a word using opentype?

matthew_desmond's picture

I'm trying to figure out if there's a way to substitute the first letter of a word for an alternate version. I don't want the rest of the s's in the word to swap also like how standard swashes would work. I'd like it to be automatic so you don't have to hit the alternates every time.

The only way I can think to do it is to substitute the s using the space before the word as a ligature. But that doesn't help when there is other punctuation going on.

Any ideas?

emenninga's picture

This isn't a great option because it only works with InDesign CS3, but we started supporting the OpenType features 'init', 'fina', 'isol', and 'medi' which can be dynamically applied to characters. These correspond with "initial letter", "final letter", "isolated letter" and "medial letter". It is only semi-smart, but can handle punctuation around words for example.
A more universal approach involves some complex contextual processing which is why Thomas Phinney suggested adding support for the positional forms feature.

dezcom's picture

Are not positional forms required for proper Arabic anyway?

ChrisL

matthew_desmond's picture

Yeah, would prefer something that works in CS2 apps (AI, InDesign).

I may just have to resort to the manual swashes and the client will just have to use them at their leisure.

Matt

Mark Simonson's picture

Create a class that contains all glyphs that are letters (or anything else you consider to be part of a word). Then, set up a contextual substitution in which if a glyph is not preceded by a member of that class, use the alternate.

Here's one way to do it. In the following code, the classes are defined thus:

@letter = any glyphs you consider part of a word;
@normal_letter = any glyphs that have a different form for the beginning of a word
@alternate_letter = the alternate versions of the glyphs in @normal_letter

The contextual substitution (to be placed in the calt feature):


   lookup beginnings {
      ignore sub @letter @normal_letter' ;
      sub @normal_letter' by @alternate_letter;
   } beginnings;

matthew_desmond's picture

Ahh, must be smarter than fontlab.

This looks like it should work, but I'm getting a weird "invalid token (text was "@")" error when I try to compile.

Mark Simonson's picture

If you copied the text from here and pasted it in, you might get some trouble with the non-breaking spaces I used for the indents at the beginning of the lines. If not, then make sure you've got all your ticks and semicolons accounted for...

emenninga's picture

To belatedly reply to Chris: yes, positional forms are required for some scripts (including Arabic) and are applied automatically by InDesign ME (all versions, not just CS3) but the new thing added in CS3 was adding positional forms as an option for non-ME InDesign.

dezcom's picture

Oh, I see. Prior to that, an ME version was required. Thanks!

ChrisL

matthew_desmond's picture

OK, got rid of the error. Now I got this script to work with one letter substitution... What If I have dupes for all 26 letters? Do I need to make classes for each letter?

matthew_desmond's picture

Never mind. I'm dim sometimes. It was replacing the letters with the blank spots I had for all of the glyphs. D'oh, it's beer time.

Thanks a ton Mark!!!

Goran Soderstrom's picture

I was just looking for that kind of thing, thanks for a quick way of describing it.

matthew_desmond's picture

Paging Mark Simonson!

I understand how this method works now.
Is there a way to use this same technique for replacing the end letter of a word?

I am just no good at making the code do what I want it to do...

matthew_desmond's picture

After reading that other thread, I got it. Thanks Paul.

paul d hunt's picture

sorry i didn't link to it earlier. :^p

Syndicate content Syndicate content