New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support WOFF2 #1503

Closed
davelab6 opened this Issue Jul 11, 2014 · 19 comments

Comments

Projects
None yet
@davelab6
Member

davelab6 commented Jul 11, 2014

Following #1501, add support for WOFF2 (related, #1457)

@davelab6 davelab6 added this to the 2014 Q4 milestone Jul 11, 2014

@davelab6 davelab6 added the feature label Jul 11, 2014

@adrientetar

This comment has been minimized.

Member

adrientetar commented Jul 11, 2014

Note that we should probably fix WOFF output first (#926) before implementing this.

@ctrlcctrlv

This comment has been minimized.

ctrlcctrlv commented Jul 13, 2015

Google wrote a C implementation of WOFF2 compression / decompression:

https://github.com/google/woff2

I don't think it would be that difficult to use it in FontForge. Currently I use it for post processing.

@davelab6

This comment has been minimized.

Member

davelab6 commented Feb 12, 2016

@fred-wang

This comment has been minimized.

Contributor

fred-wang commented Feb 12, 2016

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.

@fred-wang

This comment has been minimized.

Contributor

fred-wang commented Feb 12, 2016

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):

  1. It has an abstract SplineFont structure representing the font to generate.
  2. It first writes the WOFF header (with free space for table offsets).
  3. It calls _WriteTTFFont to generate the TrueType/OpenType font.
  4. It reads again the font generated in 3), compress the binary content of each of the table with gzip and writes this compressed table into the WOFF file (filling the final table offsets in the space left in the WOFF header)
  5. Finally, if the font has some WOFF metadata it is compressed with gzip and appended to the WOFF file.

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:

  1. Start with the SplineFont structure representing the font to generate
  2. Call _WriteTTFFont to generate the TrueType/OpenType
  3. Call ConvertTTFToWOFF2 from the WOFF2 library on the generated output to generate the WOFF2 font.

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.

@fred-wang

This comment has been minimized.

Contributor

fred-wang commented Mar 20, 2016

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:

fred-wang@0e4030e

BTW, I also opened google/woff2#49

@frank-trampe

This comment has been minimized.

Contributor

frank-trampe commented Oct 13, 2017

I hadn't been following this. Now that the woff2 library seems to be buildable and linkable, I'll give it a try next week.

@Meteor0id

This comment has been minimized.

Meteor0id commented Jan 5, 2018

So uhm, did it work?

@frank-trampe

This comment has been minimized.

Contributor

frank-trampe commented Jan 5, 2018

Sorry about that. I looked at it, but it wasn't trivial, and I got buried in other work. I won't be back on the case until February. This is on my list, though.

@Connum

This comment has been minimized.

Connum commented Apr 12, 2018

Hi there, any update on the WOFF2 front?

@jrchudy

This comment has been minimized.

jrchudy commented May 15, 2018

Also looking for an update for WOFF2 formatting in fontforge.

@Dmole

This comment has been minimized.

Dmole commented May 28, 2018

sudo apt install fontforge woff2 
woff2_decompress a.woff2
fontforge a.tts
woff2_compress a.tts

seems like it's the best workaround...

@Connum

This comment has been minimized.

Connum commented May 28, 2018

Not for Windows, unfortunately! ;) but interesting, maybe I'll fire up a VM for that.

@vushe

This comment has been minimized.

vushe commented Jun 15, 2018

@Dmole, what is the woff2 package? It's at least not available as such from my Ubuntu-based distro.

@Dmole

This comment has been minimized.

Dmole commented Jun 15, 2018

@Connum
There may be ways [1] [2] to build for windows, but yes using Linux is generally more advantageous.

@vushe
Be sure you enabled the "universe" repository;

> apt show woff2
Package: woff2
Version: 1.0.2-1
Priority: optional
Section: universe/utils
Origin: Ubuntu
Maintainer: Ubuntu Developers <ubuntu-devel-discuss@lists.ubuntu.com>
Original-Maintainer: Debian Fonts Task Force <pkg-fonts-devel@lists.alioth.debian.org>
Bugs: https://bugs.launchpad.net/ubuntu/+filebug
Installed-Size: 68.6 kB
Depends: libc6 (>= 2.14), libgcc1 (>= 1:3.0), libstdc++6 (>= 5.2), libwoff1 (>= 1.0.0)
Homepage: https://github.com/google/woff2
Download-Size: 12.5 kB
APT-Manual-Installed: yes
APT-Sources: http://ca.archive.ubuntu.com/ubuntu bionic/universe amd64 Packages
Description: utilities for converting fonts to WOFF 2.0
 woff2 is a library for converting fonts from the TTF format to the WOFF 2.0
 format. The library also allows decompression from WOFF 2.0 to TTF.
 .
 The WOFF 2.0 format uses the Brotli compression algorithm to compress fonts
 suitable for use in CSS @font-face rules. WOFF 2.0 is a W3C Candidate
 Recommendation.
 .
 This package contains the woff2_compress, woff2_decompress, and woff2_info
 utilities.

@vushe

This comment has been minimized.

vushe commented Jun 15, 2018

Thanks! Looks like my core Ubuntu is a little bit outdated or such.

@jtanx

This comment has been minimized.

Contributor

jtanx commented Jun 16, 2018

I'll take a shot at integrating this.

@Connum

This comment has been minimized.

Connum commented Jun 17, 2018

This is great news! Can't wait for this to be available in the Windows builds. And you did this in just two days? Truly amazing!

@jtanx jtanx closed this in #3307 Jun 20, 2018

@fred-wang

This comment has been minimized.

Contributor

fred-wang commented Jun 20, 2018

Great, thanks!

@Awea Awea referenced this issue Oct 9, 2018

Closed

woff2 with fontforge #5

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