1
1
mirror of https://github.com/rsms/inter.git synced 2024-11-27 09:49:07 +03:00

fontbuild: adjustments to name generation

This commit is contained in:
Rasmus Andersson 2018-09-03 19:08:46 -07:00
parent fabb2241da
commit b185868203

View File

@ -19,7 +19,11 @@ from glyphsLib.interpolation import apply_instance_data
from mutatorMath.ufo.document import DesignSpaceDocumentReader from mutatorMath.ufo.document import DesignSpaceDocumentReader
subfamily_re = re.compile(r'^\s*([^\s]+)(?:\s*italic|)\s*$', re.I | re.U) stripItalic_re = re.compile(r'(?:^|\b)italic(?:\b|$)', re.I | re.U)
def stripItalic(name):
return stripItalic_re.sub('', name.strip())
def sighandler(signum, frame): def sighandler(signum, frame):
@ -62,6 +66,8 @@ def setFontInfo(font, weight, updateCreated=True):
font.info.version = version font.info.version = version
font.info.versionMajor = versionMajor font.info.versionMajor = versionMajor
font.info.versionMinor = versionMinor font.info.versionMinor = versionMinor
font.info.woffMajorVersion = versionMajor
font.info.woffMinorVersion = versionMinor
font.info.year = now.year font.info.year = now.year
font.info.openTypeNameVersion = "%s;%s" % (version, buildtag) font.info.openTypeNameVersion = "%s;%s" % (version, buildtag)
font.info.openTypeNameUniqueID = "%s %s:%d:%s" % (family, style, now.year, buildtag) font.info.openTypeNameUniqueID = "%s %s:%d:%s" % (family, style, now.year, buildtag)
@ -74,30 +80,43 @@ def setFontInfo(font, weight, updateCreated=True):
# name ID 16 "Typographic Family name" # name ID 16 "Typographic Family name"
font.info.openTypeNamePreferredFamilyName = family font.info.openTypeNamePreferredFamilyName = family
# name ID 17 "Typographic Subfamily name" # name ID 17 "Typographic Subfamily name"
subfamily = subfamily_re.sub('\\1', style) # "A Italic" => "A", "A" => "A" font.info.openTypeNamePreferredSubfamilyName = style
if len(subfamily) == 0 or subfamily.strip().lower() == 'italic':
# name ID 1 "Family name" (legacy, but required)
# Restriction:
# "shared among at most four fonts that differ only in weight or style"
# So we map as follows:
# - Regular => "Family", ("regular" | "italic" | "bold" | "bold italic")
# - Medium => "Family Medium", ("regular" | "italic")
# - Black => "Family Black", ("regular" | "italic")
# and so on.
subfamily = stripItalic(style) # "A Italic" => "A", "A" => "A"
if len(subfamily) == 0:
subfamily = "Regular" subfamily = "Regular"
font.info.openTypeNamePreferredSubfamilyName = subfamily
# Legacy family name (full name except "italic")
subfamily_lc = subfamily.lower() subfamily_lc = subfamily.lower()
if subfamily_lc != "regular" and subfamily_lc != "bold": if subfamily_lc == "regular" or subfamily_lc == "bold":
font.info.styleMapFamilyName = "%s %s" % (family, subfamily)
else:
font.info.styleMapFamilyName = family font.info.styleMapFamilyName = family
# name ID 2 "Subfamily name" (legacy, but required)
# Legacy style name. Must be one of these case-sensitive strings: # Value must be one of: "regular", "italic", "bold", "bold italic"
# "regular", "italic", "bold", "bold italic" if subfamily_lc == "regular":
font.info.styleMapStyleName = "regular" if isitalic:
if style.strip().lower().find('bold') != -1: font.info.styleMapStyleName = "italic"
else:
font.info.styleMapStyleName = "regular"
else: # bold
if isitalic:
font.info.styleMapStyleName = "bold italic"
else:
font.info.styleMapStyleName = "bold"
else:
font.info.styleMapFamilyName = family + ' ' + subfamily
# name ID 2 "Subfamily name" (legacy, but required)
if isitalic: if isitalic:
font.info.styleMapStyleName = "bold italic" font.info.styleMapStyleName = "italic"
else: else:
font.info.styleMapStyleName = "bold" font.info.styleMapStyleName = "regular"
elif isitalic:
font.info.styleMapStyleName = "italic"
class Main(object): class Main(object):
@ -196,7 +215,8 @@ class Main(object):
project.run_from_ufos( project.run_from_ufos(
[args.ufo], [args.ufo],
output_dir=self.tmpdir, output_dir=self.tmpdir,
output=formats output=formats,
subroutinize=True
) )
# run through ots-sanitize # run through ots-sanitize
@ -207,6 +227,7 @@ class Main(object):
try: try:
otssan_res = subprocess.check_output( otssan_res = subprocess.check_output(
['ots-sanitize', tmpfile, filename], ['ots-sanitize', tmpfile, filename],
# ['cp', tmpfile, filename],
shell=False shell=False
).strip() ).strip()
# Note: ots-sanitize does not exit with an error in many cases where # Note: ots-sanitize does not exit with an error in many cases where