woff2

package
v0.1.3 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Oct 9, 2026 License: MIT Imports: 8 Imported by: 0

Documentation

Overview

Package woff2 packs TrueType and CFF-flavored OpenType fonts into WOFF2 (W3C WOFF File Format 2.0), the web font format browsers load with FontFace.

glyf and loca are stored with the WOFF2 glyf transform (the decoder rebuilds both from separated point, flag and instruction streams), every other table passes through, and the whole table stream is Brotli-compressed. The Brotli encoder is left out of builds tagged bdf_noconv; Encode then returns ErrNotAvailable and callers keep the plain sfnt.

Index

Constants

View Source
const MaxRatio = 100

MaxRatio is the largest ratio of the table stream to the WOFF2 file that decoders accept (kMaxPlausibleCompressionRatio of the reference decoder, which browsers use).

Variables

View Source
var ErrDecodeNotAvailable = errors.New("woff2: decoder not available in this build")

ErrDecodeNotAvailable is returned by Decode when the Brotli decoder is not compiled in (builds tagged bdf_noconv).

View Source
var ErrImplausible = errors.New("woff2: the font compresses more than decoders accept")

ErrImplausible is returned by Encode for a font that compresses more than MaxRatio times: a few glyphs left of a large font, whose tables are mostly zeros. Decoders take such a file for a decompression bomb and reject it, so the caller keeps the plain sfnt, which is as small once its part is deflated.

View Source
var ErrNotAvailable = errors.New("woff2: encoder not available in this build")

ErrNotAvailable is returned by Encode when the Brotli encoder is not compiled in.

View Source
var ErrTooLarge = errors.New("woff2: the tables of the font are too large")

ErrTooLarge is returned by Decode for a font whose tables are larger than 256 MiB together.

Functions

func Available

func Available() bool

Available reports whether the Brotli encoder is compiled in.

func Decode

func Decode(data []byte) ([]byte, error)

Decode unpacks a WOFF2 font into an sfnt font (TrueType or CFF-flavored OpenType), rebuilding the transformed glyf, loca and hmtx tables. Font collections are not supported.

func Encode

func Encode(font []byte) ([]byte, error)

Encode converts an sfnt font (TrueType outlines or CFF) into WOFF2. It returns ErrImplausible for a font that decoders would reject for its compression ratio.

func IsWOFF

func IsWOFF(data []byte) bool

IsWOFF reports whether data is a WOFF or WOFF2 file (already compressed).

Types

This section is empty.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL