From 68fa3bbd478e07af9f37d3f85b49050205d5ed13 Mon Sep 17 00:00:00 2001 From: Olli Meier Date: Thu, 10 Feb 2022 22:13:58 +0100 Subject: [PATCH] Cleaning code based on feedback from Just --- Lib/fontTools/otlLib/builder.py | 7 +++---- Tests/otlLib/builder_test.py | 13 ++++--------- Tests/ttLib/tables/_n_a_m_e_test.py | 7 ++----- 3 files changed, 9 insertions(+), 18 deletions(-) diff --git a/Lib/fontTools/otlLib/builder.py b/Lib/fontTools/otlLib/builder.py index 8d88295fe..c2891905e 100644 --- a/Lib/fontTools/otlLib/builder.py +++ b/Lib/fontTools/otlLib/builder.py @@ -2763,7 +2763,7 @@ def buildStatTable(ttFont, axes, locations=None, elidedFallbackName=2, windowsNa statTable.AxisValueCount = len(axisValues) -def _buildAxisRecords(axes, nameTable, windowsNames, macNames): +def _buildAxisRecords(axes, nameTable, windowsNames=True, macNames=True): axisRecords = [] axisValues = [] for axisRecordIndex, axisDict in enumerate(axes): @@ -2802,7 +2802,7 @@ def _buildAxisRecords(axes, nameTable, windowsNames, macNames): return axisRecords, axisValues -def _buildAxisValuesFormat4(locations, axes, nameTable, windowsNames, macNames): +def _buildAxisValuesFormat4(locations, axes, nameTable, windowsNames=True, macNames=True): axisTagToIndex = {} for axisRecordIndex, axisDict in enumerate(axes): axisTagToIndex[axisDict["tag"]] = axisRecordIndex @@ -2826,7 +2826,7 @@ def _buildAxisValuesFormat4(locations, axes, nameTable, windowsNames, macNames): return axisValues -def _addName(nameTable, value, minNameID=0, windows, mac): +def _addName(nameTable, value, minNameID=0, windows=True, mac=True): if isinstance(value, int): # Already a nameID return value @@ -2850,5 +2850,4 @@ def _addName(nameTable, value, minNameID=0, windows, mac): return nameID else: raise TypeError("value must be int, str, dict or list") - return nameTable.addMultilingualName(names, windows=windows, mac=mac, minNameID=minNameID) diff --git a/Tests/otlLib/builder_test.py b/Tests/otlLib/builder_test.py index 877229a55..643b39b4f 100644 --- a/Tests/otlLib/builder_test.py +++ b/Tests/otlLib/builder_test.py @@ -1403,13 +1403,10 @@ def test_buildStatTable(axes, axisValues, elidedFallbackName, expected_ttx): def test_buildStatTable_name_duplicates(): - ''' - PR: https://github.com/fonttools/fonttools/pull/2528 - Introduce new 'platform' feature for creating a STAT table. - Set windowsNames and or macNames to create name table entries - in the specified platforms - ''' - + # PR: https://github.com/fonttools/fonttools/pull/2528 + # Introduce new 'platform' feature for creating a STAT table. + # Set windowsNames and or macNames to create name table entries + # in the specified platforms font_obj = ttLib.TTFont() font_obj["name"] = ttLib.newTable("name") font_obj["name"].names = [] @@ -1475,8 +1472,6 @@ def test_buildStatTable_name_duplicates(): assert sorted(expected_names) == sorted(actual_names) - - def test_stat_infinities(): negInf = floatToFixed(builder.AXIS_VALUE_NEGATIVE_INFINITY, 16) assert struct.pack(">l", negInf) == b"\x80\x00\x00\x00" diff --git a/Tests/ttLib/tables/_n_a_m_e_test.py b/Tests/ttLib/tables/_n_a_m_e_test.py index a8c4dc3b7..a70f47f18 100644 --- a/Tests/ttLib/tables/_n_a_m_e_test.py +++ b/Tests/ttLib/tables/_n_a_m_e_test.py @@ -6,7 +6,6 @@ from fontTools.misc.xmlWriter import XMLWriter from io import BytesIO import struct import unittest -from fontTools import ttLib from fontTools.ttLib import TTFont, newTable from fontTools.ttLib.tables._n_a_m_e import ( table__n_a_m_e, NameRecord, nameRecordFormat, nameRecordSize, makeName, log) @@ -313,7 +312,7 @@ class NameTableTest(unittest.TestCase): ''' font_obj = TTFont() - font_obj["name"] = ttLib.newTable("name") + font_obj["name"] = newTable("name") font_obj["name"].names = [] font_obj["name"].setName('Weight', 270, 3, 1, 0x409) @@ -330,12 +329,10 @@ class NameTableTest(unittest.TestCase): font_obj["name"].removeNames(platformID=3) # remove all Windows names font_obj["name"].removeNames(platformID=1) # remove all Mac names nameID = font_obj["name"].addMultilingualName(names, minNameID=256) - #Because there is no name ID with the name 'Weight', + # Because there is no name ID with the name 'Weight', # take the next available name ID -> minNameID=256 self.assertEqual(256, nameID) - - def test_decompile_badOffset(self): # https://github.com/fonttools/fonttools/issues/525 table = table__n_a_m_e()