diff --git a/Lib/fontTools/feaLib/builder.py b/Lib/fontTools/feaLib/builder.py index 1c2e2710f..b3f87fed1 100644 --- a/Lib/fontTools/feaLib/builder.py +++ b/Lib/fontTools/feaLib/builder.py @@ -216,16 +216,11 @@ class Builder(object): result.LigGlyphCount = len(glyphs) result.LigGlyph = [] for glyph in glyphs: - ligGlyph = otTables.LigGlyph() - result.LigGlyph.append(ligGlyph) - ligGlyph.CaretValue = [] - for caretPos in sorted(self.ligatureCaretByPos_.get(glyph, [])): - ligGlyph.CaretValue.append( - otl.buildCaretValueForCoord(caretPos)) - for point in sorted(self.ligatureCaretByIndex_.get(glyph, [])): - ligGlyph.CaretValue.append( - otl.buildCaretValueForPoint(point)) - ligGlyph.CaretCount = len(ligGlyph.CaretValue) + coords = self.ligatureCaretByPos_.get(glyph) + points = self.ligatureCaretByIndex_.get(glyph) + ligGlyph = otl.buildLigGlyph(coords, points) + if ligGlyph: + result.LigGlyph.append(ligGlyph) return result def buildGDEFMarkAttachClassDef_(self): diff --git a/Lib/fontTools/otlLib/builder.py b/Lib/fontTools/otlLib/builder.py index 8fa8978d9..196a112fd 100644 --- a/Lib/fontTools/otlLib/builder.py +++ b/Lib/fontTools/otlLib/builder.py @@ -258,3 +258,18 @@ def buildCaretValueForPoint(point): self.Format = 2 self.CaretValuePoint = point return self + + +def buildLigGlyph(coords, points): + """([500], [4]) --> otTables.LigGlyph; None for empty coords/points""" + carets = [] + if coords: + carets.extend([buildCaretValueForCoord(c) for c in sorted(coords)]) + if points: + carets.extend([buildCaretValueForPoint(p) for p in sorted(points)]) + if not carets: + return None + self = ot.LigGlyph() + self.CaretCount = len(carets) + self.CaretValue = carets + return self diff --git a/Lib/fontTools/otlLib/builder_test.py b/Lib/fontTools/otlLib/builder_test.py index 181ba9034..a25850a2e 100644 --- a/Lib/fontTools/otlLib/builder_test.py +++ b/Lib/fontTools/otlLib/builder_test.py @@ -173,6 +173,35 @@ class BuilderTest(unittest.TestCase): ' ' '') + def test_buildLigGlyph_coords(self): + lig = builder.buildLigGlyph([500, 800], None) + self.assertEqual(getXML(lig.toXML), + '' + ' ' + ' ' + ' ' + ' ' + ' ' + ' ' + ' ' + '') + + def test_buildLigGlyph_empty(self): + self.assertIsNone(builder.buildLigGlyph([], [])) + + def test_buildLigGlyph_None(self): + self.assertIsNone(builder.buildLigGlyph(None, None)) + + def test_buildLigGlyph_points(self): + lig = builder.buildLigGlyph(None, [2]) + self.assertEqual(getXML(lig.toXML), + '' + ' ' + ' ' + ' ' + ' ' + '') + def test_buildSinglePos(self): subtables = builder.buildSinglePos({ "one": builder.buildValue({"XPlacement": 500}),