Skip to content

Commit

Permalink
Merge pull request #3253 from fonttools/name-warning
Browse files Browse the repository at this point in the history
[ttLib] Fix warning when calling addMultilingualName() with "ar" name
  • Loading branch information
anthrotype committed Aug 14, 2023
2 parents 57fb47d + ae31d05 commit dd783ff
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 3 deletions.
8 changes: 5 additions & 3 deletions Lib/fontTools/ttLib/tables/_n_a_m_e.py
Original file line number Diff line number Diff line change
Expand Up @@ -258,7 +258,9 @@ def _findUnusedNameID(self, minNameID=256):
raise ValueError("nameID must be less than 32768")
return nameID

def findMultilingualName(self, names, windows=True, mac=True, minNameID=0):
def findMultilingualName(
self, names, windows=True, mac=True, minNameID=0, ttFont=None
):
"""Return the name ID of an existing multilingual name that
matches the 'names' dictionary, or None if not found.
Expand Down Expand Up @@ -293,7 +295,7 @@ def findMultilingualName(self, names, windows=True, mac=True, minNameID=0):
)
)
if mac:
macName = _makeMacName(name, None, lang)
macName = _makeMacName(name, None, lang, ttFont)
if macName is not None:
reqNameSet.add(
(
Expand Down Expand Up @@ -352,7 +354,7 @@ def addMultilingualName(
if nameID is None:
# Reuse nameID if possible
nameID = self.findMultilingualName(
names, windows=windows, mac=mac, minNameID=minNameID
names, windows=windows, mac=mac, minNameID=minNameID, ttFont=ttFont
)
if nameID is not None:
return nameID
Expand Down
9 changes: 9 additions & 0 deletions Tests/ttLib/tables/_n_a_m_e_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -324,6 +324,15 @@ def test_addMultilingualName_noTTFont(self):
nameTable.addMultilingualName({"en": "A", "la": "ⱾƤℚⱤ"})
captor.assertRegex("cannot store language la into 'ltag' table")

def test_addMultilingualName_TTFont(self):
# if ttFont argument is passed, it should not WARN about not being able
# to create ltag table.
font = FakeFont(glyphs=[".notdef", "A"])
nameTable = newTable("name")
with CapturingLogHandler(log, "WARNING") as captor:
nameTable.addMultilingualName({"en": "A", "ar": "ع"}, ttFont=font)
self.assertFalse(captor.records)

def test_addMultilingualName_minNameID(self):
table = table__n_a_m_e()
names, namesSubSet, namesSuperSet = self._get_test_names()
Expand Down

0 comments on commit dd783ff

Please sign in to comment.