Skip to content

Commit

Permalink
chore: allow building variants
Browse files Browse the repository at this point in the history
  • Loading branch information
mishamyrt committed Sep 25, 2024
1 parent e899676 commit 6ee16a8
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 8 deletions.
18 changes: 14 additions & 4 deletions scripts/builder/font.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
"""Glyphs helper"""
from __future__ import annotations

from pathlib import Path
from shutil import rmtree
from tempfile import mkdtemp
from typing import Callable
Expand All @@ -24,10 +25,15 @@ class GlyphsFont:
"""Glyphs font builder"""
_font: GSFont = None
_path: str
_name: str

def __init__(self, path: str):
def __init__(self, path: str, name: str = None):
self._font = GSFont(path)
self._path = path
if name is None:
self._name = Path(self._path).stem
else:
self._name = name

@property
def file(self) -> GSFont:
Expand Down Expand Up @@ -91,7 +97,7 @@ def build(self, formats: list[str], out_dir: str, store_temp=False) -> bool:
print(f'Unsupported format "{fmt}"')
break
fmt_dir = f'{out_dir}/{fmt}'
success = success and make(self.file.familyName, ds_file, fmt, fmt_dir)
success = success and make(self._name, ds_file, fmt, fmt_dir)
if store_temp:
print(f'Build directory: {temp_dir}')
else:
Expand All @@ -112,7 +118,11 @@ def _prepare_build(self) -> str:
temp_dir = mkdtemp(prefix="LilexBuild")
glyphs_file = f'{temp_dir}/{self._font.familyName}.glyphs'
ufo_dir = f'{temp_dir}/master_ufo'
ds_file = f"{ufo_dir}/{self._font.familyName}.designspace"
ds_file = f"{ufo_dir}/{self._name}.designspace"
self.save_to(glyphs_file)
build_masters(glyphs_file, ufo_dir, write_skipexportglyphs=True)
build_masters(
glyphs_file,
ufo_dir,
write_skipexportglyphs=True
)
return (temp_dir, ds_file)
7 changes: 5 additions & 2 deletions scripts/builder/make.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@
STAT_CONFIG = 'sources/STAT.yaml'
VARIABLE_SUFFIX = '[wght]'

def _format_variable_path(font_dir: str, family_name: str) -> str:
return f"{font_dir}/{family_name}{VARIABLE_SUFFIX}.ttf"

def _run(*args: str) -> bool:
with sp.Popen(" ".join(args), shell=True, stdout=sp.PIPE) as child:
child.communicate()
Expand All @@ -28,7 +31,7 @@ def _gftools(subcommand: str, *args: str) -> bool:

def _fix_variable(font_dir, family_name) -> bool:
"""Generate STAT table for variable ttf"""
file_path = f'{font_dir}/{family_name}{VARIABLE_SUFFIX}.ttf'
file_path = _format_variable_path(font_dir, family_name)
return _gftools(
"fix-font",
"--include-source-fixes",
Expand Down Expand Up @@ -73,7 +76,7 @@ def make(family_name: str, ds_path: str, fmt: str, out_dir: str) -> bool:
"--filter DecomposeTransformedComponentsFilter"
]
if fmt == "variable":
cmd.append(f'--output-path "{out_dir}/{family_name}{VARIABLE_SUFFIX}.ttf"')
cmd.append(f'--output-path "{_format_variable_path(out_dir, family_name)}"')
else:
cmd.append("--interpolate")
cmd.append(f'--output-dir "{out_dir}"')
Expand Down
10 changes: 8 additions & 2 deletions scripts/lilex.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,10 @@

global_args(
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")
arg("--features", "-f", help=(
"A list of features that will be \"baked\" into the font. Comma separated, no spaces."
" Or you can pass \"ignore\" to use file's prebuilt features")
)
)

@command(
Expand Down Expand Up @@ -84,6 +86,10 @@ def move_to_calt(font: GSFont, features: list[str]):
def create_font(args):
font = GlyphsFont(args.input)

if args.features == "ignore":
print("Using prebuilt features")
return args, font

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

Expand Down

0 comments on commit 6ee16a8

Please sign in to comment.