From 35a23627a5222684119a11b3b0c8dc5cb1ea04a2 Mon Sep 17 00:00:00 2001 From: Rasmus Andersson Date: Wed, 27 Mar 2019 11:08:49 -0700 Subject: [PATCH] Adds --name option to "fontbuild compile-var" for customizing family name, useful for producing variable font files with a different name than the constant files so they can be installed alongside each other. Closes #144 --- misc/fontbuild | 33 +++++++++++++++++++++++++-------- 1 file changed, 25 insertions(+), 8 deletions(-) diff --git a/misc/fontbuild b/misc/fontbuild index bf88e95b0..e7c86a67c 100755 --- a/misc/fontbuild +++ b/misc/fontbuild @@ -114,6 +114,10 @@ def findGlyphDirectives(g): # -> set | None class VarFontProject(FontProject): + def __init__(self, familyName=None, *args, **kwargs): + super(VarFontProject, self).__init__(*args, **kwargs) + self.familyName = familyName + def decompose_glyphs(self, designspace, glyph_filter=lambda g: True): """Move components of UFOs' glyphs to their outlines.""" for ufo in designspace: @@ -162,13 +166,17 @@ class VarFontProject(FontProject): masters = [s.font for s in designspace.sources] for ufo in masters: - ufo.info.familyName = "Inter Variable" - ufo.info.styleMapFamilyName = "Inter Variable" - ufo.info.postscriptFontName = "InterVariable" - ufo.info.macintoshFONDName =\ - ufo.info.macintoshFONDName.replace('Inter', 'Inter Variable') - ufo.info.openTypeNamePreferredFamilyName =\ - ufo.info.openTypeNamePreferredFamilyName.replace('Inter', 'Inter Variable') + if self.familyName is not None: + ufo.info.familyName =\ + ufo.info.familyName.replace('Inter', self.familyName) + ufo.info.styleMapFamilyName =\ + ufo.info.styleMapFamilyName.replace('Inter', self.familyName) + ufo.info.postscriptFontName =\ + ufo.info.postscriptFontName.replace('Inter', self.familyName.replace(' ', '')) + ufo.info.macintoshFONDName =\ + ufo.info.macintoshFONDName.replace('Inter', self.familyName) + ufo.info.openTypeNamePreferredFamilyName =\ + ufo.info.openTypeNamePreferredFamilyName.replace('Inter', self.familyName) updateFontVersion(ufo) isItalic = ufo.info.italicAngle != 0 ufoname = basename(ufo.path) @@ -405,6 +413,9 @@ class Main(object): argparser.add_argument('-o', '--output', metavar='', help='Output font file') + argparser.add_argument('--name', metavar='', + help='Override family name, replacing "Inter"') + args = argparser.parse_args(argv) # decide output filename (or check user-provided name) @@ -419,7 +430,12 @@ class Main(object): mkdirs(dirname(outfilename)) - project = VarFontProject(verbose=self.logLevelName) + # override family name? + familyName = None + if args.name is not None and len(args.name) > 0: + familyName = args.name + + project = VarFontProject(verbose=self.logLevelName, familyName=familyName) project.run_from_designspace( args.srcfile, interpolate=False, @@ -430,6 +446,7 @@ class Main(object): output=['variable'], overlaps_backend='pathops', # use Skia's pathops ) + self.log("write %s" % outfilename) # Note: we can't run ots-sanitize on the generated file as OTS