Join GitHub today
GitHub is home to over 28 million developers working together to host and review code, manage projects, and build software together.Sign up
Support WOFF2 #1503
I thought a bit on that while working on #926 and my conclusion was that WOFF2 is slightly more complex than just gzip compression of tables... So it makes sense to just generate the OpenType/TrueType file with fontforge's functions and then call Google's woff2 library on it (and the other way around for opening font). Also WOFF2 may invalidate font checksum and then remove DSIG table, so maybe we should warn the user about that...
The main "difficulty" is that libraries https://github.com/google/woff2 and https://github.com/google/brotli/ are not really available as standard released packages so we'll have to include the code into fontforge's build system in some way.
I'm not suggesting to use an external program, just the ConvertTTFToWOFF2/ConvertWOFF2ToTTF functions from the WOFF2 library.
Here was my rationale:
_WriteWOFFFont essentially works as follows (https://github.com/fontforge/fontforge/blob/master/fontforge/woff.c#L382):
For WOFF2, brotli is used instead of gzip. However, there are several differences. First, the compression is applied to the whole set of tables so the logic in 4) (to compress each of the table individually and to calculate the final offsets) does not apply. Second, there are some "high-level" optimizations (e.g. those on glyf and loca tables) that are better done using the abstract structure provided by SplineFont than the binary data obtained in 3). Finally, WOFF2 is also able to handle TrueType Collection and I'm not really sure how we would handle that here. So my conclusion was that it is not really relevant to reuse our existing code for WOFF compression/decompression.
My naive proposal for WOFF2 is just:
And of course the same reasoning applies for opening WOFF2 file. So I guess that would be quite easy. As I said the main difficulty would be to properly integrate the woff2 library into the fontforge build system. Maybe that's why Dave suggested an alternative via Python.
So I tried a quick hack to clone & build the woff2 library during the fontforge build. However, I realize an additional difficulty: the woff2 headers are in C++ so they can not be used directly by fontforge's C source. Anyway for those interested and to illustrate the proposal of my previous comments, here is my first attempt:
BTW, I also opened google/woff2#49
referenced this issue
Oct 8, 2016