Woff2Parser
in package
WOFF 2.0 (Web Open Font Format 2.0) decompressor.
Parses a WOFF2 container, decompresses the Brotli-compressed table data, and reconstructs the original sfnt (TrueType/OpenType) bytes. The result can be passed to TrueTypeParser::fromBytes() or OpenTypeParser::fromBytes().
WOFF2 uses Brotli compression and optional table transforms (glyf/loca/hmtx). This implementation handles the basic decompression and skips table transforms (the transformed tables are stored as-is when the transform flag indicates no transformation).
Brotli decompression requires ext-brotli (PECL). This class deliberately
does not shell out to external brotli binaries — font input is treated
as untrusted and the security cost of proc_open outweighs the
convenience. If ext-brotli is not installed, decompression throws.
Tags
Table of Contents
Methods
- decompress() : string
- Decompress a WOFF2 file to raw sfnt (TTF/OTF) bytes.
- decompressBytes() : string
- Decompress WOFF2 bytes to raw sfnt (TTF/OTF) bytes.
- detectFlavor() : string
- Detect the flavor (TrueType or OpenType CFF) of a WOFF2 file.
- isWoff2() : bool
- Detect whether bytes are a WOFF2 file.
Methods
decompress()
Decompress a WOFF2 file to raw sfnt (TTF/OTF) bytes.
public
static decompress(string $woff2Path) : string
Parameters
- $woff2Path : string
Return values
stringdecompressBytes()
Decompress WOFF2 bytes to raw sfnt (TTF/OTF) bytes.
public
static decompressBytes(string $data) : string
Parameters
- $data : string
Return values
stringdetectFlavor()
Detect the flavor (TrueType or OpenType CFF) of a WOFF2 file.
public
static detectFlavor(string $data) : string
Parameters
- $data : string
Return values
stringisWoff2()
Detect whether bytes are a WOFF2 file.
public
static isWoff2(string $data) : bool
Parameters
- $data : string