Skip to content

Commit

Permalink
Make it easier to build variant families (#1055)
Browse files Browse the repository at this point in the history
* Add the postCompile and filenameSuffix options

* Docs for the new options
  • Loading branch information
simoncozens authored Nov 1, 2024
1 parent d40eb15 commit 9e060b9
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 10 deletions.
31 changes: 21 additions & 10 deletions Lib/gftools/builder/recipeproviders/googlefonts.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down Expand Up @@ -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},
Expand All @@ -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()
Expand Down
2 changes: 2 additions & 0 deletions Lib/gftools/builder/schema.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()),
Expand Down
4 changes: 4 additions & 0 deletions docs/gftools-builder/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down

0 comments on commit 9e060b9

Please sign in to comment.