Skip to main content

Python library for manipulating OpenType font features

Project description

FEE — Font Engineering with Extensibility

The Font Engineering with Extensibility (FEE) language is implemented via a Python library, fontFeatures. This format improves over Adobe FEA (.fea) in several important ways, and compiles to FEA. In future, FEE also will compile to raw GPOS/GSUB binary tables.

FEE Quickstart

Class definition is a time consuming element of writing FEA code. FEE allows regular expressions to be used to define classes; each glyph name in the font is tested against the regular expression, and the glyphs added:

DefineClass @sc = /\.sc$/;

Ran as:

fee2fea tests/LibertinusSans-Regular.otf test.fee

Results in:

@sc = [parenleft.sc parenright.sc bracketleft.sc bracketright.sc ...];

Simple replacement can be done as easily as:

DefineClass @sc = /\.sc$/;
DefineClass @sc_able = @sc~sc;

Feature smcp {
	Substitute @sc_able -> @sc;
};

Quite complex classes can be built. All the glyphs which have a smallcap and alternate form:

DefineClass @sc_and_alt_able = /.*/ and hasglyph(/$/ .alt) and hasglyph(/$/ .sc);

Returning:

@sc_and_alt_able = [h y germandbls];

FEE can even do substitutions impossible in FEA. For example:

DefineClass @digits =    U+0031=>U+0039; # this is range(U+0031, U+0039) inclusive
DefineClass @encircled = U+2474=>U+247C;

# Un-CJK parenthesize
Feature ss01 {
	Substitute @encircled -> parenleft @digits parenright;
};

Gives us:

feature ss01 {
    lookup Routine_1 {
            sub uni2474 by parenleft one parenright;
            sub uni2475 by parenleft two parenright;
            sub uni2476 by parenleft three parenright;
            sub uni2477 by parenleft four parenright;
            sub uni2478 by parenleft five parenright;
            sub uni2479 by parenleft six parenright;
            sub uni247A by parenleft seven parenright;
            sub uni247B by parenleft eight parenright;
            sub uni247C by parenleft nine parenright;
    } Routine_1;
} ss01;

FEE can do much more; see the plugins documentation. Writing your own plugins is as simple as defining its grammar, verb, and adding a class with an action() method.

fontFeatures library

OpenType fonts are "programmed" using features, which are normally authored in Adobe's feature file format. This like source code to a computer program: it's a user-friendly, but computer-unfriendly, way to represent the features.

Inside a font, the features are compiled in an efficient internal format. This is like the binary of a computer program: computers can use it, but they can't do else anything with it, and people can't read it.

The purpose of this library is to provide a middle ground for representing features in a machine-manipulable format, kind of like the abstract syntax tree of a computer programmer. This is so that:

  • features can be represented in a structured human-readable and machine-readable way, analogous to the XML files of the Unified Font Object format.
  • features can be more directly authored by programs (such as font editors), rather than them having to output AFDKO feature file format.
  • features can be easily manipulated by programs - for example, features from two files merged together, or lookups moved between languages.

How is this different from fontTool's feaLib? I'm glad you asked. feaLib translates between the Adobe feature file format and a abstract syntax tree representing elements of the feature file - not representing the feature data. The AST is still "source equivalent". For example, when you code an aalt feature in feature file format, you might include code like feature salt to include lookups from another feature. But what's actually meant by that is a set of lookups. fontFeatures allows you to manipulate meaning, not description.

Components

fontFeatures consists of the following components:

  • fontFeatures itself, which is an abstract representation of the different layout operations inside a font.
  • fontFeatures.feaLib (included as a mixin) which translates between Adobe feature syntax and fontFeatures representation.
  • fontFeatures.ttLib, which translates between OpenType binary fonts and fontFeatures representation. (Currently only OTF -> fontFeatures is partially implemented; there is no fontFeatures -> OTF compiler yet.)
  • fontFeatures.feeLib which parses a new, extensible format called FEE for font engineering.
  • fontFeatures.fontDameLib which translate FontDame text files into fontFeatures objects.

And the following utilities:

  • fee2fea: translates a FEE file into Adobe feature syntax.
  • otf2fea: translates an OTF file into Adobe features syntax.
  • txt2fea: translates a FontDame txt file into Adobe features syntax.
  • mergeFee: takes an existing font, adds FEE rules to it, and writes it out again.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

fontFeatures-1.0.4.tar.gz (84.8 kB view details)

Uploaded Source

Built Distribution

fontFeatures-1.0.4-py3-none-any.whl (110.0 kB view details)

Uploaded Python 3

File details

Details for the file fontFeatures-1.0.4.tar.gz.

File metadata

  • Download URL: fontFeatures-1.0.4.tar.gz
  • Upload date:
  • Size: 84.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.14.0 pkginfo/1.6.0 requests/2.24.0 setuptools/50.3.0 requests-toolbelt/0.9.1 tqdm/4.50.2 CPython/3.8.6

File hashes

Hashes for fontFeatures-1.0.4.tar.gz
Algorithm Hash digest
SHA256 18a969d4acd30a3c02389973677468d45ec2c58d10009b3e6c3818706bd081c2
MD5 638b3f48365f66688234d61441eec0df
BLAKE2b-256 552191fad5af5d9d4e6d2e53cbc5009aed5ca0c70b0b7e8c0c3a9a9b0ae7d937

See more details on using hashes here.

File details

Details for the file fontFeatures-1.0.4-py3-none-any.whl.

File metadata

  • Download URL: fontFeatures-1.0.4-py3-none-any.whl
  • Upload date:
  • Size: 110.0 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.14.0 pkginfo/1.6.0 requests/2.24.0 setuptools/50.3.0 requests-toolbelt/0.9.1 tqdm/4.50.2 CPython/3.8.6

File hashes

Hashes for fontFeatures-1.0.4-py3-none-any.whl
Algorithm Hash digest
SHA256 1f066cb5f94e0c4c7167c4ffcdb17e51c1c73fcf65828fedc0771fcad8a168c7
MD5 5b6febc6bb5bffd357847e8c47b08402
BLAKE2b-256 8003ec90b021a8ec4f6f4aae50808a3f396f48f9cceaa10c8653ded0f7b34397

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page