# woofwoof
[](https://crates.io/crates/woofwoof)
[](https://docs.rs/woofwoof)
[](./LICENSE-MIT)

WOFF2 font compression and decompression for Rust.
Inspired by the [woff](https://github.com/bodoni/woff) crate, but with key differences:
- **Pure Rust brotli**: Uses the [brotli](https://crates.io/crates/brotli) crate instead of linking to C brotli
- **Windows support**: Compiles on Windows, Linux, and macOS
- **WOFF2 only**: No WOFF1 support — [WOFF2 adoption](https://caniuse.com/?search=woff2) is now widespread enough that serving WOFF1 is unnecessary
This crate wraps Google's [woff2](https://github.com/google/woff2) C++ library for the font-specific table transformations that make WOFF2 compress so well, while using pure Rust for brotli compression.
## Usage
```rust
use woofwoof::{compress, decompress};
// Compress TTF/OTF to WOFF2
let ttf_data = std::fs::read("font.ttf")?;
let woff2_data = compress(&ttf_data, "", 8, true)
.expect("compression failed");
// Decompress WOFF2 back to TTF/OTF
let roundtripped = decompress(&woff2_data)
.expect("decompression failed");
```
## API
### `compress(data, metadata, quality, transform) -> Option<Vec<u8>>`
Compress a TTF/OTF font to WOFF2 format.
- `data`: The TTF or OTF font data
- `metadata`: Optional extended metadata (XML string, usually empty `""`)
- `quality`: Brotli compression quality (0-11, recommended: 8-11)
- `transform`: Whether to apply font-specific transforms (recommended: `true`)
### `decompress(data) -> Option<Vec<u8>>`
Decompress a WOFF2 font back to TTF/OTF format.
## Why "woofwoof"? 🐕
Because it does WOFF2. Get it? WOFF... woof... woofwoof?
## Architecture
```
Rust API (compress/decompress)
│
▼
C wrapper (extern "C")
│
▼
Google woff2 C++ (font transforms)
│
▼
Rust brotli shim (#[no_mangle])
│
▼
brotli crate (pure Rust)
```
The C++ woff2 library handles the complex font table transformations that make WOFF2 compress so well. Instead of linking to C brotli, we provide stub headers and implement the brotli functions in Rust, forwarding to the pure Rust brotli crate.
## Testing
The test suite compresses a real font (Roboto) to WOFF2, verifies the WOFF2 signature, then decompresses it back. Note that roundtripped fonts are not byte-identical to the original due to WOFF2's font table transformations, but they are semantically equivalent.
```bash
cargo test
```
For manual verification, the compressed and decompressed fonts can be inspected with tools like [FontGoggles](https://fontgoggles.org/).
## Credits
This crate was inspired by [bodoni/woff](https://github.com/bodoni/woff), which pioneered the approach of wrapping Google's woff2 C++ library for Rust.
## Sponsors
Thanks to all individual sponsors:
<p> <a href="https://github.com/sponsors/fasterthanlime">
<picture>
<source media="(prefers-color-scheme: dark)" srcset="https://github.com/fasterthanlime/woofwoof/raw/main/static/sponsors/github-dark.svg">
<img src="https://github.com/fasterthanlime/woofwoof/raw/main/static/sponsors/github-light.svg" height="40" alt="GitHub Sponsors">
</picture>
</a> <a href="https://patreon.com/fasterthanlime">
<picture>
<source media="(prefers-color-scheme: dark)" srcset="https://github.com/fasterthanlime/woofwoof/raw/main/static/sponsors/patreon-dark.svg">
<img src="https://github.com/fasterthanlime/woofwoof/raw/main/static/sponsors/patreon-light.svg" height="40" alt="Patreon">
</picture>
</a> </p>
...along with corporate sponsors:
<p> <a href="https://zed.dev">
<picture>
<source media="(prefers-color-scheme: dark)" srcset="https://github.com/fasterthanlime/woofwoof/raw/main/static/sponsors/zed-dark.svg">
<img src="https://github.com/fasterthanlime/woofwoof/raw/main/static/sponsors/zed-light.svg" height="40" alt="Zed">
</picture>
</a> <a href="https://depot.dev?utm_source=woofwoof">
<picture>
<source media="(prefers-color-scheme: dark)" srcset="https://github.com/fasterthanlime/woofwoof/raw/main/static/sponsors/depot-dark.svg">
<img src="https://github.com/fasterthanlime/woofwoof/raw/main/static/sponsors/depot-light.svg" height="40" alt="Depot">
</picture>
</a> </p>
...without whom this work could not exist.
## License
Licensed under either of:
- Apache License, Version 2.0 ([LICENSE-APACHE](LICENSE-APACHE) or <http://www.apache.org/licenses/LICENSE-2.0>)
- MIT license ([LICENSE-MIT](LICENSE-MIT) or <http://opensource.org/licenses/MIT>)
at your option.
The bundled [woff2](https://github.com/google/woff2) C++ library is licensed under the MIT license.