Fonttools: Can I convert to woff with zopfli at TTFont?

Created on 22 Sep 2020  路  4Comments  路  Source: fonttools/fonttools

Related Topic

491

Describe
I'm trying to convert the font using TTFont.
It works fine.

from fontTools.ttLib import TTFont

font = TTFont( SOURCE_PATH )
font.flavor = "woff"
font.save( TARGET_PATH )

But..
There is no way to use zopfli in document ttFont Doc.
What can I do?

Most helpful comment

Chris is correct, although I dislike that approach of modifying a global variable. Pity I didn't get the chance to fix that yet. (PRs welcome)

All 4 comments

Here is the approach that is being used in ttx:

https://github.com/fonttools/fonttools/blob/0b413be45a92bb75e64362c1e38309f41d06cafd/Lib/fontTools/ttx.py#L278-L292

I think that if you set sfnt.USE_ZOPFLI = True before your font.save([PATH]) step, SFNTWriter should use zopfli rather than the zlib package?

https://github.com/fonttools/fonttools/blob/0b413be45a92bb75e64362c1e38309f41d06cafd/Lib/fontTools/ttLib/sfnt.py#L175-L189

Chris is correct, although I dislike that approach of modifying a global variable. Pity I didn't get the chance to fix that yet. (PRs welcome)

@chrissimpkins

Thanks for telling me a good way.
If I have enough time, I will consider writing a PR.

2066

Was this page helpful?
0 / 5 - 0 ratings