Additional discretion with positional alternates?

So!

I’ve been trying to write an OpenType feature that inserts positional alternates at the start and end of a line of text, to create lines like “Bing sings and Walt disnae”.

I used the code in this tutorial as a starting point, but as that activates at the start and end of each word, I attempted to amend it with an additional two lines on the end. The end result looking like:

lookup IsolForms {
	ignore sub @isolDef' @AnyLetter, @AnyLetter @isolDef';
	sub @isolDef' by @isolSub;
} IsolForms;

lookup InitForms {
	ignore sub @AnyLetter @initDef';
	sub @initDef' by @initSub;
} InitForms;

lookup FinaForms {
	ignore sub @finaDef' @AnyLetter;
	sub @finaDef' by @finaSub;
} FinaForms;

sub @finaSub' space by @isolSub;
sub space @initSub' by @isolSub;

This works just dandy in Glyphs, TextEdit and (as a woff) in Safari, but it rather runs aground in Adobe InDesign: the final alternate only activates if there’s a period or hard return following the glyph that has to be substituted.

This is the ‘simpler fix’: my original idea was to create a set of spaces and add them to the OpenType substitution classes — treating them like any other letter — but that ran aground in InDesign and Illustrator.

Does anyone have any ideas as to where this is going wrong?

Don’t use the space in OT feature code. Use an ignore statement instead.

I’m afraid my brain’s stuck in a rut today, Rainer, so I’ve not quite caught your drift: is there way to write the ignore sub so it responds to the space without naming it?

You do not use the space because the glyph is likely not in use by the layout engine. Therefore, do not employ separator glyphs in OT feature code. Think the other way around: Instead of ‘before/after an empty space, replace a by b’, you think ‘replace a by b, except when any non-separator glyph precedes/follows’. And that is what the ignore statement is about.

I do not understand what you are trying to do, though. Why would you want to change initial or final shapes into isolated shapes?

Ah, that’s a good question and one that’s made me realise that I’ve really not been as clear as I should have been: I’ve been staring at this problem too long. It’s a Latin custom font, and the client has quirky initial and final letters, different designs, that they’d like to see at each end of a headline. I was hoping to get the type to be able to run substitutions to produce both [initial] [default] [final] and [initial] [default] [space] [default] [final] — I thought I had and had convinced myself that I was enormously clever for tweaking your positional alternates code until I tested it in InDesign.

As it’s a quirky brand, I can’t rely on initial replacements being one case and the final replacements being another, and the need to account for multi-word lines is what keeps bringing me back to the space. As I can’t control for spaces, I think adding something I can reliably account for would do the trick:

asterisk A sub A.isol
A asterisk sub A.final

Much less elegant (and not as automatic as I’d like), but more reliable. That is, so long as asterisks aren’t universal grief engines!

In a controlled environment like this, the asterisk is a good hack. Pick something that they never need to show up and that they can type easily. Maybe underscore?

Also: it must be a character that cannot be changed by autocorrect, so hyphens and periods are a bad idea. But asterisks should be fine.

I’m waiting to see what the client says, but in the meantime cheers to you both for your help and patience on this — I’ll get you a beer or two if you’re at TypoLabs?

2 Likes