Skip to content

Commit

Permalink
Merge pull request #70 from jenskutilek/vfb3ufo
Browse files Browse the repository at this point in the history
vfbLib
  • Loading branch information
benkiel authored Sep 16, 2024
2 parents 8f2a9e0 + fc7284e commit 1289b9d
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 11 deletions.
40 changes: 30 additions & 10 deletions Lib/extractor/formats/vfb.py
Original file line number Diff line number Diff line change
@@ -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


# ----------------
Expand All @@ -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:
Expand Down
8 changes: 7 additions & 1 deletion README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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
------------
Expand All @@ -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 <https://travis-ci.org/typesupply/extractor>`__ under the name
``ufo-extractor``, to disambiguate it from another package also called "extractor".
Expand Down
3 changes: 3 additions & 0 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down

0 comments on commit 1289b9d

Please sign in to comment.