Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cut instances in the Noto recipe provider #1030

Draft
wants to merge 2 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions Lib/gftools/builder/operations/hbsubset.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
from functools import cached_property
import logging
import os
import shutil
Expand All @@ -10,9 +11,9 @@

class HbSubset(OperationBase):
description = "Run a subsetter to slim down a font"
rule = "$subsetter --output-file=$in.subset --notdef-outline --unicodes=* --name-IDs=* --layout-features=* --glyph-names $args $in && mv $in.subset $out"
rule = "$subsetter --output-file=$out --notdef-outline --unicodes=* --name-IDs=* --layout-features=* --glyph-names $args $in"

@property
@cached_property
def subsetter(self):
subsetter = self.original.get(
"subsetter", os.environ.get(SUBSETTER_ENV_KEY, "auto")
Expand Down
36 changes: 36 additions & 0 deletions Lib/gftools/builder/recipeproviders/noto.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import copy
import os
from pathlib import Path
import sys
from collections import defaultdict

Expand Down Expand Up @@ -210,6 +211,41 @@ def build_STAT(self):
self.recipe[last_target].append(build_stat_step)

def build_a_static(self, source, instance, output):
axis_map = {a.name: a.tag for a in source.designspace.axes}
if (
output == "otf" or not self.has_variables
): # No choice but to instantiate the UFO
return self.build_a_static_from_ufo(source, instance, output)
relevant_variable_recipe = {
k: v
for k, v in self.recipe.items()
if v[0]["source"] == source.path and "/variable-ttf" in k
}
if not relevant_variable_recipe:
return self.build_a_static_from_ufo(source, instance, output)
for variable_name, recipe in relevant_variable_recipe.items():
instancebase = Path(instance.filename).stem + ".ttf"
static_name = str(
Path(variable_name.replace("variable-ttf", "ttf")).parent / instancebase
)

args = "--retain-gids --name-legacy --passthrough-tables "
if "unhinted" in static_name:
args += "--no-hinting"
loc = ",".join(
f"{axis_map[k]}={v}" for k, v in instance.designLocation.items()
)
args += f' --instance="{loc}"'
recipe = copy.deepcopy(recipe)
while "postprocess" in recipe[-1]:
recipe.pop()
recipe += [{"operation": "hbsubset", "args": args}]
if "googlefonts" in static_name:
recipe.append({"operation": "fix", "args": "--include-source-fixes"})

self.recipe[static_name] = recipe

def build_a_static_from_ufo(self, source, instance, output):
familyname_path = source.family_name.replace(" ", "")

# Unhinted static
Expand Down
Loading