Google Fonts

Build the fonts

🦕 Because of our commitment to Libre font culture, all Google Fonts projects must be built using a reproducible, libre toolchain. We do not onboard binaries exported from font editors. This chapter aims to guide designers in building their font binaries using open-source tools as per our production requirements. Everything related to font file settings is detailed in the Pre-production section of this guide, and for practicality, that information will not be repeated here.

If you read “you should follow the recommendation” or “respect the requirements” etc, please refer to the chapters labeled start and must→ in the Pre-production: Getting your fonts ready for GF section of this guide. You will have a better understanding of the following guidelines if you have read them first.

We recommend you install all the tools in a virtual environment, to avoid conflict between packages. Further information is detailed in the Tools and Dependencies section.

For the rest of this chapter, it would be better if you have basic knowledge of:
Background reading:
start Tools and Dependencies
must→ Pre-production: Getting your fonts ready for GF
must→ Production requirements

Table of contents

Fontmake

Fontmake is a tool to generate font binaries. Run fontmake --help to see all the options.

Fontmake makes use of a variety of Python libraries to build TTF fonts from UFO or Glyphs source files:

You don’t have to understand this very well to start working with the tools, but it can come in handy if you have a bug to report, or if you want to understand the relationship between the different libraries. See “What happens when you build a variable font (using the open source tool chain)” for more details.

gftools

Unfortunately, Fontmake is not enough to generate fonts that can be onboarded to Google Fonts. Some post-processing is needed to meet Google Fonts requirements. The gftools scripts are an enhanced collection of helpers to do that post-processing.

Run gftools --help to see the available scripts.

These scripts are extremely useful to batch patch binaries (as well as UFO).

gen-stat

You can use for example gftools gen-stat to easily patch a STAT table to your variable font:

gftools gen-stat path/to/*.ttf --src stat.yaml --inplace

--inplace would be to override the font files, --src would be to use an external yaml file with axis values instructions, for example:

# stat.yaml
- name: Width
  tag: wdth
  values:
  - name: Condensed
    value: 75
  - name: Normal
    value: 100
- name: Weight
  tag: wght
  values:
  - name: Regular
    value: 400
    linkedValue: 700
        flags: 2
  - name: Bold
    value: 700

If you need to patch a different STAT table on separated fonts of the same family—for example in the case of Italic—you can add file name information, such as:

# stat.yaml
Fontname[wght].ttf:
- name: Weight
  tag: wght
  values:
  - name: Regular
    value: 400
        flags: 2
- name: Italic
    tag: ital
    - name: Regular
        value: 0
    linkedValue: 1
        flags: 2
Fontname-Italic[wght].ttf:
- name: Weight
  tag: wght
  values:
  - name: Regular
    value: 400
- name: Italic
    tag: ital
    - name: Italic
        value: 1

The build script

Google Fonts has a policy of building all exports in one step to simplify the font generation process. To generate the font with Fontmake, and then post-process the binaries with some gftools scripts, users often created a bash shell script.

Example: Public Sans

As you can see in the example, these build scripts were extremely long and redundant. That is why gftools builder was created.

gftools builder

gftools builder is a command line tool that wraps Fontmake to efficiently generate several font formats in one command, as well as several gftools fix-* and gftools gen-stat scripts to post-process the generated fonts following Google Fonts’ specifications.

Run gftools builder --help to see all the options.

Usage from the CLI

The Builder can take source files (.glyphs, .ufo, .designspace) as direct argument.

You can do that if:

Example:

gftools builder FontName.glyphs FontName-italic.glyphs

This will generate Static OTF, TTF, WOFF2 and Variable TTF, using the Axis Registry to set up the STAT table.

Using a yaml file with more detailed instructions is a preferred option to have more control over the outcome. Once this “config” file is set up, you would just have to run, for example:

gftools builder config.yaml

Config file for simple font

For Example: JetBrains Mono

# config.yaml
sources:
    - FontName[axis].glyphs
    - FontName-Italic[axis].glyphs
axisOrder:
    - wght
    - ital
familyName: "Font Name"

Google Fonts only needs TTF fonts, so you can avoid building OTF as well by adding:

buildOTF: false

→ Note that the ital axis shouldn’t be in the source files if the Roman is separated for from the Italic. Although, the axis order is here to describe the entire design space of the family, so the ital should be mentioned to properly set up the style linking between the two files, as well as a complete STAT table.

Config file for complex font

For example: Texturina, Montserrat, Roboto Serif.


Useful tools

Unfortunately, the Builder can’t do everything yet. You will have to use an external bash script in these cases:

Further reading:
must→ Static fonts specifics
must→ Vertical metrics
must→ QA - Local testing