X-Git-Url: https://git.mdrn.pl/librarian.git/blobdiff_plain/db91f942ce46e3af1420f3469a83257ef5aca4c2..23d025c8875cca1404f274aca7170c9db5e980e7:/src/librarian/fonts.py?ds=inline diff --git a/src/librarian/fonts.py b/src/librarian/fonts.py index adaeae4..0f99bf4 100644 --- a/src/librarian/fonts.py +++ b/src/librarian/fonts.py @@ -1,38 +1,21 @@ +# This file is part of Librarian, licensed under GNU Affero GPLv3 or later. +# Copyright © Fundacja Wolne Lektury. See NOTICE for more information. +# import os from shutil import rmtree -import subprocess from tempfile import mkdtemp +from fontTools.subset import main -def strip_font(path, chars, verbose=False): +def strip_font(path, chars): tmpdir = mkdtemp('-librarian-epub') - try: - cwd = os.getcwd() - except OSError: - cwd = None - - os.chdir(os.path.join(os.path.dirname(os.path.realpath(__file__)), - 'font-optimizer')) - optimizer_call = [ - 'perl', 'subset.pl', '--chars', - ''.join(chars).encode('utf-8'), + main([ path, - os.path.join(tmpdir, 'font.ttf') - ] - env = {"PERL_USE_UNSAFE_INC": "1"} - if verbose: - print("Running font-optimizer") - subprocess.check_call(optimizer_call, env=env) - else: - dev_null = open(os.devnull, 'w') - subprocess.check_call(optimizer_call, stdout=dev_null, - stderr=dev_null, env=env) + '--text=' + ''.join(chars), + '--output-file=' + os.path.join(tmpdir, 'font.ttf') + ]) with open(os.path.join(tmpdir, 'font.ttf'), 'rb') as f: content = f.read() rmtree(tmpdir) - - if cwd is not None: - os.chdir(cwd) - return content