Working with WOFF and WOFF2 Fonts

Working with WOFF and WOFF2 Fonts

Working with WOFF and WOFF2 Fonts

WOFF and WOFF2 are compressed web font containers. FontLoader handles both formats transparently — the format is auto-detected from the binary magic bytes.


Loading WOFF / WOFF2

from aspose_font.loader import FontLoader

woff  = FontLoader.open("MyFont.woff")
woff2 = FontLoader.open("MyFont.woff2")

print(woff.font_family, woff.num_glyphs)

Converting WOFF2 to TTF

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

woff2 = FontLoader.open("MyFont.woff2")
ttf = FontConverter.convert(woff2, target_format="ttf")

Tips and Best Practices

  • WOFF2 uses Brotli compression; FontLoader decompresses automatically
  • After converting WOFF2 to TTF, apply FontCleaner.clean_for_web() before re-packaging
  • Use FontSubsetter.subset_for_web() before packaging as WOFF2 for web delivery

API Reference Summary

Class / MethodDescription
FontLoader.open(path)Load WOFF or WOFF2 from file path
FontLoader.load(data)Load WOFF or WOFF2 from raw bytes
FontConverter.convert(font, target_format)Convert to another format