Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

vfbLib #70

Merged
merged 3 commits into from
Sep 16, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading