Hello, this is my first post on TypeDrawers.
I'm interested in cycling through positional alternates, and am not quite sure where to begin except by posting here. Maybe you have an idea how to achieve it?
Most guidance on Glyph Cycles only relate to strings of a successively repeated character ("aaaa"), rather than the sporadic appearance of a character.
Since I can't as yet code it in OpenType, the text below is of course just to illustrate my goal:
(t.init#1)to (t.init#2)thine(e.fina#1) own se(e.medi#1)lf be(e.fina#2) (t.init#1)true(e.fina#1)
Thank you for reading my question
Comments
You need to combine two techniques. I would set up two lookups in your calt feature. (If you don't know how to create separate lookups or why they're useful, please see my Thinking In OpenType tutorial.) The first lookup will set up the init/medi/fina glyphs that you want to vary, just to get them into the first variant glyph (t.init1, e.fina1, etc. in your example). The OpenType Cookbook should have a recipe which helps you do that. I'm going to assume you can do that already.
The second lookup is the interesting one - this will be the one which cycles these glyphs through different variants. So much about programming is finding the right way to frame the question. If the question is "Can I keep track of the last variant of a glyph and change the next variant based on it?" then it seems really tough, as OpenType doesn't really have any way to save state. If you frame the question as "Can I substitute a glyph for e.g. t.init3 if it's preceded at some point in the recent past by a t.init2?" then the answer begins to write itself. You may find it easiest to understand the code below by starting reading from the middle set of rules - that'll be clearer what you're substituting for what.
It will get very tedious to enumerate all the cases, but I think it should work.
Oh, bother. Look, I got the tick marks right, Adobe got them wrong.
The rand feature is only implemented in Harfbuzz, so this will only work in applications using Harfbuzz - it won't work in Microsoft Word, Adobe Illustrator, TextEdit, etc. (Related thread.)