[otlLib] Return None for empty argument to buildAttachList()
This simplifies call sites when building GDEF tables. Also, publicly expose the buildAttachPoint() function. https://github.com/behdad/fonttools/issues/468#issuecomment-173006650
This commit is contained in:
parent
d1fd788af9
commit
1bb757ee3c
@ -162,9 +162,8 @@ class Builder(object):
|
|||||||
def buildGDEF(self):
|
def buildGDEF(self):
|
||||||
gdef = otTables.GDEF()
|
gdef = otTables.GDEF()
|
||||||
gdef.GlyphClassDef = self.buildGDEFGlyphClassDef_()
|
gdef.GlyphClassDef = self.buildGDEFGlyphClassDef_()
|
||||||
gdef.AttachList = (
|
gdef.AttachList = \
|
||||||
otl.buildAttachList(self.attachPoints_, self.glyphMap)
|
otl.buildAttachList(self.attachPoints_, self.glyphMap)
|
||||||
if self.attachPoints_ else None)
|
|
||||||
gdef.LigCaretList = self.buildGDEFLigCaretList_()
|
gdef.LigCaretList = self.buildGDEFLigCaretList_()
|
||||||
gdef.MarkAttachClassDef = self.buildGDEFMarkAttachClassDef_()
|
gdef.MarkAttachClassDef = self.buildGDEFMarkAttachClassDef_()
|
||||||
gdef.MarkGlyphSetsDef = self.buildGDEFMarkGlyphSetsDef_()
|
gdef.MarkGlyphSetsDef = self.buildGDEFMarkGlyphSetsDef_()
|
||||||
|
@ -225,16 +225,18 @@ def buildValue(value):
|
|||||||
# GDEF
|
# GDEF
|
||||||
|
|
||||||
def buildAttachList(attachPoints, glyphMap):
|
def buildAttachList(attachPoints, glyphMap):
|
||||||
"""{"glyphName": [4, 23]} --> otTables.AttachList"""
|
"""{"glyphName": [4, 23]} --> otTables.AttachList, or None"""
|
||||||
|
if not attachPoints:
|
||||||
|
return None
|
||||||
self = ot.AttachList()
|
self = ot.AttachList()
|
||||||
self.Coverage = buildCoverage(attachPoints.keys(), glyphMap)
|
self.Coverage = buildCoverage(attachPoints.keys(), glyphMap)
|
||||||
self.AttachPoint = [_buildAttachPoint(attachPoints[g])
|
self.AttachPoint = [buildAttachPoint(attachPoints[g])
|
||||||
for g in self.Coverage.glyphs]
|
for g in self.Coverage.glyphs]
|
||||||
self.GlyphCount = len(self.AttachPoint)
|
self.GlyphCount = len(self.AttachPoint)
|
||||||
return self
|
return self
|
||||||
|
|
||||||
|
|
||||||
def _buildAttachPoint(points):
|
def buildAttachPoint(points):
|
||||||
"""[4, 23, 41] --> otTables.AttachPoint"""
|
"""[4, 23, 41] --> otTables.AttachPoint"""
|
||||||
self = ot.AttachPoint()
|
self = ot.AttachPoint()
|
||||||
self.PointIndex = sorted(points)
|
self.PointIndex = sorted(points)
|
||||||
|
@ -75,6 +75,18 @@ class BuilderTest(unittest.TestCase):
|
|||||||
' </AttachPoint>'
|
' </AttachPoint>'
|
||||||
'</AttachList>')
|
'</AttachList>')
|
||||||
|
|
||||||
|
def test_buildAttachList_empty(self):
|
||||||
|
self.assertIsNone(builder.buildAttachList({}, self.GLYPHMAP))
|
||||||
|
|
||||||
|
def test_buildAttachPoint(self):
|
||||||
|
attachPoint = builder.buildAttachPoint([7, 3])
|
||||||
|
self.assertEqual(getXML(attachPoint.toXML),
|
||||||
|
'<AttachPoint>'
|
||||||
|
' <!-- PointCount=2 -->'
|
||||||
|
' <PointIndex index="0" value="3"/>'
|
||||||
|
' <PointIndex index="1" value="7"/>'
|
||||||
|
'</AttachPoint>')
|
||||||
|
|
||||||
def test_buildCoverage(self):
|
def test_buildCoverage(self):
|
||||||
cov = builder.buildCoverage({"two", "four"}, {"two": 2, "four": 4})
|
cov = builder.buildCoverage({"two", "four"}, {"two": 2, "four": 4})
|
||||||
self.assertEqual(getXML(cov.toXML),
|
self.assertEqual(getXML(cov.toXML),
|
||||||
|
Loading…
x
Reference in New Issue
Block a user