Project Proposal: https://docs.google.com/document/d/1JETYduhFgrmhRgUMFo4HjwmUp0IMyh3UZsQbmwAmjjI/edit?usp=sharing
GSoC Project Link: https://summerofcode.withgoogle.com/projects/#5914661667471360
Contributed Repositories: freetype2
Languages: C
, Unix build tools
.
Over the summer I have worked to integrate support for the WOFF2 format into FreeType so that these fonts can be recognized, decompressed, and loaded as any other SFNT font. This included study and comparison of how SFNT fonts are wrapped into WOFF 1.0 and WOFF 2.0 files, exploration of existing libraries for WOFF 2.0 and Brotli compression, and finally, writing code to allow FreeType to handle WOFF 2.0 fonts.
Seamless support for the WOFF File Format 2.0 into FreeType. FreeType can now recognize, decompress and open WOFF2 fonts as any other SFNT font.
Working branch: http://git.savannah.gnu.org/cgit/freetype/freetype2.git/?h=GSoC-2019-nikhil
Full diff: http://git.savannah.gnu.org/cgit/freetype/freetype2.git/diff/?id=f67786d&id2=47ca5cb
FreeType includes support for WOFF 1.0 since version 2.5.1. The WOFF2 format offers a 30% average compression gain over the original WOFF, making it faster to serve over the web, while allowing fast decompression even on mobile devices. More information on web fonts and their adoption can be found here.
A valid WOFF2 font file can be loaded as any other font file. The FreeType Tutorial provides examples on how a font face can be loaded from a file.
Note: FreeType must be built from the GSoC-2019-nikhil branch to support WOFF2 till this code is merged to master.
- Study existing SFNT sources and create a roadmap (Initial obersvations).
- Move the WOFF 1.0 sources and header definitions to separate files (commit).
- Study the WOFF2 W3C Recommendation in detail (WOFF2 Recommendation).
- Create
sfwoff2.c
, read and parse the WOFF2 header (commit). - Read WOFF2 table and collection directory (commit, relevant discussion).
- Add Brotli support to build system and decompress the compressed WOFF2 stream (commit 1, commit 2).
- In case input font is a TTC, optimize reconstruction using the
face_index
paramater (commit). - Reconstruct transformed
glyf
table (steps, commit). - Reconstruct transformed
loca
andhmtx
, swap streams and load SFNT (commit). - Improve memory handling to avoid too many reallocations (commit).
- Support hmtx reconstruction when glyf is untransformed (commit, relevant issue).
- Discussion on FreeType stream macros.
- Collection directory reading - Update.
- Discussion on setting
face->num_faces
for a WOFF2 TTC. - Minor Formatting Updates.
I am really grateful to the amazing FreeType community that helped me immensely, and taught me so much over the past few months. The constructive discussions, suggestions and criticism helped expand my knowledge of font rendering, improve my programming skills and make my summer super-interesting and productive.
Thank you, Werner, Alexei and all of the community for taking the time to review and test code and for all the valuable feedback.
Hope to see you all in the next commit :-)
Cheers,
Nikhil