Skip to content

Commit

Permalink
replace old family name with new name
Browse files Browse the repository at this point in the history
  • Loading branch information
m4rc1e committed May 9, 2022
1 parent fb0b17e commit bed9a2a
Showing 1 changed file with 15 additions and 1 deletion.
16 changes: 15 additions & 1 deletion Lib/axisregistry/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -347,6 +347,7 @@ def build_static_name_table(self, family_name, style_name):
# TODO replace occurences in all records
# stip mac names
self.name_table.removeNames(platformID=1)
existing_name = self.ttFont["name"].getBestFamilyName()

names = {}
is_ribbi = False
Expand All @@ -372,7 +373,7 @@ def build_static_name_table(self, family_name, style_name):
new_family_name = family_name.split()
is_italic = "Italic" in style_tokens
for t in style_tokens:
if t in ["Regular", "Italic"]:
if t in ["Regular", "Italic"] or t in new_family_name:
continue
new_family_name.append(t)
new_family_name = " ".join(new_family_name)
Expand All @@ -397,6 +398,19 @@ def build_static_name_table(self, family_name, style_name):
log.debug(f"Adding name record {k}: {v}")
self.name_table.setName(v, *k)

# Replace occurences of old family name in untouched records
skip_ids = [i.numerator for i in NameID]
for r in self.ttFont["name"].names:
if r.nameID in skip_ids:
continue
current = r.toUnicode()
if existing_name not in current:
continue
replacement = current.replace(existing_name, family_name)
self.ttFont["name"].setName(
replacement, r.nameID, r.platformID, r.platEncID, r.langID
)

def build_static_name_table_v1(self, family_name, style_name):
"""Pre VF name tables, this version can only accept wght + ital"""
non_weight_tokens = []
Expand Down

0 comments on commit bed9a2a

Please sign in to comment.