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)
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)

View File

@ -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"

View File

@ -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()