From c4bc38057710b6cdee19fd07ae04736fd4fdac76 Mon Sep 17 00:00:00 2001 From: mishamyrt Date: Fri, 31 Mar 2023 10:59:16 +0300 Subject: [PATCH] Add forced feature activation to the builder --- CHANGELOG.md | 3 ++- README.md | 22 ++++++++++++++++++++++ scripts/lilex.py | 40 +++++++++++++++++++++++++++++++--------- 3 files changed, 55 insertions(+), 10 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 7587c9b7..a58d6324 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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 diff --git a/README.md b/README.md index c94d29c0..d608b348 100644 --- a/README.md +++ b/README.md @@ -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 diff --git a/scripts/lilex.py b/scripts/lilex.py index 49124a74..8afa761c 100755 --- a/scripts/lilex.py +++ b/scripts/lilex.py @@ -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" @@ -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( @@ -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)