From 9e060b9d1743210f96f329c332f4fd67067dfaa1 Mon Sep 17 00:00:00 2001 From: Simon Cozens Date: Fri, 1 Nov 2024 12:46:27 +0000 Subject: [PATCH] Make it easier to build variant families (#1055) * Add the postCompile and filenameSuffix options * Docs for the new options --- .../builder/recipeproviders/googlefonts.py | 31 +++++++++++++------ Lib/gftools/builder/schema.py | 2 ++ docs/gftools-builder/README.md | 4 +++ 3 files changed, 27 insertions(+), 10 deletions(-) diff --git a/Lib/gftools/builder/recipeproviders/googlefonts.py b/Lib/gftools/builder/recipeproviders/googlefonts.py index 4ab8a4961..b18781ebf 100644 --- a/Lib/gftools/builder/recipeproviders/googlefonts.py +++ b/Lib/gftools/builder/recipeproviders/googlefonts.py @@ -280,17 +280,26 @@ def _vtt_steps(self, target: str): def build_a_variable( self, source: File, italic_ds: Italic = None, roman: bool = False ): + suffix = self.config.get("filenameSuffix", "") if roman: - target = self._vf_filename(source, italic_ds=italic_ds, roman=True) + target = self._vf_filename( + source, suffix=suffix, italic_ds=italic_ds, roman=True + ) else: - target = self._vf_filename(source, italic_ds=italic_ds, roman=False) - steps = [ - {"source": source.path}, - { - "operation": "buildVariable", - "args": self.fontmake_args(source, variable=True), - }, - ] + self._vtt_steps(target) + target = self._vf_filename( + source, suffix=suffix, italic_ds=italic_ds, roman=False + ) + steps = ( + [ + {"source": source.path}, + { + "operation": "buildVariable", + "args": self.fontmake_args(source, variable=True), + }, + ] + + self.config.get("postCompile", []) + + self._vtt_steps(target) + ) if italic_ds: desired_slice = italic_ds[0] + "=" if roman: @@ -322,7 +331,8 @@ def build_all_statics(self): self.build_a_static(source, instance, output="otf") def build_a_static(self, source: File, instance: InstanceDescriptor, output): - target = self._static_filename(instance, extension=output) + suffix = self.config.get("filenameSuffix", "") + target = self._static_filename(instance, suffix=suffix, extension=output) steps = [ {"source": source.path}, @@ -349,6 +359,7 @@ def build_a_static(self, source: File, instance: InstanceDescriptor, output): "args": self.fontmake_args(source, variable=False), } ] + + self.config.get("postCompile", []) + self._autohint_steps(target) + self._vtt_steps(target) + self._fix_step() diff --git a/Lib/gftools/builder/schema.py b/Lib/gftools/builder/schema.py index 1487f1019..fd8e41e52 100644 --- a/Lib/gftools/builder/schema.py +++ b/Lib/gftools/builder/schema.py @@ -66,6 +66,8 @@ GOOGLEFONTS_SCHEMA = Map( { Optional("recipe"): MapPattern(Str(), Seq(Any())), + Optional("postCompile"): Seq(Any()), + Optional("filenameSuffix"): Str(), Optional("recipeProvider"): Str(), "sources": Seq(Str()), Optional("vttSources"): MapPattern(Str(), Str()), diff --git a/docs/gftools-builder/README.md b/docs/gftools-builder/README.md index 7f86cb2a5..84c729f81 100644 --- a/docs/gftools-builder/README.md +++ b/docs/gftools-builder/README.md @@ -206,6 +206,10 @@ The build can be customized by adding the following keys to the YAML file: - `localMetadata`: A field that's ignored so you can put whatever you like in it. +- `filenameSuffix`: A suffix appended to the family name part of filenames. + +- `postCompile`: A list of operations to be run after the font compilation step; you can use this (together with the above option) to build variant fonts, rename families, bake in stylistic sets, etc. + ## *Really* customizing the build process