1
1
mirror of https://github.com/rsms/inter.git synced 2024-12-01 20:43:10 +03:00

attempt to fix static font name linking metadata stuff, re #519 and #515

This commit is contained in:
Rasmus Andersson 2023-04-21 17:45:54 -07:00
parent 0e3f6d91ab
commit b4d529e2d1
3 changed files with 168 additions and 13 deletions

View File

@ -18,10 +18,9 @@ $(UFODIR)/%.glyphs: src/%.glyphspackage | $(UFODIR) venv
. $(VENV) ; build/venv/bin/glyphspkg -o $(dir $@) $^
# features
features_data: src/features $(wildcard src/features/*)
@touch "$@"
@true
$(UFODIR)/features: src/features
build/features_data: $(UFODIR)/features $(wildcard src/features/*)
touch "$@"
$(UFODIR)/features:
@mkdir -p $(UFODIR)
@rm -f $(UFODIR)/features
@ln -s ../../src/features $(UFODIR)/features
@ -33,9 +32,9 @@ $(UFODIR)/%.designspace: $(UFODIR)/%.glyphs $(UFODIR)/features | venv
. $(VENV) ; python misc/tools/postprocess-designspace.py $@
# instance UFOs from designspace
$(UFODIR)/Inter-%Italic.ufo: $(UFODIR)/Inter-Italic.designspace features_data | venv
$(UFODIR)/Inter-%Italic.ufo: $(UFODIR)/Inter-Italic.designspace | venv
. $(VENV) ; bash misc/tools/gen-instance-ufo.sh $< $@
$(UFODIR)/Inter-%.ufo: $(UFODIR)/Inter-Roman.designspace features_data | venv
$(UFODIR)/Inter-%.ufo: $(UFODIR)/Inter-Roman.designspace | venv
. $(VENV) ; bash misc/tools/gen-instance-ufo.sh $< $@
# designspace & master UFOs (for editing)
@ -46,9 +45,9 @@ build/ufo-editable/%.designspace: $(UFODIR)/%.glyphs $(UFODIR)/features | venv
. $(VENV) ; python misc/tools/postprocess-designspace.py --editable $@
# instance UFOs from designspace (for editing)
build/ufo-editable/Inter-%Italic.ufo: build/ufo-editable/Inter-Italic.designspace build/ufo-editable/features | venv
build/ufo-editable/Inter-%Italic.ufo: build/ufo-editable/Inter-Italic.designspace | venv
. $(VENV) ; bash misc/tools/gen-instance-ufo.sh $< $@
build/ufo-editable/Inter-%.ufo: build/ufo-editable/Inter-Roman.designspace build/ufo-editable/features | venv
build/ufo-editable/Inter-%.ufo: build/ufo-editable/Inter-Roman.designspace | venv
. $(VENV) ; bash misc/tools/gen-instance-ufo.sh $< $@
editable-ufos: build/ufo-editable/.ok
@ -140,20 +139,30 @@ build/ufo-editable/.ok: build/ufo-editable/Inter-Roman.designspace build/ufo-edi
# ---------------------------------------------------------------------------------
# products
$(FONTDIR)/static/%.otf: $(UFODIR)/%.ufo | $(FONTDIR)/static venv
$(FONTDIR)/static/Inter-Displa%.otf: $(UFODIR)/Inter-Displa%.ufo build/features_data | $(FONTDIR)/static venv
. $(VENV) ; fontmake -u $< -o otf --output-path $@ --overlaps-backend pathops --production-names
. $(VENV) ; python misc/tools/fix-static-display-names.py $@
$(FONTDIR)/static/%.otf: $(UFODIR)/%.ufo build/features_data | $(FONTDIR)/static venv
. $(VENV) ; fontmake -u $< -o otf --output-path $@ --overlaps-backend pathops --production-names
$(FONTDIR)/static/%.ttf: $(UFODIR)/%.ufo | $(FONTDIR)/static venv
$(FONTDIR)/static/Inter-Displa%.ttf: $(UFODIR)/Inter-Displa%.ufo build/features_data | $(FONTDIR)/static venv
. $(VENV) ; fontmake -u $< -o ttf --output-path $@ --overlaps-backend pathops --production-names
. $(VENV) ; python misc/tools/fix-static-display-names.py $@
$(FONTDIR)/static/%.ttf: $(UFODIR)/%.ufo build/features_data | $(FONTDIR)/static venv
. $(VENV) ; fontmake -u $< -o ttf --output-path $@ --overlaps-backend pathops --production-names
$(FONTDIR)/static-hinted/%.ttf: $(FONTDIR)/static/%.ttf | $(FONTDIR)/static-hinted venv
. $(VENV) ; python -m ttfautohint --no-info "$<" "$@"
$(FONTDIR)/var/_%.var.ttf: $(UFODIR)/%.designspace | $(FONTDIR)/var venv
$(FONTDIR)/var/_%.var.ttf: $(UFODIR)/%.designspace build/features_data | $(FONTDIR)/var venv
. $(VENV) ; fontmake -o variable -m $< --output-path $@ \
--overlaps-backend pathops --production-names
$(FONTDIR)/var/_%.var.otf: $(UFODIR)/%.designspace | $(FONTDIR)/var venv
$(FONTDIR)/var/_%.var.otf: $(UFODIR)/%.designspace build/features_data | $(FONTDIR)/var venv
. $(VENV) ; fontmake -o variable-cff2 -m $< --output-path $@ \
--overlaps-backend pathops --production-names

View File

@ -0,0 +1,132 @@
import sys, os, os.path, argparse, re
from fontTools.ttLib import TTFont
WINDOWS_ENGLISH_IDS = 3, 1, 0x409
MAC_ROMAN_IDS = 1, 0, 0
LEGACY_FAMILY = 1
SUBFAMILY_NAME = 2
TRUETYPE_UNIQUE_ID = 3
FULL_NAME = 4
POSTSCRIPT_NAME = 6
PREFERRED_FAMILY = 16
TYPO_SUBFAMILY_NAME = 17
WWS_FAMILY = 21
WWS_SUBFAMILY = 22
whitespace_re = re.compile(r'\s+')
def remove_whitespace(s):
return whitespace_re.sub('', s)
def normalize_whitespace(s):
return whitespace_re.sub(' ', s)
def remove_substring(s, substr):
# examples of remove_substring(s, "Display"):
# "Inter Display" => "Inter"
# "Display Lol" => "Lol"
# "Foo Display Lol" => "Foo Lol"
# " Foo Bar Lol " => "Foo Bar Lol"
return normalize_whitespace(s.strip().replace(substr, '')).strip()
def getStyleName(font):
nameTable = font["name"]
for plat_id, enc_id, lang_id in (WINDOWS_ENGLISH_IDS, MAC_ROMAN_IDS):
for name_id in (TYPO_SUBFAMILY_NAME, SUBFAMILY_NAME):
r = nameTable.getName(
nameID=name_id, platformID=plat_id, platEncID=enc_id, langID=lang_id)
if r is not None:
return r.toUnicode()
raise ValueError("style name not found")
def print_relevant_names(nameTable):
names = {
LEGACY_FAMILY: "LEGACY_FAMILY",
TRUETYPE_UNIQUE_ID: "TRUETYPE_UNIQUE_ID",
FULL_NAME: "FULL_NAME",
POSTSCRIPT_NAME: "POSTSCRIPT_NAME",
PREFERRED_FAMILY: "PREFERRED_FAMILY",
WWS_FAMILY: "WWS_FAMILY",
WWS_SUBFAMILY: "WWS_SUBFAMILY",
SUBFAMILY_NAME: "SUBFAMILY_NAME",
TYPO_SUBFAMILY_NAME: "TYPO_SUBFAMILY_NAME",
}
for rec in nameTable.names:
name_id = rec.nameID
name = names.get(name_id)
if name:
print("%-19s #%-2d %s" % (name, name_id, rec.toUnicode()))
def main():
argparser = argparse.ArgumentParser(
description='Rename family and styles of static "Inter Display" fonts'
)
a = lambda *args, **kwargs: argparser.add_argument(*args, **kwargs)
a('-o', '--output', metavar='<file>',
help='Output font file. Defaults to input file (overwrite)')
a('input', metavar='<file>', help='Input font file')
args = argparser.parse_args()
infile = args.input
outfile = args.output or infile
font = TTFont(infile, recalcBBoxes=False, recalcTimestamp=False)
family = "Inter Display"
style = remove_substring(getStyleName(font), "Display")
if style == '':
style = 'Regular'
# See https://learn.microsoft.com/en-us/typography/opentype/spec/name
nameTable = font["name"]
fullName = family + " " + style
fullNamePs = remove_whitespace(family) + "-" + remove_whitespace(style)
try:
# print_relevant_names(nameTable)
# set full name
nameTable.setName(fullName, FULL_NAME, 1, 0, 0) # mac
nameTable.setName(fullName, FULL_NAME, 3, 1, 0x409) # windows
nameTable.setName(fullNamePs, POSTSCRIPT_NAME, 1, 0, 0) # mac
nameTable.setName(fullNamePs, POSTSCRIPT_NAME, 3, 1, 0x409) # windows
for rec in nameTable.names:
id = rec.nameID
if id == TRUETYPE_UNIQUE_ID: # ID 3
# Format:
# version ";" "git-" git-tag ";" foundry-tag ";" ps_family "-" ps_style
# E.g.
# "4.001;git-4de559246;RSMS;Inter-DisplayThinItalic"
id = rec.toUnicode().split(";")
id[3] = fullNamePs
rec.string = ";".join(id)
elif id == LEGACY_FAMILY: # ID 1
rec.string = family
elif id == PREFERRED_FAMILY: # ID 16
rec.string = family
elif id == WWS_FAMILY: # ID 21
rec.string = family
elif id == WWS_SUBFAMILY: # ID 22
rec.string = style
elif id in (SUBFAMILY_NAME, TYPO_SUBFAMILY_NAME): # ID 2, ID 17
rec.string = style
# print("————————————————————————————————————————————————————")
# print_relevant_names(nameTable)
font.save(outfile)
finally:
font.close()
if __name__ == '__main__':
main()

View File

@ -27,7 +27,21 @@ def update_version(ufo):
ufo.info.openTypeNameVersion = "Version %d.%03d;git-%s" % (versionMajor, versionMinor, buildtag)
psFamily = re.sub(r'\s', '', ufo.info.familyName)
psStyle = re.sub(r'\s', '', ufo.info.styleName)
ufo.info.openTypeNameUniqueID = "%s-%s:%d:%s" % (psFamily, psStyle, now.year, buildtag)
#
# id format:
# version ";" "git-" git-tag ";" foundry-tag ";" ps_family "-" ps_style
# E.g.
# "4.001;git-4de559246;RSMS;Inter-DisplayThinItalic"
# Note: this should match what generated by fontmake.
# fix-static-display-names.py depends on this format being consistent for all fonts.
#
if buildtag != "src":
buildtag = "git-" + buildtag
ufo.info.openTypeNameUniqueID = "%d.%03d;%s;%s;%s-%s" % (
versionMajor, versionMinor,
buildtag,
ufo.info.openTypeOS2VendorID,
psFamily, psStyle)
ufo.info.openTypeHeadCreated = now.strftime("%Y/%m/%d %H:%M:%S")