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
24 changes: 17 additions & 7 deletions Lib/fontmake/font_project.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,10 @@
["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 +431,9 @@ 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,
the autohinting step is skipped. The lib key is
"com.schriftgestaltung.customParameter.InstanceDescriptorAsGSInstance.TTFAutohint options"
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 @@ -469,7 +475,7 @@ def save_otfs(
pre-filters or post-filters, called before or after the default
filters. The default filters are format specific and some can
be disabled with other arguments.
"""
""" # noqa: B950
assert not (output_path and output_dir), "mutually exclusive args"

if output_path is not None and len(ufos) > 1:
Expand Down Expand Up @@ -523,8 +529,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,7 +545,12 @@ def save_otfs(
if "GSUB" in gsub_src:
font["GSUB"] = gsub_src["GSUB"]

if do_autohint:
# Decide on autohinting and its parameters
autohint_thisfont = ttf and (
autohint or ufo.lib.get(AUTOHINTING_PARAMETERS)
)

if autohint_thisfont:
# if we are autohinting, we save the unhinted font to a
# temporary path, and the hinted one to the final destination
fd, otf_path = tempfile.mkstemp("." + ext)
Expand All @@ -567,7 +576,7 @@ def save_otfs(
):
self.subset_otf_from_ufo(otf_path, ufo)

if not do_autohint:
if not autohint_thisfont:
continue

if output_path is not None:
Expand All @@ -577,7 +586,8 @@ def save_otfs(
ufo, ext, is_instance, autohinted=True, output_dir=output_dir
)
try:
ttfautohint(otf_path, hinted_otf_path, args=autohint)
logger.info("Autohinting %s", otf_path)
ttfautohint(otf_path, hinted_otf_path, args=autohint_thisfont)
except TTFAError:
# copy unhinted font to destination before re-raising error
shutil.copyfile(otf_path, hinted_otf_path)
Expand Down
Loading