woff

package
v0.0.0-...-b4e252f Latest Latest
Warning

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

Go to latest
Published: Apr 14, 2026 License: Freetype Imports: 5 Imported by: 0

Documentation

Overview

Package woff decodes the Web Open Font Format containers (WOFF 1.0 and WOFF 2.0) into plain SFNT bytes that the truetype package can parse. The goal is transparent web-font loading: callers do not need to know whether a .woff / .woff2 file landed on disk versus a raw .ttf / .otf — they call Decode and hand the result to truetype.Parse.

This file implements WOFF 1.0 (zlib-compressed table data). WOFF 2.0 (brotli-compressed + glyph table transformations) lives in woff2.go.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Decode

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

Decode unpacks a WOFF container and returns the plain SFNT bytes. Accepts either WOFF 1.0 or WOFF 2.0 (if the woff2 support is available); non-WOFF input is returned unchanged as a convenience for callers that accept mixed web-font / raw-SFNT input.

func IsWOFF

func IsWOFF(data []byte) bool

IsWOFF reports whether data has a WOFF 1.0 or 2.0 signature. Call Decode to actually unpack it.

func RegisterBrotli

func RegisterBrotli(dec BrotliDecoder)

RegisterBrotli installs the given brotli decompression function so woff.Decode (and therefore truetype.Parse) can unpack WOFF2 files. Pass nil to clear the registration.

Typical setup in main:

import "github.com/andybalholm/brotli"
woff.RegisterBrotli(func(src []byte) ([]byte, error) {
    r := brotli.NewReader(bytes.NewReader(src))
    return io.ReadAll(r)
})

Types

type BrotliDecoder

type BrotliDecoder func(src []byte) ([]byte, error)

BrotliDecoder is any callable that takes a brotli-compressed byte slice and returns the uncompressed bytes. Go's standard library does not ship a brotli decompressor, so WOFF2 callers supply their own via RegisterBrotli — typical implementations wrap github.com/andybalholm/brotli.

type FormatError

type FormatError string

FormatError reports a malformed WOFF container.

func (FormatError) Error

func (e FormatError) Error() string

type UnsupportedError

type UnsupportedError string

UnsupportedError reports an unimplemented feature.

func (UnsupportedError) Error

func (e UnsupportedError) Error() string

Jump to

Keyboard shortcuts

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