def decompress(input_file, output_file): """Decompress WOFF2 font to OpenType font. Args: input_file: a file path, file or file-like object (open in binary mode) containing a compressed WOFF2 font. output_file: a file path, file or file-like object where to save the decompressed OpenType font. """ log.info("Processing %s => %s" % (input_file, output_file)) font = TTFont(input_file, recalcBBoxes=False, recalcTimestamp=False) font.flavor = None font.flavorData = None font.save(output_file, reorderTables=True)
def compress(input_file, output_file, transform_tables=None): """Compress OpenType font to WOFF2. Args: input_file: a file path, file or file-like object (open in binary mode) containing an OpenType font (either CFF- or TrueType-flavored). output_file: a file path, file or file-like object where to save the compressed WOFF2 font. transform_tables: Optional[Iterable[str]]: a set of table tags for which to enable preprocessing transformations. By default, only 'glyf' and 'loca' tables are transformed. An empty set means disable all transformations. """ log.info("Processing %s => %s" % (input_file, output_file)) font = TTFont(input_file, recalcBBoxes=False, recalcTimestamp=False) font.flavor = "woff2" if transform_tables is not None: font.flavorData = WOFF2FlavorData( data=font.flavorData, transformedTables=transform_tables ) font.save(output_file, reorderTables=False)