-
Notifications
You must be signed in to change notification settings - Fork 43
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
similar to #470 but for featureWriters. Also useful for testing/debugging.
- Loading branch information
1 parent
357f920
commit 564b0b6
Showing
1 changed file
with
48 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
import argparse | ||
from io import StringIO | ||
import logging | ||
|
||
from fontTools.misc.cliTools import makeOutputFileName | ||
|
||
from ufo2ft.constants import FEATURE_WRITERS_KEY | ||
from ufo2ft.featureCompiler import FeatureCompiler | ||
from ufo2ft.featureWriters import loadFeatureWriterFromString, logger | ||
|
||
try: | ||
import ufoLib2 | ||
|
||
loader = ufoLib2.Font | ||
except ImportError: | ||
import defcon | ||
|
||
loader = defcon.Font | ||
|
||
logging.basicConfig(level=logging.INFO) | ||
|
||
parser = argparse.ArgumentParser(description="Apply feature writers to a UFO file") | ||
parser.add_argument("--output", "-o", metavar="OUTPUT", help="output file name") | ||
parser.add_argument("ufo", metavar="UFO", help="UFO file") | ||
parser.add_argument( | ||
"writers", | ||
metavar="WRITER", | ||
nargs="*", | ||
help="list of feature writers to enable", | ||
) | ||
|
||
args = parser.parse_args() | ||
if not args.output: | ||
args.output = makeOutputFileName(args.ufo) | ||
|
||
ufo = loader(args.ufo) | ||
writers = [loadFeatureWriterFromString(w) for w in args.writers] | ||
compiler = FeatureCompiler(ufo, featureWriters=writers or None) | ||
compiler.setupFeatures() | ||
buf = StringIO() | ||
compiler.writeFeatures(buf) | ||
ufo.features.text = buf.getvalue() | ||
|
||
if FEATURE_WRITERS_KEY in ufo.lib: | ||
del ufo.lib[FEATURE_WRITERS_KEY] | ||
|
||
logger.info("Written on %s" % args.output) | ||
ufo.save(args.output) |