11import os
22import shutil
33import tempfile
4- import subprocess
54
65from 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
1116def 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 :
0 commit comments