Skip to content

Instantly share code, notes, and snippets.

@nikramakrishnan
Created August 25, 2019 11:49
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save nikramakrishnan/f88f3bae3cd2f0ba06d20ab3e0c74fb3 to your computer and use it in GitHub Desktop.
Save nikramakrishnan/f88f3bae3cd2f0ba06d20ab3e0c74fb3 to your computer and use it in GitHub Desktop.

GSoC 2019: Add Support for WOFF2 Fonts to FreeType

Project Details

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.

Project Description

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.

Final Work Product

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

Introduction

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.

Usage

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.

Goals Achieved

  • 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 and hmtx, 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).

Relevant discussions on mailing list

Thank You All

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment