woff2 library

Public API of the woff2 package.

See the package README for a quick start. The three main entry points are:

  • loadWoffFontFromAsset — one-call helper for the typical "bundle a .woff2 in assets/, use it in Text(...)" case.
  • WoffFontRegistry — batch-register multiple @font-face variants (e.g. weight / style families) parsed from a CSS file.
  • decodeFontIfWoff — low-level decoder for callers that just want WOFF / WOFF2SFNT bytes and will handle font loading themselves.

Classes

CssFontFaceRule
Parsed @font-face rule containing font metadata and source.
WoffFontRegistry
Registry for managing WOFF/WOFF2 (and TTF/OTF) fonts at runtime.

Enums

WoffDecodeResult
Result of a WOFF decode attempt.

Functions

decodeFontIfWoff(Uint8List bytes) → (WoffDecodeResult, Uint8List?)
Inspects bytes and converts WOFF1/WOFF2 to SFNT if needed.
extractFontFaceRules(String cssText) List<CssFontFaceRule>
Extracts every @font-face { ... } rule from a CSS text blob.
loadWoffFontFromAsset({required String fontFamily, required String assetPath, AssetBundle? bundle}) Future<bool>
Loads a single WOFF / WOFF2 / TTF / OTF font from an asset bundle and registers it under fontFamily so it can be used in Text(...) widgets.
loadWoffFontFromBytes({required String fontFamily, required Uint8List bytes}) Future<bool>
Loads a single WOFF / WOFF2 / TTF / OTF font from raw bytes and registers it under fontFamily.

Typedefs

WoffSrcResolver = Future<Uint8List?> Function(String src)
Callback used by WoffFontRegistry to resolve a url(...) reference from a @font-face rule into the actual font bytes.