Skip to content

Commit 1289b9d

Browse files
authored
Merge pull request #70 from jenskutilek/vfb3ufo
vfbLib
2 parents 8f2a9e0 + fc7284e commit 1289b9d

File tree

3 files changed

+40
-11
lines changed

3 files changed

+40
-11
lines changed

Lib/extractor/formats/vfb.py

Lines changed: 30 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,20 @@
11
import os
22
import shutil
33
import tempfile
4-
import subprocess
54

65
from fontTools.ufoLib import UFOReader
76

8-
_ufo2vfbLocation = "/usr/local/bin/vfb2ufo"
7+
try:
8+
from vfbLib.vfb.vfb import Vfb
9+
from vfbLib.ufo.builder import VfbToUfoBuilder
10+
11+
haveVfbLib = True
12+
except ImportError:
13+
haveVfbLib = False
914

1015

1116
def haveVfb2ufo():
12-
return os.path.exists(_ufo2vfbLocation)
17+
return haveVfbLib
1318

1419

1520
# ----------------
@@ -36,15 +41,30 @@ def extractFontFromVFB(
3641
doLib=True,
3742
customFunctions=[],
3843
):
44+
extract_minimal = True
45+
vfb = Vfb(
46+
pathOrFile,
47+
minimal=extract_minimal,
48+
drop_keys=("Encoding", "Encoding Mac"),
49+
unicode_strings=True,
50+
)
51+
vfb.decompile()
52+
builder = VfbToUfoBuilder(
53+
vfb,
54+
minimal=extract_minimal,
55+
base64=True,
56+
pshints=False,
57+
add_kerning_groups=False,
58+
)
59+
masters = builder.get_ufo_masters(silent=True)
60+
ufoLib_source = masters[0]
3961
ufoPath = tempfile.mkdtemp(suffix=".ufo")
40-
cmds = [_ufo2vfbLocation, "-64", "-fo", pathOrFile, ufoPath]
41-
cmds = subprocess.list2cmdline(cmds)
42-
popen = subprocess.Popen(cmds, shell=True)
43-
popen.wait()
62+
ufoLib_source.save(ufoPath, overwrite=True)
4463
try:
45-
# vfb2ufo writes ufo2, and has no update since 2015...so dont get to crazy here...
46-
# dont validate as vfb2ufo writes invalid ufos
47-
source = UFOReader(ufoPath, validate=False)
64+
# We now use vfbLib instead of vfb2ufo, which wrote ufo2, and had no update
65+
# since 2015, so the extracted UFOs were pretty basic.
66+
# More data could be extracted now with vfbLib if needed.
67+
source = UFOReader(ufoPath, validate=True)
4868
if doInfo:
4969
source.readInfo(destination.info)
5070
if doKerning:

README.rst

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ Supported input formats:
2727
(``*.ttx``)
2828
- WOFF 1.0/2.0 (``*.woff``, ``*.woff2``)
2929
- PostScript Type1 fonts (``*.pfa``, ``*.pfb``, etc.)
30-
- FontLab files (``*.vfb``)
30+
- FontLab files (``*.vfb``, when installed with optional dependency "vfb")
3131

3232
Installation
3333
------------
@@ -38,6 +38,12 @@ You can install ``extractor`` with ``pip``:
3838
3939
$ pip install ufo-extractor
4040
41+
To install with support for extracting from vfb files:
42+
43+
.. code::
44+
45+
$ pip install ufo-extractor[vfb]
46+
4147
Note that, for historical reasons, the package is listed on the
4248
`Python Package Index <https://travis-ci.org/typesupply/extractor>`__ under the name
4349
``ufo-extractor``, to disambiguate it from another package also called "extractor".

setup.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,9 @@
3737
"fonttools[ufo,lxml,woff,unicode,type1]>=4.17.0",
3838
"fontFeatures",
3939
],
40+
extras_require={
41+
"vfb": ["vfbLib>=0.7.1"],
42+
},
4043
classifiers=[
4144
"Development Status :: 4 - Beta",
4245
"Environment :: Console",

0 commit comments

Comments
 (0)