[Snippets] add woff_compress.py and woff2_decompress.py sample scripts
This commit is contained in:
parent
0d21b67162
commit
2591a1075d
27
Snippets/woff2_compress.py
Normal file
27
Snippets/woff2_compress.py
Normal file
@ -0,0 +1,27 @@
|
|||||||
|
#!/usr/bin/env python
|
||||||
|
from __future__ import print_function
|
||||||
|
import sys
|
||||||
|
import os
|
||||||
|
from fontTools.ttLib import TTFont
|
||||||
|
from fontTools.ttx import makeOutputFileName
|
||||||
|
|
||||||
|
|
||||||
|
def main(args=None):
|
||||||
|
if args is None:
|
||||||
|
args = sys.argv[1:]
|
||||||
|
if len(args) < 1:
|
||||||
|
print("One argument, the input filename, must be provided.", file=sys.stderr)
|
||||||
|
sys.exit(1)
|
||||||
|
|
||||||
|
filename = args[0]
|
||||||
|
outfilename = makeOutputFileName(filename, outputDir=None, extension='.woff2')
|
||||||
|
|
||||||
|
print("Processing %s => %s" % (filename, outfilename))
|
||||||
|
|
||||||
|
font = TTFont(filename, recalcBBoxes=False, recalcTimestamp=False)
|
||||||
|
font.flavor = "woff2"
|
||||||
|
font.save(outfilename, reorderTables=False)
|
||||||
|
|
||||||
|
|
||||||
|
if __name__ == '__main__':
|
||||||
|
main()
|
37
Snippets/woff2_decompress.py
Normal file
37
Snippets/woff2_decompress.py
Normal file
@ -0,0 +1,37 @@
|
|||||||
|
#!/usr/bin/env python
|
||||||
|
from __future__ import print_function
|
||||||
|
import sys
|
||||||
|
import os
|
||||||
|
from fontTools.ttLib import TTFont
|
||||||
|
from fontTools.ttx import makeOutputFileName
|
||||||
|
|
||||||
|
|
||||||
|
def make_output_name(filename):
|
||||||
|
with open(filename, "rb") as f:
|
||||||
|
f.seek(4)
|
||||||
|
sfntVersion = f.read(4)
|
||||||
|
assert len(sfntVersion) == 4, "not enough data"
|
||||||
|
ext = '.ttf' if sfntVersion == b"\x00\x01\x00\x00" else ".otf"
|
||||||
|
outfilename = makeOutputFileName(filename, outputDir=None, extension=ext)
|
||||||
|
return outfilename
|
||||||
|
|
||||||
|
|
||||||
|
def main(args=None):
|
||||||
|
if args is None:
|
||||||
|
args = sys.argv[1:]
|
||||||
|
if len(args) < 1:
|
||||||
|
print("One argument, the input filename, must be provided.", file=sys.stderr)
|
||||||
|
sys.exit(1)
|
||||||
|
|
||||||
|
filename = args[0]
|
||||||
|
outfilename = make_output_name(filename)
|
||||||
|
|
||||||
|
print("Processing %s => %s" % (filename, outfilename))
|
||||||
|
|
||||||
|
font = TTFont(filename, recalcBBoxes=False, recalcTimestamp=False)
|
||||||
|
font.flavor = None
|
||||||
|
font.save(outfilename, reorderTables=True)
|
||||||
|
|
||||||
|
|
||||||
|
if __name__ == '__main__':
|
||||||
|
main()
|
Loading…
x
Reference in New Issue
Block a user