Variables and algoritms with dliga sub?

I’d like to write a script that replaces the 26 letters of the alphabet with numbers, then calculates the summ of the numbers that are connected. For instance:

If I type “ABC” or “Abc” or “Abc” the font should display "6"
If I type “I am abc.” it should display “9 14 9.”

I was thinking about doing it with the dliga feature, first creating numbers up until 1000, calling them “eleven” “twelve” “thirteen” etc, and then just substitute letter combinations with

sub aa by two;
sub ab by three;
etc

and

one one by two
one two by three
etc

but the rules become exceedingly complex without variables. Is there a way to use variables and algorithms with the dliga sub feature?

You mean dlig sub a a by two; sub a b by three;

Note the space between the letters.

No. You will have to substitute all possible combinations. And your GSUB table could exceed 64k if you do, and the font will not compile in that case. So, the problem is not complexity, but the quantity of substitutions you have to make.

Okay, I’ll have to do it on code level then. Thank you for the quick reply!

Perhaps an OpenType feature is not the best solution for this. What is this for?

Birthday present for my aunt. She’s into http://en.wikipedia.org/wiki/Isopsephia. It’s easy to do it in Java Script, but I wanted to make a font for her that does in on the fly as she types in any environment.

Or do you happen to have an idea how it could be done on the font level?

  1. OT features do not work in every environment.
  2. If you know how to do it, perhaps JS is indeed the best option for you.
  3. As described, you have to really write every possible sum. You could put it in lookups. Each lookup can build on the previous ones:

lookup SINGLELETTER {
sub a by one;
sub b by two;

} SINGLELETTER;

lookup CONSECUTIVELETTERS {
sub one one by two;
sub one two by three;
sub one three by four;

} CONSECUTIVELETTERS;

… and so on. You could write a script that produces this code. But again, the danger is that it can become too large to compile if you really want to go to a thousand. So, a JavaScript is probably the best solution after all.

Which letter corresponds to which number, assuming you’re not using the Greek scheme like in your Wikipedia link? I might be interested to try.

I guess it is:
a = 1
b = 2
c = 3

x = 24
y = 25
z = 26

I don’t want to bother you with this but it has become kind of a puzzle and a challenge that I don’t want to just let go. I figured that:

  1. For two letters there are 26*26 = 676 basic single combinations, but the combinations result in 52 numbers that equalize each other, for instance, 26 can stand for AZ, BY CW etc.
  2. For three letters here are 52*26 combinations = 78 numbers
  3. For four letters there are 52*52 combinations = 112 numbers
  4. For eight letters there are 112*112 combinations = 224 numbers
  5. For sixteen letters, there are 224*224 combinations, 448 numbers.

With 8 letters, a big part of the English language would be covered. (the average length is 5). With 16 letters you’re at 99.99%. If a script could fit 8 or even 16 letters that would be simply awesome.

Now, in a simple routine, one could group the letters 4 times. For example:

c + o + m + b + i + n + a + t + i + o + n
3 +15+13 + 2+9 + 14+1 +20+9+15+14

—> sub a by one, b by two etc.

co+mb+in+at+io+n
(18+15)+(23+21)+(24+14)

----> lookup CONSECUTIVELETTERS sub eighteen fifteen by thirtythree etc.

comb+inat+ion
(33 + 44) + 38

----> lookup CONSECUTIVELETTERS sub thirtythree fourtyfour by seventyseven etc.

combinat ion
77 + 38

----> lookup CONSECUTIVELETTERS sub seventyseven thirtyeight by 115

combination
115

At this point my mathematical skills come to an end. I’m not sure how, but it seems to me that if we can loop the routines, with this method one could significantly reduce the amount of possibilities. Not sure how to do it exactly and if we stay within 64k though. It’s a puzzle, maybe insolvable.

With some empirical help (see f.i. http://www.umich.edu/~umich/fm-34-40-2/appa.pdf, http://www.umich.edu/~umich/fm-34-40-2/appb.pdf, http://www.umich.edu/~umich/fm-34-40-2/appc.pdf) the combinations could be further reduced.

It is trickier than I thought. You need to specify the max wordlength for which the feature should work. You can use this Python script for creating the feature (set the wordlength at the beginning):

https://gist.github.com/mekkablue/11179587

In the end, you get a comment with the names of the number glyphs you must create: copy them into your clipboard, and paste them into the Add Glyphs dialog (Cmd-Shift-G).

EDIT: And I get a subtable overflow with a word length of seven.

Awesome! Thank you so much. I get a subtable overflow with a word length of 5. Do you have an idea why I get the overflow earlier?

This might depend on other features in the font.

Weird. I made a completely new font. Bare of anything but numbers and the dlig definition. Still get a subtable overflow at five. Since we’re so close to solving the puzzle, am I doing something wrong? Isn’t it supposed to go into the dlig Features? Where did you put it? I put the compiled code in Features > dlig Is that correct?

I put it in ccmp.

Same effect:

“GSUB feature ‘ccmp’ causes overflow of offset to a subtable (0x13b08 4)”

As soon as I have over ±8000 lines, I get this error message. I wonder what you did differently there…

You may need to delete all the other substitution features.

Perhaps there is a different, smarter way with OT features. But I really think that JavaScript is the better solution for this.