Typophile

node 17195

unknown

Hello everyone

I am new to Typophile and this is my first post. I am glad to be here. I have an OpenType features related problem. I want to make the following substitutions:

1 + 0 with a glyph called 1_0
1 + 0 + 0 with a glyph called 1_0_0 and
1 + 0 + 0 + 0 with a glyph called 1_0_0_0

(1 and 0 can be replaced by any digit - see code below)

I work in Fontlab Studio 5 and I at first I wrote the following code:

# glyph classes
@digitsnozero=[one two three four five six seven eight nine];
@digits=[zero one two three four five six seven eight nine];
@twodigits=[X X_X X_X_X X_L L L_X L_X_X L_X_X_X X_C];
@threedigits=[C C_C C_C_C C_C_C_C D D_C D_C_C D_C_C_C D_C_C_C_C];
@fourdigits=[M M_M M_M_M M_M_M_M];

feature liga {
# substitutions for two digits
sub @digitsnozero’ @digits by @twodigits;
# substitutions for three digits
sub @digitsnozero’ [@digits @twodigits @threedigits] @digits by @threedigits;
# substitutions for four digits
sub [one two three four]’ [@digits @twodigits @threedigits]
@digits @digits by @fourdigits;
} liga;

The problem is that when the first rule is activated the other two are ignored. As a result I only get the first substitution (1 + 0 -> 1_0)

I solved the problem by putting each rule in a different feature (the first in onum, the second in smcp and the third in liga - it works).

So now I have the following:

feature onum {
# substitutions for two digits
sub @digitsnozero’ @digits by @twodigits;
} onum;

feature smcp {
# substitutions for three digits
sub @digitsnozero’ [@digits @twodigits @threedigits] @digits by @threedigits;
} smcp;

feature liga {
# substitutions for four digits
sub [one two three four]’ [@digits @twodigits @threedigits] @digits @digits by @fourdigits;
} liga;

I read in the OpenType specification about the Chaining Context Substitution but I did not understand how am I supposed to do it.

Can anyone tell me if I can put all the three rules in one feature (e.g. in a liga feature)? Can I do anything with ‘lookup’?

George Triantafyllakos - backpacker.gr

unknown

I believe the solution is to reverse the order of your substitutions. Start with the longest (1_0_0_0) and work down.

unknown

Oh God! It worked …

I can’t believe it was so easy!! (I thought I tried it but I didn’t and I ‘ve been trying for the last 6 hours for a solution)

Mark, thank you very much!

George Triantafyllakos - backpacker.gr

unknown

Writing OT features is a bit of a logic puzzle sometimes. The easy way is not always obvious.

unknown

Big hint: With any many-to-one substitutions, the longest string should go first, which is why “ffi” and “ffl” are before “ff”, “fi”, and “fl”. (Which is pretty much the opposite of what happens when you’re typing. Which is why you should always write OT code while drunk.)

unknown

“Which is why you should always write OT code while drunk”

So that is your secret :-)

ChrisL

Captured from web.archive.org on 15 Jan 2006. view this capture