Skip to content

Commit

Permalink
Merge pull request #130 from anthrotype/fix-empty-fea-block
Browse files Browse the repository at this point in the history
[markFeatureWriter] do not write empty mkmk feature block
  • Loading branch information
Cosimo Lupo authored May 5, 2017
2 parents 73c1b01 + f60c307 commit 76840c6
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 5 deletions.
12 changes: 7 additions & 5 deletions Lib/ufo2ft/markFeatureWriter.py
Original file line number Diff line number Diff line change
Expand Up @@ -160,19 +160,21 @@ def _addFeature(self, lines, isMkmk=False):
# nothing to do, don't write empty feature
return
featureName = "mkmk" if isMkmk else "mark"

lines.append("feature %s {" % featureName)
feature = []

for i, anchorPair in enumerate(anchorList):
lookupName = "%s%d" % (featureName, i + 1)
self._addMarkLookup(lines, lookupName, isMkmk, anchorPair)
self._addMarkLookup(feature, lookupName, isMkmk, anchorPair)

if not isMkmk:
for i, anchorPairs in enumerate(self.ligaAnchorList):
lookupName = "mark2liga%d" % (i + 1)
self._addMarkToLigaLookup(lines, lookupName, anchorPairs)
self._addMarkToLigaLookup(feature, lookupName, anchorPairs)

lines.append("} %s;\n" % featureName)
if feature:
lines.append("feature %s {" % featureName)
lines.extend(feature)
lines.append("} %s;\n" % featureName)

def setupAnchorPairs(self):
"""
Expand Down
15 changes: 15 additions & 0 deletions tests/markFeatureWriter_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,21 @@ def test_add_classes(self):
'markClass cedilla <anchor 100 0> @MC_bottom;\n\n'
'markClass grave <anchor 100 200> @MC_top;')

def test_skip_empty_feature(self):
ufo = Font()
glyph = ufo.newGlyph('a')
glyph.appendAnchor(glyph.anchorClass(
anchorDict={'name': 'top', 'x': 100, 'y': 200}))
glyph = ufo.newGlyph('acutecomb')
glyph.appendAnchor(glyph.anchorClass(
anchorDict={'name': '_top', 'x': 100, 'y': 200}))

writer = MarkFeatureWriter(ufo)
fea = writer.write()

self.assertIn("feature mark", fea)
self.assertNotIn("feature mkmk", fea)


if __name__ == '__main__':
unittest.main()

0 comments on commit 76840c6

Please sign in to comment.