phpdftk API Documentation

Woff2Parser
in package

FinalYes

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
see
https://www.w3.org/TR/WOFF2/

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
string

decompressBytes()

Decompress WOFF2 bytes to raw sfnt (TTF/OTF) bytes.

public static decompressBytes(string $data) : string
Parameters
$data : string
Return values
string

detectFlavor()

Detect the flavor (TrueType or OpenType CFF) of a WOFF2 file.

public static detectFlavor(string $data) : string
Parameters
$data : string
Return values
string

isWoff2()

Detect whether bytes are a WOFF2 file.

public static isWoff2(string $data) : bool
Parameters
$data : string
Return values
bool

        
On this page

Search results