Working with WOFF and WOFF2 Fonts
Working with WOFF and WOFF2 Fonts
This guide shows how to load WOFF and WOFF2 web fonts and convert them to other formats such as TTF for desktop use or further processing.
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
FontLoader.open() decompresses WOFF and WOFF2 containers automatically and returns a standard Font object with the same metadata and glyph access as any other format.
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
FontConverter.convert(font, target) produces a new font object in the target format. Converting WOFF2 to TTF extracts the uncompressed TrueType data for editing or re-packaging.
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;
FontLoaderdecompresses 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 / Method | Description |
|---|---|
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 |