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

More work on scripts. #21

Merged
merged 8 commits into from
Aug 15, 2012
Prev Previous commit
Next Next commit
GPOS and GSUB tables can be reloaded separately
  • Loading branch information
madig committed Aug 15, 2012
commit 91c19a97f6a41434af170b6486e538960d97826c
45 changes: 29 additions & 16 deletions tools/makefont.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
# invoked by the Makefile

import os
import re
import argparse
import fontforge

Expand All @@ -18,35 +19,47 @@
'version',
help='Version string to embed into the font file, e.g. "v1.1"')
argparser.add_argument(
'--reloadlookups',
help='Clean lookups (GPOS and GSUB) and reimport '
'--reloadgpos', action="store_true",
help='Clean GPOS lookups and reimport '
'them from the feature files before generating '
'font files. For Developement. Give the '
'identifier-prefix for the font from featurefiles/, '
'e.g. "Regular" when you want to make "EBGaramond12-Regular.sfdir". '
'When using this option, execute the script from '
'the top-level directory so it can find the feature files!')
'font files. For Developement.')
argparser.add_argument(
'--reloadgsub', action="store_true",
help='Clean GSUB lookups and reimport '
'them from the feature files before generating '
'font files. For Developement.')
args = argparser.parse_args()

def reloadfeature(feature):
"""Read and merge a certain feature file. Example: For
EBGaramond12-Regular.sfdir, reloadfeature("GPOS") would merge
featurefiles/12-Regular_GPOS.fea and reloadfeature("features") would merge
featurefiles/12-Regular_features.fea (GSUB table)."""
# Guess prefix of feature file from input, e.g.
# 'EBGaramond12-Regular.sfdir' becomes inferred_style="12-Regular".
font_source_name = os.path.split(args.input)[1]
inferred_style = re.search('\d+-\w+', font_source_name).group(0)
featurepath = "featurefiles/" + inferred_style + "_%s.fea"
featurefile = featurepath % feature

if os.path.exists(featurefile):
font.mergeFeature(featurefile)

font = fontforge.open(args.input)
font.version = args.version
font.encoding = 'UnicodeFull'
font.selection.all()
font.autoHint()

if args.reloadlookups:
if args.reloadgpos:
for lookup in font.gpos_lookups:
font.removeLookup(lookup)
reloadfeature("GPOS")

if args.reloadgsub:
for lookup in font.gsub_lookups:
font.removeLookup(lookup)

featurepath = "featurefiles/" + args.reloadlookups + "_%s.fea"
featurefile = featurepath % "features"
if os.path.exists(featurefile):
font.mergeFeature(featurefile)
gpos_featurefile = featurepath % "GPOS"
if os.path.exists(gpos_featurefile):
font.mergeFeature(gpos_featurefile)
reloadfeature("features")

extension = os.path.splitext(args.output)[1]
if extension == '.ttf':
Expand Down