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

Chain autohinting parameters from Glyphs source to fontmake #850

Merged
merged 15 commits into from
Jan 28, 2022
19 changes: 16 additions & 3 deletions Lib/fontmake/font_project.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@
["ttf-interpolatable", "otf-interpolatable", "variable", "variable-cff2"]
)

AUTOHINTING_PARAMETERS = GLYPHS_PREFIX + "customParameter.InstanceDescriptorAsGSInstance.TTFAutohint options"

@contextmanager
def temporarily_disabling_axis_maps(designspace_path):
Expand Down Expand Up @@ -427,7 +428,8 @@ def save_otfs(
ttf: If True, build fonts with TrueType outlines and .ttf extension.
is_instance: If output fonts are instances, for generating paths.
autohint: Parameters to provide to ttfautohint. If not provided, the
autohinting step is skipped.
UFO lib is scanned for autohinting parameters. If nothing is found,
yanone marked this conversation as resolved.
Show resolved Hide resolved
the autohinting step is skipped.
subset: Whether to subset the output according to data in the UFOs.
If not provided, also determined by flags in the UFOs.
use_production_names: Whether to use production glyph names in the
Expand Down Expand Up @@ -523,8 +525,6 @@ def save_otfs(
inplace=True, # avoid extra copy
)

do_autohint = ttf and autohint is not None

for font, ufo in zip(fonts, ufos):
if interpolate_layout_from is not None:
master_locations, instance_locations = self._designspace_locations(
Expand All @@ -541,6 +541,18 @@ def save_otfs(
if "GSUB" in gsub_src:
font["GSUB"] = gsub_src["GSUB"]


# Read autohinting parameters from autohint variable
if autohint is not None:
autohint_thisfont = autohint
# otherwise read autohinting parameters from ufo lib if present
elif AUTOHINTING_PARAMETERS in ufo.lib and autohint is None:
autohint_thisfont = ufo.lib[AUTOHINTING_PARAMETERS]
else:
autohint_thisfont = None

do_autohint = ttf and autohint_thisfont is not None
anthrotype marked this conversation as resolved.
Show resolved Hide resolved

if do_autohint:
# if we are autohinting, we save the unhinted font to a
# temporary path, and the hinted one to the final destination
Expand Down Expand Up @@ -577,6 +589,7 @@ def save_otfs(
ufo, ext, is_instance, autohinted=True, output_dir=output_dir
)
try:
logger.info("Autohinting %s", otf_path)
ttfautohint(otf_path, hinted_otf_path, args=autohint)
yanone marked this conversation as resolved.
Show resolved Hide resolved
except TTFAError:
# copy unhinted font to destination before re-raising error
Expand Down