Skip to content

Commit

Permalink
Check all name records, not just first 255
Browse files Browse the repository at this point in the history
  • Loading branch information
simoncozens committed Sep 30, 2024
1 parent df3d86a commit 7c91435
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 9 deletions.
16 changes: 11 additions & 5 deletions Lib/gftools/fix.py
Original file line number Diff line number Diff line change
Expand Up @@ -677,11 +677,17 @@ def drop_superfluous_mac_names(ttfont) -> FixResult:
def drop_mac_names(ttfont, keep_ids=[]) -> FixResult:
"""Drop all mac names"""
messages = []
for n in range(255):
name = ttfont["name"].getName(n, 1, 0, 0)
if name:
ttfont["name"].names.remove(name)
messages.append(f"Removed nameID {n}: {name.toStr()}")
for namerecord in list( # list() to avoid removing while iterating
ttfont["name"].names
):
if namerecord.nameID not in keep_ids:
messages.append(f"Removed nameID {namerecord.nameID}: {namerecord.toStr()}")
if (
namerecord.platformID == 1
and namerecord.platEncID == 0
and namerecord.langID == 0
):
ttfont["name"].names.remove(namerecord)
return ttfont, messages


Expand Down
10 changes: 6 additions & 4 deletions Lib/gftools/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -520,10 +520,12 @@ def has_mac_names(ttfont):
"""Check if a font has Mac names. Mac names have the following
field values:
platformID: 1, encodingID: 0, LanguageID: 0"""
for i in range(255):
if ttfont["name"].getName(i, 1, 0, 0):
return True
return False
return any(
namerecord.platformID == 1
and namerecord.platEncID == 0
and namerecord.langID == 0
for namerecord in ttfont["name"].names
)


def font_is_italic(ttfont):
Expand Down

0 comments on commit 7c91435

Please sign in to comment.