Skip to content

Commit

Permalink
Merge pull request #1036 from googlefonts/fix-1035
Browse files Browse the repository at this point in the history
Check all name records for Mac IDs
  • Loading branch information
m4rc1e authored Sep 30, 2024
2 parents a2b3549 + 7c91435 commit 67c8b63
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 19 deletions.
28 changes: 13 additions & 15 deletions Lib/gftools/fix.py
Original file line number Diff line number Diff line change
Expand Up @@ -671,25 +671,23 @@ def drop_superfluous_mac_names(ttfont) -> FixResult:
such as Word 2011. IDs 1-6 are very common, > 16 are edge cases.
https://www.microsoft.com/typography/otspec/name.htm"""
keep_ids = [1, 2, 3, 4, 5, 6, 16, 17, 18, 20, 21, 22, 25]
messages = []
for n in range(255):
if n not in keep_ids:
name = ttfont["name"].getName(n, 1, 0, 0)
if name:
messages.append(f"Removed nameID {n}: {name.toStr()}")
ttfont["name"].names.remove(name)
return ttfont, messages
drop_mac_names(ttfont, keep_ids=[1, 2, 3, 4, 5, 6, 16, 17, 18, 20, 21, 22, 25])


def drop_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 67c8b63

Please sign in to comment.