Git Product home page Git Product logo

woff2's Introduction

This is a README for the font compression reference code. There are several compression related modules in this repository.

brotli/ contains reference code for the Brotli byte-level compression algorithm. Note that it is licensed under the MIT license.

src/ contains the C++ code for compressing and decompressing fonts.

Build & Run

This document documents how to run the compression reference code. At this writing, the code, while it is intended to produce a bytestream that can be reconstructed into a working font, the reference decompression code is not done, and the exact format of that bytestream is subject to change.

The build process depends on the g++ compiler.

Build

On a standard Unix-style environment:

git clone --recursive https://github.com/google/woff2.git
cd woff2
make clean all

Alternatively, if Brotli is already installed on your system you can use CMake to build executables and libraries:

git clone https://github.com/google/woff2.git
cd woff2
mkdir out
cd out
cmake ..
make
make install

By default, shared libraries are built. To use static linkage, do:

cd woff2
mkdir out-static
cmake -DBUILD_SHARED_LIBS=OFF ..
make
make install

Run

Ensure the binaries from the build process are in your $PATH, then:

woff2_compress myfont.ttf
woff2_decompress myfont.woff2

References

http://www.w3.org/TR/WOFF2/ http://www.w3.org/Submission/MTX/

Also please refer to documents (currently Google Docs):

WOFF Ultra Condensed file format: proposals and discussion of wire format issues (PDF is in docs/ directory)

WIFF Ultra Condensed: more discussion of results and compression techniques. This tool was used to prepare the data in that document.

woff2's People

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

woff2's Issues

Tag a release?

Hello,
It would be great to have a tagged release so we could include woff2 in the Homebrew core.
Thanks!

Compile Error on CentOS

I am stuck at compiling this on CentOS 6 + gcc 4.8.2.

make clean all
...
...
g++ -fno-omit-frame-pointer -no-canonical-prefixes -fno-tree-vrp -std=c++11 -I./brotli/dec/ -I./brotli/enc/ -I./src -c -o src/woff2_dec.o src/woff2_dec.cc
src/woff2_dec.cc: In function ‘bool woff2::ConvertWOFF2ToTTF(uint8_t_, size_t, const uint8_t_, size_t)’:
src/woff2_dec.cc:939:49: error: expected ‘)’ before ‘PRIu64’
fprintf(stderr, "offset fail; src_offset %" PRIu64 " length %lu "
                                                             ^
make: *** [src/woff2_dec.o] Error 1

Glyf table point flags bit 6 gets lost

Compressing a TTF to WOFF2 ignores bit 6 of any glyf table point flags. This bit is marked as reserved in the OT spec, but Apple uses it to determine the presence of overlapping contours in a glyph. See fonttools/fonttools#730 and https://developer.apple.com/fonts/TrueType-Reference-Manual/RM06/Chap6AATIntro.html:

For simple glyphs, you should set bit 6 of the first Outline Flag byte to 1 if the unhinted glyph outline has overlapping contours or if variation controls or hinting controls can ever cause any of the contours to overlap. Otherwise this bit should be set to 0.

Should the woff2_compress code be patched so the flag stays intact? I don’t have the experience in C to do it myself.

Please upgrade the brotli submodule

Currently https://github.com/google/brotli/tree/510131d1db47f91602f45b9a8d7b1ee54d12a629 does not have public headers in a separate directory.

In the latest version, they are moved into a include/brotli. This means that the WOFF2 makefile could have rule '-I./brotli/include' so that the WOFF2 files could just include the headers using the syntax <brotli/*.h>. Then that would make possible to compile woff2 using pre-installed brotli library and headers rather than a git submodule.

woff2_compress zeroes the glyf OVERLAP_SIMPLE flag

In tests, woff2_compress zeroes the glyf OVERLAP_SIMPLE flag.

This bug refers to the Apple OVERLAP_SIMPLE flag, which is set by default by fontTools varLib.mutator since #1518.

Before woff2_compress:

<TTGlyph name="Psi" xMin="40" yMin="0" xMax="835" yMax="717">
  <contour>
    <pt x="311" y="0" on="1" overlap="1"/>
    <pt x="564" y="0" on="1"/>
    <pt x="564" y="50" on="1"/>
    …

After woff2_compress:

<TTGlyph name="Psi" xMin="40" yMin="0" xMax="835" yMax="717">
  <contour>
    <pt x="311" y="0" on="1"/>
    <pt x="564" y="0" on="1"/>
    <pt x="564" y="50" on="1"/>
    …

Cannot build individual executables with Makefile

I have a script which requires only the woff2_compress and woff_decompress executables to be built, so I would like to build just those targets with make. However, the Makefile seems to bundle all of the dependencies together, and I end up with an error like this:

$ make woff2_compress woff2_decompress 
g++ -fno-omit-frame-pointer -no-canonical-prefixes -DFONT_COMPRESSION_BIN -D __STDC_FORMAT_MACROS -fno-tree-vrp -std=c++11 -I./brotli/c/include/ -I./src -I./include  -c -o src/woff2_compress.o src/woff2_compress.cc
...more stuff...
make[1]: Leaving directory '/home/bdusell/Programming/github/webfont-generator/vendor/woff2/brotli'
g++   src/font.o  src/glyph.o  src/normalize.o  src/table_tags.o  src/transform.o  src/woff2_dec.o  src/woff2_enc.o  src/woff2_common.o  src/woff2_out.o  src/variable_length.o brotli/bin/obj/c/common/*.o brotli/bin/obj/c/enc/*.o brotli/bin/obj/c/dec/*.o src/woff2_compress.o -o woff2_compress
g++: error: src/font.o: No such file or directory
g++: error: src/glyph.o: No such file or directory
g++: error: src/normalize.o: No such file or directory
g++: error: src/table_tags.o: No such file or directory
g++: error: src/transform.o: No such file or directory
g++: error: src/woff2_dec.o: No such file or directory
g++: error: src/woff2_enc.o: No such file or directory
g++: error: src/woff2_common.o: No such file or directory
g++: error: src/woff2_out.o: No such file or directory
g++: error: src/variable_length.o: No such file or directory
Makefile:56: recipe for target 'woff2_compress' failed
make: *** [woff2_compress] Error 1

I would prefer to avoid requiring the user to install CMake.

woff2_compress does not allow to specify WOFF metadata

woff2_compress only accepts the input font file as argument and does not allow to provide metadata (especially http://dev.w3.org/webfonts/WOFF2/spec/#Metadata).

As a comparison, sfnt2woff has the following parameters:

fred@debian:~$ sfnt2woff 
Usage:
  sfnt2woff [-v <maj>.<min>] [-m <metadata.xml>] [-p <private.dat>] <otffile>
    package OpenType <otffile> as WOFF, creating <otffile>.woff
Options:
    -v <maj>.<min>     set font version number (major and minor, both integers)
    -m <metadata.xml>  include metadata from <metadata.xml> (not validated)
    -p <private.dat>   include private data block

See also https://lists.w3.org/Archives/Public/www-font/2015JanMar/0000.html

Bounding Box not kept in conversion

This most commonly happens when converting icon fonts where icons are centered with a fixed width. Basically the icon looks to be anchored to the left inside of the box.

The zip below contains the 4 font files and the rendered output in a preview.html illustrating the difference between TTF, WOFF, WOFF2 (converted with this tool), and WOFF2 converted with a third party tool.

image

Download Fonts / preview.html

Thanks for looking into this and maintaining the project.

Related: sapegin/grunt-webfont#229

some warnings

When i compiled it i got 3 warnings, don't know if it is anything to care about or not...

make clean all
rm -f  src/font.o  src/glyph.o  src/normalize.o  src/table_tags.o  src/transform.o  src/woff2_dec.o  src/woff2_enc.o  src/woff2_common.o  src/variable_length.o  src/woff2_compress.o  src/woff2_decompress.o woff2_compress woff2_decompress
/Applications/Xcode.app/Contents/Developer/usr/bin/make -C brotli/dec clean
rm -f bit_reader.o decode.o huffman.o safe_malloc.o state.o streams.o
/Applications/Xcode.app/Contents/Developer/usr/bin/make -C brotli/enc clean
rm -f backward_references.o block_splitter.o brotli_bit_stream.o encode.o encode_parallel.o entropy_encode.o histogram.o literal_cost.o metablock.o static_dict.o streams.o 
c++ -fno-omit-frame-pointer -no-canonical-prefixes -std=c++11 -I./brotli/dec/ -I./brotli/enc/ -I./src -DOS_MACOSX  -c -o src/font.o src/font.cc
c++ -fno-omit-frame-pointer -no-canonical-prefixes -std=c++11 -I./brotli/dec/ -I./brotli/enc/ -I./src -DOS_MACOSX  -c -o src/glyph.o src/glyph.cc
c++ -fno-omit-frame-pointer -no-canonical-prefixes -std=c++11 -I./brotli/dec/ -I./brotli/enc/ -I./src -DOS_MACOSX  -c -o src/normalize.o src/normalize.cc
c++ -fno-omit-frame-pointer -no-canonical-prefixes -std=c++11 -I./brotli/dec/ -I./brotli/enc/ -I./src -DOS_MACOSX  -c -o src/table_tags.o src/table_tags.cc
c++ -fno-omit-frame-pointer -no-canonical-prefixes -std=c++11 -I./brotli/dec/ -I./brotli/enc/ -I./src -DOS_MACOSX  -c -o src/transform.o src/transform.cc
c++ -fno-omit-frame-pointer -no-canonical-prefixes -std=c++11 -I./brotli/dec/ -I./brotli/enc/ -I./src -DOS_MACOSX  -c -o src/woff2_dec.o src/woff2_dec.cc
c++ -fno-omit-frame-pointer -no-canonical-prefixes -std=c++11 -I./brotli/dec/ -I./brotli/enc/ -I./src -DOS_MACOSX  -c -o src/woff2_enc.o src/woff2_enc.cc
c++ -fno-omit-frame-pointer -no-canonical-prefixes -std=c++11 -I./brotli/dec/ -I./brotli/enc/ -I./src -DOS_MACOSX  -c -o src/woff2_common.o src/woff2_common.cc
c++ -fno-omit-frame-pointer -no-canonical-prefixes -std=c++11 -I./brotli/dec/ -I./brotli/enc/ -I./src -DOS_MACOSX  -c -o src/variable_length.o src/variable_length.cc
c++ -fno-omit-frame-pointer -no-canonical-prefixes -std=c++11 -I./brotli/dec/ -I./brotli/enc/ -I./src -DOS_MACOSX  -c -o src/woff2_compress.o src/woff2_compress.cc
c++ -fno-omit-frame-pointer -no-canonical-prefixes -std=c++11 -I./brotli/dec/ -I./brotli/enc/ -I./src -DOS_MACOSX  -c -o src/woff2_decompress.o src/woff2_decompress.cc
/Applications/Xcode.app/Contents/Developer/usr/bin/make -C brotli/dec
cc -fno-omit-frame-pointer -no-canonical-prefixes -Wall -DOS_MACOSX  -c -o bit_reader.o bit_reader.c
cc -fno-omit-frame-pointer -no-canonical-prefixes -Wall -DOS_MACOSX  -c -o decode.o decode.c
cc -fno-omit-frame-pointer -no-canonical-prefixes -Wall -DOS_MACOSX  -c -o huffman.o huffman.c
cc -fno-omit-frame-pointer -no-canonical-prefixes -Wall -DOS_MACOSX  -c -o safe_malloc.o safe_malloc.c
cc -fno-omit-frame-pointer -no-canonical-prefixes -Wall -DOS_MACOSX  -c -o state.o state.c
cc -fno-omit-frame-pointer -no-canonical-prefixes -Wall -DOS_MACOSX  -c -o streams.o streams.c
/Applications/Xcode.app/Contents/Developer/usr/bin/make -C brotli/enc
c++ -fno-omit-frame-pointer -no-canonical-prefixes -std=c++11 -DOS_MACOSX  -c -o backward_references.o backward_references.cc
c++ -fno-omit-frame-pointer -no-canonical-prefixes -std=c++11 -DOS_MACOSX  -c -o block_splitter.o block_splitter.cc
c++ -fno-omit-frame-pointer -no-canonical-prefixes -std=c++11 -DOS_MACOSX  -c -o brotli_bit_stream.o brotli_bit_stream.cc
c++ -fno-omit-frame-pointer -no-canonical-prefixes -std=c++11 -DOS_MACOSX  -c -o encode.o encode.cc
c++ -fno-omit-frame-pointer -no-canonical-prefixes -std=c++11 -DOS_MACOSX  -c -o encode_parallel.o encode_parallel.cc
c++ -fno-omit-frame-pointer -no-canonical-prefixes -std=c++11 -DOS_MACOSX  -c -o entropy_encode.o entropy_encode.cc
c++ -fno-omit-frame-pointer -no-canonical-prefixes -std=c++11 -DOS_MACOSX  -c -o histogram.o histogram.cc
c++ -fno-omit-frame-pointer -no-canonical-prefixes -std=c++11 -DOS_MACOSX  -c -o literal_cost.o literal_cost.cc
c++ -fno-omit-frame-pointer -no-canonical-prefixes -std=c++11 -DOS_MACOSX  -c -o metablock.o metablock.cc
c++ -fno-omit-frame-pointer -no-canonical-prefixes -std=c++11 -DOS_MACOSX  -c -o static_dict.o static_dict.cc
static_dict.cc:366:16: warning: comparison of constant -62 with expression of type 'const uint8_t' (aka 'const unsigned char') is always false [-Wtautological-constant-out-of-range-compare]
      (data[0] == '\xc2' && data[1] == '\xa0')) {
       ~~~~~~~ ^  ~~~~~~
static_dict.cc:366:37: warning: comparison of constant -96 with expression of type 'const uint8_t' (aka 'const unsigned char') is always false [-Wtautological-constant-out-of-range-compare]
      (data[0] == '\xc2' && data[1] == '\xa0')) {
                            ~~~~~~~ ^  ~~~~~~
static_dict.cc:377:21: warning: comparison of constant -62 with expression of type 'const uint8_t' (aka 'const unsigned char') is always false [-Wtautological-constant-out-of-range-compare]
        if (data[0] == '\xc2') {
            ~~~~~~~ ^  ~~~~~~
3 warnings generated.
c++ -fno-omit-frame-pointer -no-canonical-prefixes -std=c++11 -DOS_MACOSX  -c -o streams.o streams.cc
c++   src/font.o  src/glyph.o  src/normalize.o  src/table_tags.o  src/transform.o  src/woff2_dec.o  src/woff2_enc.o  src/woff2_common.o  src/variable_length.o brotli/enc/*.o brotli/dec/*.o src/woff2_compress.o -o woff2_compress
openc++   src/font.o  src/glyph.o  src/normalize.o  src/table_tags.o  src/transform.o  src/woff2_dec.o  src/woff2_enc.o  src/woff2_common.o  src/variable_length.o brotli/enc/*.o brotli/dec/*.o src/woff2_decompress.o -o woff2_decompress

but the compilation was a success...

PowerPC build failure (store_bytes.h - invalid cast from type ‘int’ to type ‘uint16_t)

ppc64 builds fail with the following error

g++ -fno-omit-frame-pointer -no-canonical-prefixes -DFONT_COMPRESSION_BIN -D STDC_FORMAT_MACROS -fno-tree-vrp -std=c++11 -I./brotli/dec/ -I./brotli/enc/ -I./src -c -o src/font.o src/font.cc
In file included from src/font.cc:23:0:
src/./store_bytes.h: In function ‘size_t woff2::Store16(uint8_t
, size_t, int)’:
src/./store_bytes.h:40:76: error: invalid cast from type ‘int’ to type ‘uint16_t {aka short unsigned int}’
*reinterpret_cast<uint16_t
>(dst + offset) = reinterpret_cast<uint16_t>(x);
^
src/./store_bytes.h: In function ‘void woff2::Store16(int, size_t_, uint8_t_)’:
src/./store_bytes.h:62:37: error: invalid cast from type ‘int’ to type ‘uint16_t {aka short unsigned int}’
reinterpret_cast<uint16_t>(val);
^
: recipe for target 'src/font.o' failed

Consider relicensing to BSD or MIT license

Hi, I'm a WebKit project developer. On Linux, we currently bundle the woff2 library. Yesterday we discovered a license incompatibility: woff2 uses the Apache 2 license, but WebKit needs to remain available under the LGPLv2+ license. We can't add Apache 2 to the mix because, as a system library, we need to retain compatibility with GPLv2 applications (without expecting all applications using WebKit to upgrade to GPLv3+). So changing the license of WebKit is not an option. Clearly we failed to do our usual due diligence when adding a new dependency to WebKit, as we've been bundling woff2 for a couple years now. And obviously that is our fault and not Google's.

Unfortunately, our current plan is to immediately remove support for woff2 fonts from WebKit (on Linux) until we are able to reimplement the functionality provided by this library. We would not have to do this if woff2 was available under, say, a BSD or MIT license. (Or LGPLv2+, but I don't think it's typical for Google to use that license.) It would be really, really nice for us if relicensing could be considered. It looks like there are very few non-Google contributors to this project, so it should be feasible.

Note: this doesn't affect WebKit on Apple products, because GPLv2 compatibility is not an issue there and woff2 support is implemented using other system libraries on those platforms. It matters only for Linux.

CC @fred-wang

Compile issue with Cygwin

Compiling the referenced version of brotli did not succeed on Cygwin. I used the following workaround:

diff --git a/enc/Makefile b/enc/Makefile
index 7408d8a..1cf8b52 100644
--- a/enc/Makefile
+++ b/enc/Makefile
@@ -2,6 +2,12 @@

include ../shared.mk

+OSO := $(shell uname -o)
+
+ifeq ($(OSO), Cygwin)

  • CXXFLAGS += -include cstdlib
    

    +endif
    +

    OBJS = backward_references.o block_splitter.o brotli_bit_stream.o encode.o encode_parallel.o entropy_encode.o histogram.o literal_cost.o metablock.o static_dict.o streams.o

all : $(OBJS)

Compile error on Debian

make clean all
rm -f  src/font.o  src/glyph.o  src/normalize.o  src/table_tags.o  src/transform.o  src/woff2_dec.o
src/woff2_enc.o  src/woff2_common.o  src/variable_length.o  src/woff2_compress.o      src/woff2_decompress.o woff2_compress woff2_decompress
make -C brotli/dec clean
make[1]: Entering directory `/home/vagrant/woff2/brotli/dec'
rm -f bit_reader.o decode.o huffman.o safe_malloc.o state.o streams.o
make[1]: Leaving directory `/home/vagrant/woff2/brotli/dec'
make -C brotli/enc clean
make[1]: Entering directory `/home/vagrant/woff2/brotli/enc'
rm -f backward_references.o block_splitter.o brotli_bit_stream.o encode.o encode_parallel.o entropy_encode.o histogram.o literal_cost.o metablock.o static_dict.o streams.o
make[1]: Leaving directory `/home/vagrant/woff2/brotli/enc'
g++ -fno-omit-frame-pointer -no-canonical-prefixes -fno-tree-vrp -std=c++11 -I./brotli/dec/ -I./brotli/enc/ -I./src  -c -o src/font.o src/font.cc
g++ -fno-omit-frame-pointer -no-canonical-prefixes -fno-tree-vrp -std=c++11 -I./brotli/dec/ -I./brotli/enc/ -I./src  -c -o src/glyph.o src/glyph.cc
g++ -fno-omit-frame-pointer -no-canonical-prefixes -fno-tree-vrp -std=c++11 -I./brotli/dec/ -I./brotli/enc/ -I./src  -c -o src/normalize.o src/normalize.cc
g++ -fno-omit-frame-pointer -no-canonical-prefixes -fno-tree-vrp -std=c++11 -I./brotli/dec/ -I./brotli/enc/ -I./src  -c -o src/table_tags.o src/table_tags.cc
g++ -fno-omit-frame-pointer -no-canonical-prefixes -fno-tree-vrp -std=c++11 -I./brotli/dec/ -I./brotli/enc/ -I./src  -c -o src/transform.o src/transform.cc
g++ -fno-omit-frame-pointer -no-canonical-prefixes -fno-tree-vrp -std=c++11 -I./brotli/dec/ -I./brotli/enc/ -I./src  -c -o src/woff2_dec.o src/woff2_dec.cc
src/woff2_dec.cc: In function ‘bool woff2::ConvertWOFF2ToTTF(uint8_t*, size_t, const uint8_t*, size_t)’:
src/woff2_dec.cc:939:49: error: expected ‘)’ before ‘PRIu64’
make: *** [src/woff2_dec.o] Error 1

Using built-in specs.
COLLECT_GCC=gcc
COLLECT_LTO_WRAPPER=/usr/lib/gcc/x86_64-linux-gnu/4.7/lto-wrapper
Target: x86_64-linux-gnu
Configured with: ../src/configure -v --with-pkgversion='Debian 4.7.2-5' --with-bugurl=file:///usr/share/doc/gcc-4.7/README.Bugs --enable-languages=c,c++,go,fortran,objc,obj-c++ --prefix=/usr --program-suffix=-4.7 --enable-shared --enable-linker-build-id --with-system-zlib --libexecdir=/usr/lib --without-included-gettext --enable-threads=posix --with-gxx-include-dir=/usr/include/c++/4.7 --libdir=/usr/lib --enable-nls --with-sysroot=/ --enable-clocale=gnu --enable-libstdcxx-debug --enable-libstdcxx-time=yes --enable-gnu-unique-object --enable-plugin --enable-objc-gc --with-arch-32=i586 --with-tune=generic --enable-checking=release --build=x86_64-linux-gnu --host=x86_64-linux-gnu --target=x86_64-linux-gnu
Thread model: posix

'make clean' should remove src/.deps/ and src/.dirstamp

Discover this while playing with ots, which uses this as a submodule. 'make' then 'make clean' in the woff2 directory results in ots's git status as:

modified:   third_party/woff2 (untracked content)

and the untracked content are src/.deps/ and src/.dirstamp

Extended Metadata Block

Hi,
how can I add metadata to the woff2 file? Is there any documentation?
Thanks,
Christoph

Prevent "Brotli bombing"

To prevent out-of-memory error by malformed webfonts, the WOFF2 decoder in OTS rejects Brotli-encoded WOFF2 tables that decompress to larger than 30MB.

https://github.com/khaledhosny/ots/blob/ab40012/src/woff2.cc#L1016

Currently woff2_dec.cc allows up to 4GB uncompressed buffer, so we might want to add some limitation.
If 30MB limitation is too restrictive for non-browser use cases, maybe we could use result_length (the output size of ConvertWOFF2ToTTF) instead.

Ability to create a libwoff2 library

This is the same idea as librotli (google/brotli#326).
At the moment we have woff2_decompress and woff2_compress executables but it would be great to generate libraries exposing woff2_dec.h and woff2_enc.h APIs so that other programs can just link to them.

decode.h missing

When I call make all I get an error

g++ -fno-omit-frame-pointer -no-canonical-prefixes -DFONT_COMPRESSION_BIN -D __STDC_FORMAT_MACROS -fno-tree-vrp -std=c++11 -I./brotli/dec/ -I./brotli/enc/ -I./src  -c -o src/woff2_dec.o src/woff2_dec.cc
src/woff2_dec.cc:30:22: fatal error: ./decode.h: No such file or directory
 #include "./decode.h"
                      ^
compilation terminated.
make: *** [<eingebaut>: src/woff2_dec.o] Fehler 1

I don't see `decode.h` anywhere.
Has `compressor.h` appeared in the meantime?
https://github.com/google/woff2/commit/07cd303dd2959cbf69a6840706c0896e49e42677

Decompress puts file in wrong place

Would be very helpful if we could specify the output path for a woff2_decompress call. Right now, I need to run the call as follows:

cd /home/ubuntu/webfont-generator/vendor/woff2
./woff2_decompress /var/www/website.com/font.woff2

This then puts the font in the following location:

/var/www/website.ttf

This is presumably because of line #33 in /vendor/woff2/src/woff2_decompress.cc

string outfilename = filename.substr(0, filename.find_last_of(".")) + ".ttf";

Being able to specify the output location would address this, or else, have line #33 be smarter and store the decompressed font in the same directory from which it came.

Subsetting?

Can this tool subset directly or has the input TTF be subsetted first?

Provide C bindings

After working on fontforge/fontforge#3307, and given how simple the woff2 interface is, it would be nice if a C interface was exposed (e.g. something like this), instead of having to do that on our side. It would also make it easier to create bindings to other languages which often have C interop.

Compilation problem under MinGW

_byteswap_ulong is not defined in MinGW

diff --git a/src/buffer.h b/src/buffer.h
index 08681a6..9e08bba 100644
--- a/src/buffer.h
+++ b/src/buffer.h
@@ -28,11 +28,18 @@ typedef int int32_t;
 typedef unsigned int uint32_t;
 typedef __int64 int64_t;
 typedef unsigned __int64 uint64_t;
+#ifdef _MSC_VER
 #define ntohl(x) _byteswap_ulong (x)
 #define ntohs(x) _byteswap_ushort (x)
 #define htonl(x) _byteswap_ulong (x)
 #define htons(x) _byteswap_ushort (x)
 #else
+#define ntohl(x) __builtin_bswap32 (x)
+#define ntohs(x) ((x >> 8) | (x << 8))
+#define htonl(x) __builtin_bswap32 (x)
+#define htons(x) ((x >> 8) | (x << 8))
+#endif
+#else
 #include <arpa/inet.h>
 #include <stdint.h>
 #endif

With that changes, everything compiles without problems.

build failed: ./decode.h: No such file or directory

$make

g++ -fno-omit-frame-pointer -no-canonical-prefixes -fno-tree-vrp -std=c++11 -I./brotli/dec/ -I./brotli/enc/ -I./src -c -o src/font.o src/font.cc
g++ -fno-omit-frame-pointer -no-canonical-prefixes -fno-tree-vrp -std=c++11 -I./brotli/dec/ -I./brotli/enc/ -I./src -c -o src/glyph.o src/glyph.cc
g++ -fno-omit-frame-pointer -no-canonical-prefixes -fno-tree-vrp -std=c++11 -I./brotli/dec/ -I./brotli/enc/ -I./src -c -o src/normalize.o src/normalize.cc
g++ -fno-omit-frame-pointer -no-canonical-prefixes -fno-tree-vrp -std=c++11 -I./brotli/dec/ -I./brotli/enc/ -I./src -c -o src/table_tags.o src/table_tags.cc
g++ -fno-omit-frame-pointer -no-canonical-prefixes -fno-tree-vrp -std=c++11 -I./brotli/dec/ -I./brotli/enc/ -I./src -c -o src/transform.o src/transform.cc
g++ -fno-omit-frame-pointer -no-canonical-prefixes -fno-tree-vrp -std=c++11 -I./brotli/dec/ -I./brotli/enc/ -I./src -c -o src/woff2_dec.o src/woff2_dec.cc
src/woff2_dec.cc:29:22: fatal error: ./decode.h: No such file or directory
#include "./decode.h"
^
compilation terminated.
make: *** [src/woff2_dec.o] Error 1

Compiling fails on Ubuntu 16.04

Here's the last few lines of the output:

g++ -fno-omit-frame-pointer -no-canonical-prefixes -DFONT_COMPRESSION_BIN -D __STDC_FORMAT_MACROS -fno-tree-vrp -std=c++11 -I./brotli/c/include/ -I./src -I./include  -c -o src/convert_woff2ttf_fuzzer_new_entry.o src/convert_woff2ttf_fuzzer_new_entry.cc
ar cr f src/convert_woff2ttf_fuzzer.a  src/font.o  src/glyph.o  src/normalize.o  src/table_tags.o  src/transform.o  src/woff2_dec.o  src/woff2_enc.o  src/woff2_common.o  src/woff2_out.o  src/variable_length.o \
      brotli/bin/obj/c/common/*.o brotli/bin/obj/c/enc/*.o brotli/bin/obj/c/dec/*.o src/convert_woff2ttf_fuzzer.o
ar: src/convert_woff2ttf_fuzzer.a: No such file or directory
Makefile:52: recipe for target 'convert_woff2ttf_fuzzer' failed
make: *** [convert_woff2ttf_fuzzer] Error 1

53846e1 compiled successfully

make clean all fails with error

#With the current version https://github.com/google/woff2/tree/82a9f3afb28efb5c544fb6fa883408f167d6105f

the setup make clean all fails on OSX 10.11.6 and XCODE 8.2 with the following error:

make clean all
rm -f  src/font.o  src/glyph.o  src/normalize.o  src/table_tags.o  src/transform.o  src/woff2_dec.o  src/woff2_enc.o  src/woff2_common.o  src/woff2_out.o  src/variable_length.o  src/woff2_compress.o  src/woff2_decompress.o woff2_compress woff2_decompress  src/convert_woff2ttf_fuzzer.o  src/convert_woff2ttf_fuzzer_new_entry.o
/Applications/Xcode.app/Contents/Developer/usr/bin/make -C brotli/dec clean
rm -f bit_reader.o decode.o dictionary.o huffman.o state.o
/Applications/Xcode.app/Contents/Developer/usr/bin/make -C brotli/enc clean
rm -f backward_references.o block_splitter.o brotli_bit_stream.o compress_fragment.o compress_fragment_two_pass.o encode.o encode_parallel.o entropy_encode.o histogram.o literal_cost.o metablock.o static_dict.o streams.o utf8_util.o dictionary.o
c++ -fno-omit-frame-pointer -no-canonical-prefixes -DFONT_COMPRESSION_BIN -D __STDC_FORMAT_MACROS -std=c++11 -I./brotli/dec/ -I./brotli/enc/ -I./src -DOS_MACOSX  -c -o src/font.o src/font.cc
c++ -fno-omit-frame-pointer -no-canonical-prefixes -DFONT_COMPRESSION_BIN -D __STDC_FORMAT_MACROS -std=c++11 -I./brotli/dec/ -I./brotli/enc/ -I./src -DOS_MACOSX  -c -o src/glyph.o src/glyph.cc
c++ -fno-omit-frame-pointer -no-canonical-prefixes -DFONT_COMPRESSION_BIN -D __STDC_FORMAT_MACROS -std=c++11 -I./brotli/dec/ -I./brotli/enc/ -I./src -DOS_MACOSX  -c -o src/normalize.o src/normalize.cc
c++ -fno-omit-frame-pointer -no-canonical-prefixes -DFONT_COMPRESSION_BIN -D __STDC_FORMAT_MACROS -std=c++11 -I./brotli/dec/ -I./brotli/enc/ -I./src -DOS_MACOSX  -c -o src/table_tags.o src/table_tags.cc
c++ -fno-omit-frame-pointer -no-canonical-prefixes -DFONT_COMPRESSION_BIN -D __STDC_FORMAT_MACROS -std=c++11 -I./brotli/dec/ -I./brotli/enc/ -I./src -DOS_MACOSX  -c -o src/transform.o src/transform.cc
c++ -fno-omit-frame-pointer -no-canonical-prefixes -DFONT_COMPRESSION_BIN -D __STDC_FORMAT_MACROS -std=c++11 -I./brotli/dec/ -I./brotli/enc/ -I./src -DOS_MACOSX  -c -o src/woff2_dec.o src/woff2_dec.cc
c++ -fno-omit-frame-pointer -no-canonical-prefixes -DFONT_COMPRESSION_BIN -D __STDC_FORMAT_MACROS -std=c++11 -I./brotli/dec/ -I./brotli/enc/ -I./src -DOS_MACOSX  -c -o src/woff2_enc.o src/woff2_enc.cc
c++ -fno-omit-frame-pointer -no-canonical-prefixes -DFONT_COMPRESSION_BIN -D __STDC_FORMAT_MACROS -std=c++11 -I./brotli/dec/ -I./brotli/enc/ -I./src -DOS_MACOSX  -c -o src/woff2_common.o src/woff2_common.cc
c++ -fno-omit-frame-pointer -no-canonical-prefixes -DFONT_COMPRESSION_BIN -D __STDC_FORMAT_MACROS -std=c++11 -I./brotli/dec/ -I./brotli/enc/ -I./src -DOS_MACOSX  -c -o src/woff2_out.o src/woff2_out.cc
c++ -fno-omit-frame-pointer -no-canonical-prefixes -DFONT_COMPRESSION_BIN -D __STDC_FORMAT_MACROS -std=c++11 -I./brotli/dec/ -I./brotli/enc/ -I./src -DOS_MACOSX  -c -o src/variable_length.o src/variable_length.cc
c++ -fno-omit-frame-pointer -no-canonical-prefixes -DFONT_COMPRESSION_BIN -D __STDC_FORMAT_MACROS -std=c++11 -I./brotli/dec/ -I./brotli/enc/ -I./src -DOS_MACOSX  -c -o src/woff2_compress.o src/woff2_compress.cc
c++ -fno-omit-frame-pointer -no-canonical-prefixes -DFONT_COMPRESSION_BIN -D __STDC_FORMAT_MACROS -std=c++11 -I./brotli/dec/ -I./brotli/enc/ -I./src -DOS_MACOSX  -c -o src/woff2_decompress.o src/woff2_decompress.cc
/Applications/Xcode.app/Contents/Developer/usr/bin/make -C brotli/dec
cc -fno-omit-frame-pointer -no-canonical-prefixes -O2 -Wmissing-prototypes -Wall -DOS_MACOSX  -c -o bit_reader.o bit_reader.c
cc -fno-omit-frame-pointer -no-canonical-prefixes -O2 -Wmissing-prototypes -Wall -DOS_MACOSX  -c -o decode.o decode.c
cc -fno-omit-frame-pointer -no-canonical-prefixes -O2 -Wmissing-prototypes -Wall -DOS_MACOSX  -c -o dictionary.o dictionary.c
cc -fno-omit-frame-pointer -no-canonical-prefixes -O2 -Wmissing-prototypes -Wall -DOS_MACOSX  -c -o huffman.o huffman.c
cc -fno-omit-frame-pointer -no-canonical-prefixes -O2 -Wmissing-prototypes -Wall -DOS_MACOSX  -c -o state.o state.c
/Applications/Xcode.app/Contents/Developer/usr/bin/make -C brotli/enc
c++ -fno-omit-frame-pointer -no-canonical-prefixes -O2 -Wmissing-declarations -DOS_MACOSX  -c -o backward_references.o backward_references.cc
c++ -fno-omit-frame-pointer -no-canonical-prefixes -O2 -Wmissing-declarations -DOS_MACOSX  -c -o block_splitter.o block_splitter.cc
c++ -fno-omit-frame-pointer -no-canonical-prefixes -O2 -Wmissing-declarations -DOS_MACOSX  -c -o brotli_bit_stream.o brotli_bit_stream.cc
c++ -fno-omit-frame-pointer -no-canonical-prefixes -O2 -Wmissing-declarations -DOS_MACOSX  -c -o compress_fragment.o compress_fragment.cc
c++ -fno-omit-frame-pointer -no-canonical-prefixes -O2 -Wmissing-declarations -DOS_MACOSX  -c -o compress_fragment_two_pass.o compress_fragment_two_pass.cc
c++ -fno-omit-frame-pointer -no-canonical-prefixes -O2 -Wmissing-declarations -DOS_MACOSX  -c -o encode.o encode.cc
c++ -fno-omit-frame-pointer -no-canonical-prefixes -O2 -Wmissing-declarations -DOS_MACOSX  -c -o encode_parallel.o encode_parallel.cc
c++ -fno-omit-frame-pointer -no-canonical-prefixes -O2 -Wmissing-declarations -DOS_MACOSX  -c -o entropy_encode.o entropy_encode.cc
c++ -fno-omit-frame-pointer -no-canonical-prefixes -O2 -Wmissing-declarations -DOS_MACOSX  -c -o histogram.o histogram.cc
c++ -fno-omit-frame-pointer -no-canonical-prefixes -O2 -Wmissing-declarations -DOS_MACOSX  -c -o literal_cost.o literal_cost.cc
c++ -fno-omit-frame-pointer -no-canonical-prefixes -O2 -Wmissing-declarations -DOS_MACOSX  -c -o metablock.o metablock.cc
c++ -fno-omit-frame-pointer -no-canonical-prefixes -O2 -Wmissing-declarations -DOS_MACOSX  -c -o static_dict.o static_dict.cc
c++ -fno-omit-frame-pointer -no-canonical-prefixes -O2 -Wmissing-declarations -DOS_MACOSX  -c -o streams.o streams.cc
c++ -fno-omit-frame-pointer -no-canonical-prefixes -O2 -Wmissing-declarations -DOS_MACOSX  -c -o utf8_util.o utf8_util.cc
c++   src/font.o  src/glyph.o  src/normalize.o  src/table_tags.o  src/transform.o  src/woff2_dec.o  src/woff2_enc.o  src/woff2_common.o  src/woff2_out.o  src/variable_length.o brotli/enc/*.o brotli/dec/*.o src/woff2_compress.o -o woff2_compress
c++   src/font.o  src/glyph.o  src/normalize.o  src/table_tags.o  src/transform.o  src/woff2_dec.o  src/woff2_enc.o  src/woff2_common.o  src/woff2_out.o  src/variable_length.o brotli/enc/*.o brotli/dec/*.o src/woff2_decompress.o -o woff2_decompress
c++ -fno-omit-frame-pointer -no-canonical-prefixes -DFONT_COMPRESSION_BIN -D __STDC_FORMAT_MACROS -std=c++11 -I./brotli/dec/ -I./brotli/enc/ -I./src -DOS_MACOSX  -c -o src/convert_woff2ttf_fuzzer.o src/convert_woff2ttf_fuzzer.cc
c++ -fno-omit-frame-pointer -no-canonical-prefixes -DFONT_COMPRESSION_BIN -D __STDC_FORMAT_MACROS -std=c++11 -I./brotli/dec/ -I./brotli/enc/ -I./src -DOS_MACOSX  -c -o src/convert_woff2ttf_fuzzer_new_entry.o src/convert_woff2ttf_fuzzer_new_entry.cc
ar crf src/convert_woff2ttf_fuzzer.a  src/font.o  src/glyph.o  src/normalize.o  src/table_tags.o  src/transform.o  src/woff2_dec.o  src/woff2_enc.o  src/woff2_common.o  src/woff2_out.o  src/variable_length.o brotli/enc/*.o brotli/dec/*.o src/convert_woff2ttf_fuzzer.o
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/ar: illegal option -- f
usage:  ar -d [-TLsv] archive file ...
	ar -m [-TLsv] archive file ...
	ar -m [-abiTLsv] position archive file ...
	ar -p [-TLsv] archive [file ...]
	ar -q [-cTLsv] archive file ...
	ar -r [-cuTLsv] archive file ...
	ar -r [-abciuTLsv] position archive file ...
	ar -t [-TLsv] archive [file ...]
	ar -x [-ouTLsv] archive [file ...]
make: *** [convert_woff2ttf_fuzzer] Error 1

can't decode WOFF2 where only hmtx is transformed, but not glyf

The following zip archive contains two WOFF2 fonts.
In the first ("TestTTF-Regular+hmtx+glyf.woff2") both the glyf (and loca) and hmtx table are transformed; in the second font ("TestTTF-Regular+hmtx-glyf.woff2") only the hmtx table is transformed, whereas the glyf and loca are stored in their original form without pre-processing transformation.

Decompressing with woff2_decompress the first font (with all tables trasformed) completes successfully, whereas attempting to decompress the second font (where only hmtx is transformed but not glyf+loca) fails.

https://github.com/khaledhosny/ots/files/3281395/test-woff2-hmtx-transform.zip

As far as I know, the WOFF2 spec doesn't say that whenever hmtx is transformed, glyf should also be transformed. Only glyf and loca have to be transformed or not transformed together.

I reported the same issue in khaledhosny/ots#190, which uses the google/woff2 library to decode WOFF2 fonts.

Add CLI command to show version

Would like to know somehow what version i have and what version is released on github

eg:

$ woff2_compress -version [-v]
$ woff2_decompress -version [-v]

decoder fails to reconstruct unpadded glyf table

Following a discussion on Webfonts-WG mailing list, there seems to be a bug in the current decoder when reconstructing the glyf table from WOFF2 fonts created by a different encoder.

If the glyf table's encoded origLength happens to be smaller than the length of the reconstructed table, the decoder fails because it interprets the encoded origLength as the destination length for the reconstructed glyf table.

The problem occurs especially if the glyf table was encoded without internal 4-byte padding between glyph entries. While the reference encoder still produces padded glyf tables, this requirement was removed in the latest version of the WOFF2 specification, so one would expect that the reference decoder would be able to decode both padded and unpadded glyf tables.

Thank you,

Cosimo

woff2_decompress fails with “implausible compression ratio”

I get the following error when I attempt woff2_decompress on a woff2 font that I have just compressed using woff2_compress:

Implausible compression ratio 770.0

Admittedly the source TTF contains 65535 glyphs, almost all of which are duplicates. It is a test font, but I still expect to be able to decompress it.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.