Skip to content

Commit

Permalink
Add forced feature activation to the builder
Browse files Browse the repository at this point in the history
  • Loading branch information
mishamyrt committed Mar 31, 2023
1 parent 7ea834e commit c4bc380
Show file tree
Hide file tree
Showing 3 changed files with 55 additions and 10 deletions.
3 changes: 2 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,12 @@ All notable changes to this project will be documented in this file.

## Fixed

* `04F8`, `042B` (ы, Ы) point order (In 400-700 the scaling was broken)
* `044B` (`ы`), `042B` (`Ы`) point order (In 400-700 the scaling was broken)

## Added

* Arrows (and Markdown tables). `<<-|->>`, `|--|--|--|`
* Forced feature activation in the builder

## [2.000] — March 28, 2023

Expand Down
22 changes: 22 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,28 @@ Now run the command to build it.
make build
```

or

```sh
./scripts/lilex.py build
```

### Forced feature activation

The builder gives you the ability to forcibly enable any font features. This works by moving their code to the calt. If ligatures work, the selected features will also work.

To do this, regenerate the source file with the features:

```sh
./scripts/lilex.py --features 'sups,zero' generate -o Lilex.custom.glyphs
```

And then build the binaries from the new source:

```sh
./scripts/lilex.py -i Lilex.custom.glyphs build
```

## Credits

- Author: Mikhael Khrustik
Expand Down
40 changes: 31 additions & 9 deletions scripts/lilex.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
#!/usr/bin/env python3
"""Lilex helper entrypoint"""
from arrrgs import arg, command, run, global_args
import sys
from typing import List

from arrrgs import arg, command, global_args, run
from builder import SUPPORTED_FORMATS, GlyphsFont
from generator import generate_spacers, render_ligatures
from glyphsLib import GSFeature
from glyphsLib import GSFeature, GSFont
from utils import read_classes, read_features, read_files

FONT_FILE = "Lilex.glyphs"
Expand All @@ -12,7 +15,9 @@
OUT_DIR = "./build"

global_args(
arg("--input", "-i", default=FONT_FILE, help="Input .glyphs file")
arg("--input", "-i", default=FONT_FILE, help="Input .glyphs file"),
arg("--features", "-f",
help="A list of features that will be \"baked\" into the font. Comma separated, no spaces")
)

@command(
Expand All @@ -36,20 +41,37 @@ def generate_calt(font: GlyphsFont) -> GSFeature:
code = render_ligatures(glyphs) + read_files(f"{FEATURES_DIR}/calt")
return GSFeature("calt", code)

def prepare(args):
def move_to_calt(font: GSFont, features: List[str]):
for fea in features:
if fea not in font.features:
print(f"Unknown feature: '{fea}'")
print(font.features)
sys.exit(1)
# Move the code of the feature to the calt,
# which is executed in most cases
feature = font.features[fea]
feature.disabled = True
font.features["calt"].code += "\n" + feature.code
# Remove feature from aalt
aalt = font.features["aalt"]
aalt.code = aalt.code.replace(f"feature {fea};\n", "")

def create_font(args):
font = GlyphsFont(args.input)

cls = read_classes(CLASSES_DIR)
fea = read_features(FEATURES_DIR)

print(generate_calt(font))
fea.append(generate_calt(font))

calt = generate_calt(font)
fea.append(calt)
generate_spacers(font.ligatures(), font.file.glyphs)

font.set_classes(cls)
font.set_features(fea)

if args.features is not None:
features = args.features.split(",")
move_to_calt(font.file, features)
return args, font

if __name__ == "__main__":
run(prepare=prepare)
run(prepare=create_font)

0 comments on commit c4bc380

Please sign in to comment.