Determine number of alternative layers in variable font

Hello,

I have a variable font to demonstrate a type historical project with a custom history axis from 0-1000. For some glyphs i have as many as 90 alternative layers.


This applies to 50 glyphs but the number of alternative layers varies depending on the historical evidence for each character.

As these alternates are hidden inside the layers panel i can’t count them in the glyphs main view.

I can see all of them neatly in the adobe apps glyphs panel

theoretically i could manually count them there.

I was wondering if there is a smarter, automatised way of counting my alternative layer glyphs?

Best,
Basti

So what exactly is it you want to count? The maximum number of alternate layers in any glyph? The combined number of alternate layers in all glyphs? A list overview of the number of layers in each glyph? The number of (or a list overview of) glyphs that have alternate layers?

i would like to count all individual alternate layers throughout the font (as displayed in the screenshot of the adobe apps glyphs panel)

But you don’t want to include glyphs in non-alternate layers, only those in alternate layers?

indeed, those are redundant

count_of_alternates = 0
for g in Font.glyphs:
    for l in g.layers:
        if not l.isMasterLayer and l.isSpecialLayer:
            if l.attributes["axisRules"]:
                count_of_alternates += 1
print(count_of_alternates)

This should work, didn’t test.

1 Like

thank you, will test later!

of, if you like it per glyph:

for g in Font.glyphs:
    count_of_alternates = 0
    for l in g.layers:
        if not l.isMasterLayer and l.isSpecialLayer:
            if l.attributes["axisRules"]:
                count_of_alternates += 1
    if count_of_alternates > 0:
        print(g.name, count_of_alternates)

Out of curiosity, is there a reason to check isMasterLayer, am I missing a case when a special layer can be a master layer?

image

1 Like

You can add axis rules to master layers. I do that all the time:

1 Like