From 3aac7bddaf3846c836ca36d9f32453ed61cccde6 Mon Sep 17 00:00:00 2001 From: Jens Kutilek Date: Mon, 16 Sep 2024 13:16:46 +0200 Subject: [PATCH 1/3] Replace vfb2ufo by vfbLib --- Lib/extractor/formats/vfb.py | 40 +++++++++++++++++++++++++++--------- 1 file changed, 30 insertions(+), 10 deletions(-) diff --git a/Lib/extractor/formats/vfb.py b/Lib/extractor/formats/vfb.py index 8d74140..9c0239c 100644 --- a/Lib/extractor/formats/vfb.py +++ b/Lib/extractor/formats/vfb.py @@ -1,15 +1,20 @@ import os import shutil import tempfile -import subprocess from fontTools.ufoLib import UFOReader -_ufo2vfbLocation = "/usr/local/bin/vfb2ufo" +try: + from vfbLib.vfb.vfb import Vfb + from vfbLib.ufo.builder import VfbToUfoBuilder + + haveVfbLib = True +except ImportError: + haveVfbLib = False def haveVfb2ufo(): - return os.path.exists(_ufo2vfbLocation) + return haveVfbLib # ---------------- @@ -36,15 +41,30 @@ def extractFontFromVFB( doLib=True, customFunctions=[], ): + extract_minimal = True + vfb = Vfb( + pathOrFile, + minimal=extract_minimal, + drop_keys=("Encoding", "Encoding Mac"), + unicode_strings=True, + ) + vfb.decompile() + builder = VfbToUfoBuilder( + vfb, + minimal=extract_minimal, + base64=True, + pshints=False, + add_kerning_groups=False, + ) + masters = builder.get_ufo_masters(silent=True) + ufoLib_source = masters[0] ufoPath = tempfile.mkdtemp(suffix=".ufo") - cmds = [_ufo2vfbLocation, "-64", "-fo", pathOrFile, ufoPath] - cmds = subprocess.list2cmdline(cmds) - popen = subprocess.Popen(cmds, shell=True) - popen.wait() + ufoLib_source.save(ufoPath, overwrite=True) try: - # vfb2ufo writes ufo2, and has no update since 2015...so dont get to crazy here... - # dont validate as vfb2ufo writes invalid ufos - source = UFOReader(ufoPath, validate=False) + # We now use vfbLib instead of vfb2ufo, which wrote ufo2, and had no update + # since 2015, so the extracted UFOs were pretty basic. + # More data could be extracted now with vfbLib if needed. + source = UFOReader(ufoPath, validate=True) if doInfo: source.readInfo(destination.info) if doKerning: From 605128306c4add038c93574696988a8cfde383e7 Mon Sep 17 00:00:00 2001 From: Jens Kutilek Date: Mon, 16 Sep 2024 13:21:36 +0200 Subject: [PATCH 2/3] Add vfbLib as optional dependency --- setup.py | 3 +++ 1 file changed, 3 insertions(+) diff --git a/setup.py b/setup.py index 28313cc..ed49a8f 100755 --- a/setup.py +++ b/setup.py @@ -37,6 +37,9 @@ "fonttools[ufo,lxml,woff,unicode,type1]>=4.17.0", "fontFeatures", ], + extras_require={ + "vfb": ["vfbLib>=0.7.1"], + }, classifiers=[ "Development Status :: 4 - Beta", "Environment :: Console", From fc7284e6c18351e3b125dc42dbfdff3ab60697b1 Mon Sep 17 00:00:00 2001 From: Jens Kutilek Date: Mon, 16 Sep 2024 13:25:10 +0200 Subject: [PATCH 3/3] Amend Readme --- README.rst | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/README.rst b/README.rst index f9bb9b9..4429389 100644 --- a/README.rst +++ b/README.rst @@ -27,7 +27,7 @@ Supported input formats: (``*.ttx``) - WOFF 1.0/2.0 (``*.woff``, ``*.woff2``) - PostScript Type1 fonts (``*.pfa``, ``*.pfb``, etc.) -- FontLab files (``*.vfb``) +- FontLab files (``*.vfb``, when installed with optional dependency "vfb") Installation ------------ @@ -38,6 +38,12 @@ You can install ``extractor`` with ``pip``: $ pip install ufo-extractor +To install with support for extracting from vfb files: + +.. code:: + + $ pip install ufo-extractor[vfb] + Note that, for historical reasons, the package is listed on the `Python Package Index `__ under the name ``ufo-extractor``, to disambiguate it from another package also called "extractor".