From 8841d9865225f33cbbded5cb34cb8f4392c2039c Mon Sep 17 00:00:00 2001 From: justvanrossum Date: Fri, 2 Nov 2018 11:56:22 +0100 Subject: [PATCH 1/3] [name] make addMultilingualName() also add Mac names by default. --- Lib/fontTools/ttLib/tables/_n_a_m_e.py | 25 +++++++++++++++---------- Tests/fontBuilder/data/test.otf.ttx | 15 +++++++++++++++ Tests/fontBuilder/data/test.ttf.ttx | 15 +++++++++++++++ 3 files changed, 45 insertions(+), 10 deletions(-) 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 29eaee168..939b3f0e6 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 17e4ce0d7..919eeac60 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 From 0d06fd23ce858827a08f73780d8a0cb184bf1d40 Mon Sep 17 00:00:00 2001 From: justvanrossum Date: Fri, 2 Nov 2018 12:12:57 +0100 Subject: [PATCH 2/3] fix test failure in addMultilingualName() test by setting mac to None, which makes it behave like before --- Tests/ttLib/tables/_n_a_m_e_test.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) 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), [ From fffd7e4b67a55f557e44966b2e033b0dff976c84 Mon Sep 17 00:00:00 2001 From: justvanrossum Date: Fri, 2 Nov 2018 12:32:50 +0100 Subject: [PATCH 3/3] fixed test failure after merging #1357 --- Tests/fontBuilder/data/test_var.ttf.ttx | 15 +++++++++++++++ 1 file changed, 15 insertions(+) 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