Brotli Compression Support

Brotli Compression Support

Brotli Compression Support

WOFF2 fonts use Brotli compression for the glyph table data. Aspose.Font FOSS for Python includes a bundled pure-Python Brotli implementation so no system-level brotli library is required.


Loading WOFF2 (Automatic Brotli Decompression)

FontLoader decompresses WOFF2 Brotli data automatically.

from aspose_font.loader import FontLoader

font = FontLoader.open("MyFont.woff2")
print(font.font_name, font.num_glyphs)

Saving as WOFF2 (Automatic Brotli Compression)

FontConverter.convert() compresses the output automatically when the target format is woff2.

from aspose_font.loader import FontLoader
from aspose_font.converter import FontConverter

font = FontLoader.open("Roboto-Regular.ttf")
woff2 = FontConverter.convert(font, target_format="woff2")

Tips and Best Practices

  • The bundled Brotli implementation is pure Python; for performance-critical applications consider installing the brotli C extension separately
  • BrotliDecoder and BrotliEncoder are internal classes; do not import them directly in application code

API Reference Summary

Class / MethodDescription
BrotliDecoderInternal Brotli decompressor (used by FontLoader for WOFF2)
BrotliEncoderInternal Brotli compressor (used by FontConverter for WOFF2)
FontLoader.open(path)Load WOFF2 with automatic decompression
FontConverter.convert(font, "woff2")Save as WOFF2 with automatic compression