FeaComposer is a wrapper around fontTools.feaLib.ast for programmatically composing code in the FEA format (officially the “OpenType feature file”).
API stability between minor versions is not guaranteed before version 2.
Users are expected to use the fontTools.feaLib.ast classes directly for functionalities that are not yet covered by the FeaComposer API.
The API is designed to be close to the FEA syntax for familiarity, but is tightened up to be more manageable for complicated projects. On the other hand, as an embedded domain-specific language (eDSL) it allows you to take full advantage of Python, especially static type checking.
For the following use cases, you will not benefit from this package:
- You just want to write FEA code directly.
- Read The (Unofficial) OpenType Cookbook if you’re a beginner, and the OpenType Feature File Specification if you need to learn more about the FEA format.
- You want to compose OpenType Layout (OTL) rules in Python code independently from the FEA format. You don’t need static type checking.
- Try fontFeatures, which allows you to work on the syntax tree of OTL rules rather than the FEA code. It still allows you to export FEA code if you want.
- You want some Python logic in FEA code. You don’t need the usual code editor experience for Python, or you care about how the FEA code is formatted.
- Try FeaPyFoFum, which provides a template language for embedding Python inside FEA code.
Install from PyPI:
pip install tptq.feacomposer
Compose FEA code in Python:
from tptq.feacomposer import FeaComposer
c = FeaComposer()
with c.Lookup(feature="liga"):
c.sub("f", "i", by="f_i")
print(c.asFeatureFile())
The printed FEA code:
languagesystem DFLT dflt;
feature liga {
lookup _1 {
lookupflag 0;
sub f i by f_i;
} _1;
} liga;
See test.py for more examples.