GithubHelp home page GithubHelp logo

sfnt2woff-zopfli's Introduction

Create WOFF files with Zopfli compression

This is a modified version of the sfnt2woff utility that uses Zopfli as a compression algorithm instead of zlib. This results in compression gains of โ€” on average โ€” 5-8% compared to regular WOFF files. Zopfli generates compressed output that is compatible with regular zlib compression so the resulting WOFF files can be used everywhere.

##Usage

To create a WOFF file from an OpenType files:

> sfnt2woff-zopfli [-v <maj>.<min>] [-m <metadata.xml>] [-n <iterations>] [-p <private.dat>] <otffile>

Options:

-v <maj>.<min>     set font version number (major and minor, both integers)
-m <metadata.xml>  include metadata from <metadata.xml> (not validated)
-n <iterations>    number of zopfli iterations (default = 15)
-p <private.dat>   include private data block

To decompress a WOFF file and write the OpenType file to stdout:

> woff2sfnt-zopfli [-v | -m | -p] <woff>

Options:

-v   write font version to stdout
-m   write WOFF metadata block to stdout
-p   write private data block to stdout

Compiling

To compile the utilities, run make:

> make

This will compile two utilities sfnt2woff-zopfli to convert OpenType files to WOFF and woff2sfnt-zopfli to convert WOFF files back to OpenType files. If the build was succesful you can make them available on your system by copying the resulting executables to /usr/local/bin and making them executable (chmod 755).

Licensing

The WOFF portion of the code is taken from sfnt2woff, which is licensed under the MPL/GPL/LGPL. The Zopfli implementation is licensed under the Apache License. My modifications to woff.c are also licensed under the MPL/GPL/LGPL.

Alternative

You can also use the ttf2woff tool, which also converts OpenType files to WOFF using Zopfli, but is exclusively licensed under the GPL. However it doesn't have a command line option for the number of Zopfli iterations and thus can't create files as small as sfnt2woff-zopfli.

sfnt2woff-zopfli's People

Contributors

bkmgit avatar bramstein avatar fangel avatar leif-w avatar matuzo avatar musicinmybrain avatar stapelberg avatar

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

sfnt2woff-zopfli's Issues

woff2sfnt-zopfli doesn't convert WOFF to OTF/TTF

The documentation says:

This will compile two utilities sfnt2woff-zopfli to convert OpenType files to WOFF and woff2sfnt-zopfli to convert WOFF files back to OpenType files.

But running woff2sfnt-zopfli.exe, it seems to be only possible to decode to STDOUT:

  woff2sfnt-zopfli [-v | -m | -p] <woff>
    decode WOFF file <woff>, writing OpenType data to stdout
Options (instead of decoding to OpenType format)
    -v   write font version to stdout
    -m   write WOFF metadata block to stdout
    -p   write private data block to stdout
Note: only one of -v, -m, -p may be used at a time.

Was this feature removed at some point?

Build issues

Hello,

I tried building this software on windows 10 with msys and mingw64.
The following warnings occur during build time:

$ make all
cc   -Izopfli  \
        woff.c sfnt2woff.c -o sfnt2woff-zopfli \
         zopfli/blocksplitter.c zopfli/cache.c zopfli/deflate.c zopfli/gzip_container.c zopfli/hash.c zopfli/katajainen.c zopfli/lz77.c zopfli/squeeze.c zopfli/tree.c zopfli/util.c zopfli/zlib_container.c zopfli/zopfli_lib.c -lz -lm
woff.c: In function 'woffEncode':
woff.c:291:113: warning: passing argument 6 of 'ZopfliCompress' from incompatible pointer type [-Win
compatible-pointer-types]
  291 |     ZopfliCompress(&options, ZOPFLI_FORMAT_ZLIB, (const uint8_t *) (sfntData + sourceOffset)
, sourceLen, &dest, &destLen);
      |
                    ^~~~~~~~
      |
                    |
      |
                    uLong * {aka long unsigned int *}
In file included from woff.c:45:
zopfli/zopfli.h:91:50: note: expected 'size_t *' {aka 'long long unsigned int *'} but argument is of
 type 'uLong *' {aka 'long unsigned int *'}
   91 |                     unsigned char** out, size_t* outsize);
      |                                          ~~~~~~~~^~~~~~~
woff.c: In function 'woffSetMetadata':
woff.c:551:98: warning: passing argument 6 of 'ZopfliCompress' from incompatible pointer type [-Winc
ompatible-pointer-types]
  551 |     ZopfliCompress(&options, ZOPFLI_FORMAT_ZLIB, (const uint8_t *) metaData, metaLen, &compD
ata, &compLen);
      |
     ^~~~~~~~
      |
     |
      |
     uLong * {aka long unsigned int *}
zopfli/zopfli.h:91:50: note: expected 'size_t *' {aka 'long long unsigned int *'} but argument is of
 type 'uLong *' {aka 'long unsigned int *'}
   91 |                     unsigned char** out, size_t* outsize);
      |                                          ~~~~~~~~^~~~~~~
cc   -Izopfli  \
        woff.c woff2sfnt.c -o woff2sfnt-zopfli \
         zopfli/blocksplitter.c zopfli/cache.c zopfli/deflate.c zopfli/gzip_container.c zopfli/hash.c zopfli/katajainen.c zopfli/lz77.c zopfli/squeeze.c zopfli/tree.c zopfli/util.c zopfli/zlib_container.c zopfli/zopfli_lib.c -lz -lm
woff.c: In function 'woffEncode':
woff.c:291:113: warning: passing argument 6 of 'ZopfliCompress' from incompatible pointer type [-Win
compatible-pointer-types]
  291 |     ZopfliCompress(&options, ZOPFLI_FORMAT_ZLIB, (const uint8_t *) (sfntData + sourceOffset)
, sourceLen, &dest, &destLen);
      |
                    ^~~~~~~~
      |
                    |
      |
                    uLong * {aka long unsigned int *}
In file included from woff.c:45:
zopfli/zopfli.h:91:50: note: expected 'size_t *' {aka 'long long unsigned int *'} but argument is of
 type 'uLong *' {aka 'long unsigned int *'}
   91 |                     unsigned char** out, size_t* outsize);
      |                                          ~~~~~~~~^~~~~~~
woff.c: In function 'woffSetMetadata':
woff.c:551:98: warning: passing argument 6 of 'ZopfliCompress' from incompatible pointer type [-Winc
ompatible-pointer-types]
  551 |     ZopfliCompress(&options, ZOPFLI_FORMAT_ZLIB, (const uint8_t *) metaData, metaLen, &compD
ata, &compLen);
      |
     ^~~~~~~~
      |
     |
      |
     uLong * {aka long unsigned int *}
zopfli/zopfli.h:91:50: note: expected 'size_t *' {aka 'long long unsigned int *'} but argument is of
 type 'uLong *' {aka 'long unsigned int *'}
   91 |                     unsigned char** out, size_t* outsize);
      |                                          ~~~~~~~~^~~~~~~


Add man pages

I wrote man pages (zip file, attached) based on the help output from the two binaries. Man pages are useful; please consider distributing these in the source tarball.

Reduce coupling with bundled Zopfli libray.

Some users need to build with an external Zopfli implementation instead of using the bundled Zopfli sources. Specifically, most Linux distributions forbid the use of bundled libraries, including Fedora (upstream for Red Hat Enterprise Linux, CentOS, and others) and Debian (upstream for Ubuntu, Mint, and others). Packagers can work around this by patching sources, but it is better if the upstream build makes it easy to remove the bundled dependency.

Personally, I would like to add sfnt2woff-zopfli to Fedora and EPEL, and it would be better if I could do so without patching the upstream sources. I have prepared a PR, #10, that would make it much easier to package it in any Linux distribution, and which I think would also benefit other users. I welcome any comments on these changes.

Thanks for taking the time to consider this.

Build fails on windows with VS 2015

Building this library via the NodeJS wrapper module node-sfnt2woff-zopfli configured for VS 2015 Update 3 gives an error regarding a redefinition of int8_t and different basic types.

Visual Studio defines int8_t and other inttypes since VS 2010, where they're available in stdint.h. Compilation fails because the compiler is being pedantic about a type mismatch with those standard headers.

You should either expand the #ifdef _MSC_VER check to handle compatible versions, or you should ensure that the redefinition is type-compatible. Adding an explicit signed to the redefinitions of int8_t; int16_t and int32_t might fix this, but the better method is probably to use what's there.

I.e. with MS compilers, import Microsoft's standard implementation if it is known to exist; otherwise rely on the older non-standard definitions for __int8 and similar. E.g.

#ifdef _MSC_VER
    #if _MSC_VER >= 1600
        #include <stdint>
    #else
        typedef __int8              int8_t;
        typedef __int16             int16_t;
        typedef __int32             int32_t;
        typedef __int64             int64_t;
        typedef unsigned __int8     uint8_t;
        typedef unsigned __int16    uint16_t;
        typedef unsigned __int32    uint32_t;
        typedef unsigned __int64    uint64_t;
    #endif
#endif

version

It would be nice if the tool could print a version number when run without arguments

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.