diff --git a/Lib/fontTools/ttLib/tables/_n_a_m_e.py b/Lib/fontTools/ttLib/tables/_n_a_m_e.py index a30291cc3..488c4ea5f 100644 --- a/Lib/fontTools/ttLib/tables/_n_a_m_e.py +++ b/Lib/fontTools/ttLib/tables/_n_a_m_e.py @@ -161,7 +161,8 @@ class table__n_a_m_e(DefaultTable.DefaultTable): raise ValueError("nameID must be less than 32768") return nameID - def addMultilingualName(self, names, ttFont=None, nameID=None): + def addMultilingualName(self, names, ttFont=None, nameID=None, + windows=True, mac=True): """Add a multilingual name, returning its name ID 'names' is a dictionary with the name in multiple languages, @@ -176,6 +177,9 @@ class table__n_a_m_e(DefaultTable.DefaultTable): 'nameID' is the name ID to be used, or None to let the library pick an unused name ID. + + If 'windows' is True, a platformID=3 name record will be added. + If 'mac' is True, a platformID=1 name record will be added. """ if not hasattr(self, 'names'): self.names = [] @@ -184,15 +188,16 @@ class table__n_a_m_e(DefaultTable.DefaultTable): # TODO: Should minimize BCP 47 language codes. # https://github.com/fonttools/fonttools/issues/930 for lang, name in sorted(names.items()): - # Apple platforms have been recognizing Windows names - # since early OSX (~2001), so we only add names - # for the Macintosh platform when we cannot not make - # a Windows name. This can happen for exotic BCP47 - # language tags that have no Windows language code. - windowsName = _makeWindowsName(name, nameID, lang) - if windowsName is not None: - self.names.append(windowsName) - else: + if windows: + windowsName = _makeWindowsName(name, nameID, lang) + if windowsName is not None: + self.names.append(windowsName) + else: + # We cannot not make a Windows name: make sure we add a + # Mac name as a fallback. This can happen for exotic + # BCP47 language tags that have no Windows language code. + mac = True + if mac: macName = _makeMacName(name, nameID, lang, ttFont) if macName is not None: self.names.append(macName) diff --git a/Tests/fontBuilder/data/test.otf.ttx b/Tests/fontBuilder/data/test.otf.ttx index 0b7279469..4c9a2a754 100644 --- a/Tests/fontBuilder/data/test.otf.ttx +++ b/Tests/fontBuilder/data/test.otf.ttx @@ -109,6 +109,21 @@ + + HelloTestFont + + + TotallyNormal + + + HelloTestFont-TotallyNormal + + + HalloTestFont + + + TotaalNormaal + HelloTestFont diff --git a/Tests/fontBuilder/data/test.ttf.ttx b/Tests/fontBuilder/data/test.ttf.ttx index 34b655e3a..b2804ccdd 100644 --- a/Tests/fontBuilder/data/test.ttf.ttx +++ b/Tests/fontBuilder/data/test.ttf.ttx @@ -201,6 +201,21 @@ + + HelloTestFont + + + TotallyNormal + + + HelloTestFont-TotallyNormal + + + HalloTestFont + + + TotaalNormaal + HelloTestFont diff --git a/Tests/fontBuilder/data/test_var.ttf.ttx b/Tests/fontBuilder/data/test_var.ttf.ttx index a7bdcaf07..760e65a56 100644 --- a/Tests/fontBuilder/data/test_var.ttf.ttx +++ b/Tests/fontBuilder/data/test_var.ttf.ttx @@ -177,6 +177,15 @@ + + HelloTestFont + + + TotallyNormal + + + HelloTestFont-TotallyNormal + Left @@ -195,6 +204,12 @@ Right Up + + HalloTestFont + + + TotaalNormaal + HelloTestFont diff --git a/Tests/ttLib/tables/_n_a_m_e_test.py b/Tests/ttLib/tables/_n_a_m_e_test.py index a27e3c1a2..fde14bc81 100644 --- a/Tests/ttLib/tables/_n_a_m_e_test.py +++ b/Tests/ttLib/tables/_n_a_m_e_test.py @@ -93,12 +93,12 @@ class NameTableTest(unittest.TestCase): "en": "Width", "de-CH": "Breite", "gsw-LI": "Bräiti", - }, ttFont=font) + }, ttFont=font, mac=False) self.assertEqual(widthID, 256) xHeightID = nameTable.addMultilingualName({ "en": "X-Height", "gsw-LI": "X-Hööchi" - }, ttFont=font) + }, ttFont=font, mac=False) self.assertEqual(xHeightID, 257) captor.assertRegex("cannot add Windows name in language gsw-LI") self.assertEqual(names(nameTable), [