From: <ek...@di...> - 2020-12-31 05:53:51
|
I ended up making a small python script to generate all the substitutions Dec 27, 2020 10:01:40 PM Martin Hosken <mar...@si...>: > Dear ekaunt, > >> Suppose I had two classes >> >> uppercase = codepoint("ABCDEFGHIJKLMNOPQRSTUVWXYZ"); >> lowercase = codepoint("abcdefghijklmnopqrstuvwxyz"); >> >> and I wanted to convert every uppercase letter to a "S" if it's preceded by the corresponding lowercase letter (so "bB" becomes "bS", "fF" becomes "fS", but "cD" stays as "cD"), how would I do that? >> >> Doing `lowercase uppercase > @1 U+0053` doesn't work because then any combination of lowercase and uppercase becomes lowercase + S including "cD" becoming "cS" (and I only want the corresponding uppercase to match) >> >> Doing `uppercase > U+0053 / lowercase _;` doesn't work either for the same reason. >> >> I can't figure it out. Can anyone please help me out? > > The matching part of Graphite's rules is not dynamic. Thus it is based purely on static glyph strings. This means there is no way to use the index into one class when matching another. In other words, unless someone is more sneaky, you are going to have to flatten the whole thing out: > > ga > g_s / g_a _; > gb > g_s / g_b _; > gc > g_s / g_c _; > > etc. > > This is tedious but is no less efficient than what the compiler would end up producing, anyway, with any more sophisticated way of writing the rules. If you want to save a bit of effort you could do something like: > > #define myrule(x) g ## x > g_S / g_ ## x _ > > myrule(a); > myrule(b); > myrule(c); > > Or you can write code to generate a .gdl file that you then #include. > > HTH, > Yours, > Martin > |