Variable Font Export using the Python API

Hello,

How do I export variable fonts in ttf, woff and woff2 formats?

I tried:

Case 1

if i.type == INSTANCETYPEVARIABLE:
    i.generate(Format=TTF, Containers=[PLAIN, WOFF, WOFF2], FontPath='path/to/file' )

and also:
Case 2

f.export(Format=VARIABLE, Containers=[PLAIN, WOFF, WOFF2], FontPath='path/to/file')

In Case 1, I am generating fonts using the instance.generate() method. In this case, I can generate all fonts that I requested but they don’t get recognized in Adobe products (no option to adjust variable axes).

In Case 2, I am generating fonts using the undocumented font.export() method. In this case, I can only generate ttf variable font which works beautifully. Even though I specified WOFF and WOFF2 containers, I only get ttf format. These work fine through the export dialog box, but not programmatically through Python API.

Any ideas?

I found a way. The bug seems to ignore Containers=[] argument. I went back to the export dialog box in the GUI and noticed that only ttf was checked. I checked all of them:

And now it exports all 3 containers through the Python API. I presume, the GUI dialog box is changing some internal state and that’s what’s being used to export.

Not super important but would love to see support for:

  • Use container=[] argument in the python f.export() function.
  • OTF container for variable fonts would be awesome as well.

I fixed the instance.generate() for variable instances.

You mean the outline format, not the container.

@GeorgSeifert Thanks. Is this fix in the beta releases?

> You mean the outline format, not the container.

Pardon my ignorance. That’s what I meant. Are there plans to export OTF variable fonts?

no. I fixed it just now :wink:

Implementing variable OTF is on the list.

And the Font.export function needs some work. But instance.generate is much better.

Excellent and thank you. Just to confirm, I will be able to use with your new fix:

i.generate(Format=VARIABLE, Containers=[PLAIN, WOFF, WOFF2], Fontpath='path/to/file')

Correct?

Yes.

1 Like

It seems to not work on 3.1.2 (3151) and on also on last cutting edge 3.2 (3181)