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

[builder] Intuit instance names better, fixes #966 #969

Merged
merged 1 commit into from
Jun 3, 2024
Merged
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
17 changes: 14 additions & 3 deletions Lib/gftools/builder/recipeproviders/googlefonts.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,10 @@
from tempfile import NamedTemporaryFile

import yaml
from fontTools.designspaceLib import DesignSpaceDocument, InstanceDescriptor
from strictyaml import load, YAMLValidationError

from gftools.builder.file import File
from gftools.builder.recipeproviders import RecipeProviderBase
from gftools.builder.schema import (
GOOGLEFONTS_SCHEMA,
Expand Down Expand Up @@ -122,7 +124,9 @@ def _vf_filename(self, source, suffix="", extension="ttf"):

return os.path.join(directory, f"{sourcebase}[{axis_tags}].{extension}")

def _static_filename(self, instance, suffix="", extension="ttf"):
def _static_filename(
self, instance: InstanceDescriptor, suffix: str = "", extension: str = "ttf"
):
"""Determine the file name for a static font."""
if extension == "ttf":
outdir = self.config["ttDir"]
Expand Down Expand Up @@ -256,17 +260,24 @@ def build_all_statics(self):
if self.config["buildOTF"]:
self.build_a_static(source, instance, output="otf")

def build_a_static(self, source, instance, output):
def build_a_static(self, source: File, instance: InstanceDescriptor, output):
target = self._static_filename(instance, extension=output)

steps = [
{"source": source.path},
]
if not source.is_ufo:
instancename = instance.name
if instancename is None:
if not instance.familyName or not instance.styleName:
raise ValueError(
f"Instance {instance.filename} must have a name, or familyName and styleName"
)
instancename = instance.familyName + " " + instance.styleName
steps.append(
{
"operation": "instantiateUfo",
"instance_name": instance.name,
"instance_name": instancename,
"glyphData": self.config.get("glyphData"),
}
)
Expand Down