Skip to content

Instantly share code, notes, and snippets.

@m4rc1e
Created June 29, 2018 17:07
Show Gist options
  • Save m4rc1e/6bce4997bf160938adf67486f46fcebe to your computer and use it in GitHub Desktop.
Save m4rc1e/6bce4997bf160938adf67486f46fcebe to your computer and use it in GitHub Desktop.
Add an avar table to a variable font
"""
Add an avar table to a VF font. This is often needed for VF fonts generated with glyphsapp
Please note: this script requires the same dependencies as fontmake, https://github.com/googlei18n/fontmake
For testing avar table see script, https://github.com/googlefonts/gftools/blob/master/bin/gftools-check-vf-avar.py
TODO (GF team) File issue on Glyphsapp if glyphsapp does not generate avar table by default.
How to use:
python add_avar.py family.glyph family-Roman-VF.ttf
"""
from fontTools.varLib import _add_avar, load_designspace
from fontTools.ttLib import TTFont
import glyphsLib
import sys
if len(sys.argv) != 3:
raise Exception('Include path to .glyphs source and VF tff e.g.\n\n python add_avar.py family.glyph family-Roman-VF.ttf')
glyphs_path = sys.argv[1]
font_path = sys.argv[2]
ttfont = TTFont(font_path)
font = glyphsLib.GSFont(glyphs_path)
designspace = glyphsLib.to_designspace(font)
designspace_filename = 'temp.designspace'
designspace.write(designspace_filename)
axes, internal_axis_supports, base_idx, normalized_master_locs, masters, instances = load_designspace(designspace_filename)
_add_avar(ttfont, axes)
ttfont.save(font_path+'.avar')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment