Drop lots of legacy code. Support Python 3.7-3.11.
[librarian.git] / src / librarian / fonts.py
1 # This file is part of Librarian, licensed under GNU Affero GPLv3 or later.
2 # Copyright © Fundacja Wolne Lektury. See NOTICE for more information.
3 #
4 import os
5 from shutil import rmtree
6 from tempfile import mkdtemp
7 from fontTools.subset import main
8
9
10 def strip_font(path, chars):
11     tmpdir = mkdtemp('-librarian-epub')
12     main([
13         path,
14        '--text=' + ''.join(chars),
15        '--output-file=' + os.path.join(tmpdir, 'font.ttf')
16     ])
17     with open(os.path.join(tmpdir, 'font.ttf'), 'rb') as f:
18         content = f.read()
19
20     rmtree(tmpdir)
21     return content