Cleaning code based on feedback from Just

This commit is contained in:
Olli Meier 2022-02-10 22:13:58 +01:00
parent d77ec968a3
commit 68fa3bbd47
3 changed files with 9 additions and 18 deletions

View File

@ -2763,7 +2763,7 @@ def buildStatTable(ttFont, axes, locations=None, elidedFallbackName=2, windowsNa
statTable.AxisValueCount = len(axisValues) statTable.AxisValueCount = len(axisValues)
def _buildAxisRecords(axes, nameTable, windowsNames, macNames): def _buildAxisRecords(axes, nameTable, windowsNames=True, macNames=True):
axisRecords = [] axisRecords = []
axisValues = [] axisValues = []
for axisRecordIndex, axisDict in enumerate(axes): for axisRecordIndex, axisDict in enumerate(axes):
@ -2802,7 +2802,7 @@ def _buildAxisRecords(axes, nameTable, windowsNames, macNames):
return axisRecords, axisValues return axisRecords, axisValues
def _buildAxisValuesFormat4(locations, axes, nameTable, windowsNames, macNames): def _buildAxisValuesFormat4(locations, axes, nameTable, windowsNames=True, macNames=True):
axisTagToIndex = {} axisTagToIndex = {}
for axisRecordIndex, axisDict in enumerate(axes): for axisRecordIndex, axisDict in enumerate(axes):
axisTagToIndex[axisDict["tag"]] = axisRecordIndex axisTagToIndex[axisDict["tag"]] = axisRecordIndex
@ -2826,7 +2826,7 @@ def _buildAxisValuesFormat4(locations, axes, nameTable, windowsNames, macNames):
return axisValues return axisValues
def _addName(nameTable, value, minNameID=0, windows, mac): def _addName(nameTable, value, minNameID=0, windows=True, mac=True):
if isinstance(value, int): if isinstance(value, int):
# Already a nameID # Already a nameID
return value return value
@ -2850,5 +2850,4 @@ def _addName(nameTable, value, minNameID=0, windows, mac):
return nameID return nameID
else: else:
raise TypeError("value must be int, str, dict or list") raise TypeError("value must be int, str, dict or list")
return nameTable.addMultilingualName(names, windows=windows, mac=mac, minNameID=minNameID) return nameTable.addMultilingualName(names, windows=windows, mac=mac, minNameID=minNameID)

View File

@ -1403,13 +1403,10 @@ def test_buildStatTable(axes, axisValues, elidedFallbackName, expected_ttx):
def test_buildStatTable_name_duplicates(): def test_buildStatTable_name_duplicates():
''' # PR: https://github.com/fonttools/fonttools/pull/2528
PR: https://github.com/fonttools/fonttools/pull/2528 # Introduce new 'platform' feature for creating a STAT table.
Introduce new 'platform' feature for creating a STAT table. # Set windowsNames and or macNames to create name table entries
Set windowsNames and or macNames to create name table entries # in the specified platforms
in the specified platforms
'''
font_obj = ttLib.TTFont() font_obj = ttLib.TTFont()
font_obj["name"] = ttLib.newTable("name") font_obj["name"] = ttLib.newTable("name")
font_obj["name"].names = [] font_obj["name"].names = []
@ -1475,8 +1472,6 @@ def test_buildStatTable_name_duplicates():
assert sorted(expected_names) == sorted(actual_names) assert sorted(expected_names) == sorted(actual_names)
def test_stat_infinities(): def test_stat_infinities():
negInf = floatToFixed(builder.AXIS_VALUE_NEGATIVE_INFINITY, 16) negInf = floatToFixed(builder.AXIS_VALUE_NEGATIVE_INFINITY, 16)
assert struct.pack(">l", negInf) == b"\x80\x00\x00\x00" assert struct.pack(">l", negInf) == b"\x80\x00\x00\x00"

View File

@ -6,7 +6,6 @@ from fontTools.misc.xmlWriter import XMLWriter
from io import BytesIO from io import BytesIO
import struct import struct
import unittest import unittest
from fontTools import ttLib
from fontTools.ttLib import TTFont, newTable from fontTools.ttLib import TTFont, newTable
from fontTools.ttLib.tables._n_a_m_e import ( from fontTools.ttLib.tables._n_a_m_e import (
table__n_a_m_e, NameRecord, nameRecordFormat, nameRecordSize, makeName, log) table__n_a_m_e, NameRecord, nameRecordFormat, nameRecordSize, makeName, log)
@ -313,7 +312,7 @@ class NameTableTest(unittest.TestCase):
''' '''
font_obj = TTFont() font_obj = TTFont()
font_obj["name"] = ttLib.newTable("name") font_obj["name"] = newTable("name")
font_obj["name"].names = [] font_obj["name"].names = []
font_obj["name"].setName('Weight', 270, 3, 1, 0x409) 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=3) # remove all Windows names
font_obj["name"].removeNames(platformID=1) # remove all Mac names font_obj["name"].removeNames(platformID=1) # remove all Mac names
nameID = font_obj["name"].addMultilingualName(names, minNameID=256) 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 # take the next available name ID -> minNameID=256
self.assertEqual(256, nameID) self.assertEqual(256, nameID)
def test_decompile_badOffset(self): def test_decompile_badOffset(self):
# https://github.com/fonttools/fonttools/issues/525 # https://github.com/fonttools/fonttools/issues/525
table = table__n_a_m_e() table = table__n_a_m_e()