From f42d312580d980f382d74949b229a20044b097b3 Mon Sep 17 00:00:00 2001 From: Sascha Brawer Date: Thu, 21 Jan 2016 15:16:55 +0100 Subject: [PATCH] [otlLib] Move building of ComponentRecords from feaLib to otlLib --- Lib/fontTools/feaLib/builder.py | 13 +++++-------- Lib/fontTools/otlLib/builder.py | 7 +++++++ Lib/fontTools/otlLib/builder_test.py | 16 ++++++++++++++++ 3 files changed, 28 insertions(+), 8 deletions(-) diff --git a/Lib/fontTools/feaLib/builder.py b/Lib/fontTools/feaLib/builder.py index d42de3ba1..407c0d603 100644 --- a/Lib/fontTools/feaLib/builder.py +++ b/Lib/fontTools/feaLib/builder.py @@ -1014,13 +1014,13 @@ class MarkLigPosBuilder(LookupBuilder): return result def build(self): + markClasses = self.buildMarkClasses_(self.marks) + markClassList = sorted(markClasses.keys(), key=markClasses.get) st = otTables.MarkLigPos() st.Format = 1 st.MarkCoverage = otl.buildCoverage(self.marks, self.glyphMap) - markClasses = self.buildMarkClasses_(self.marks) st.ClassCount = len(markClasses) st.MarkArray = self.buildMarkArray_(self.marks, markClasses) - st.LigatureCoverage = otl.buildCoverage(self.ligatures, self.glyphMap) st.LigatureArray = otTables.LigatureArray() st.LigatureArray.LigatureCount = len(self.ligatures) @@ -1031,12 +1031,9 @@ class MarkLigPosBuilder(LookupBuilder): attach.ComponentCount = len(components) attach.ComponentRecord = [] for component in components: - crec = otTables.ComponentRecord() - attach.ComponentRecord.append(crec) - crec.LigatureAnchor = [] - for markClass in sorted(markClasses.keys(), - key=markClasses.get): - crec.LigatureAnchor.append(component.get(markClass)) + anchors = [component.get(mc) for mc in markClassList] + attach.ComponentRecord.append( + otl.buildComponentRecord(anchors)) st.LigatureArray.LigatureAttach.append(attach) return self.buildLookup_([st]) diff --git a/Lib/fontTools/otlLib/builder.py b/Lib/fontTools/otlLib/builder.py index 776f23ef7..966c21d79 100644 --- a/Lib/fontTools/otlLib/builder.py +++ b/Lib/fontTools/otlLib/builder.py @@ -110,6 +110,13 @@ def buildAnchor(x, y, point=None, deviceX=None, deviceY=None): return self +def buildComponentRecord(anchors): + """[otTables.Anchor, otTables.Anchor, ...] --> otTables.ComponentRecord""" + self = ot.ComponentRecord() + self.LigatureAnchor = anchors + return self + + def buildCursivePos(attach, glyphMap): """{"alef": (entry, exit)} --> otTables.CursivePos""" self = ot.CursivePos() diff --git a/Lib/fontTools/otlLib/builder_test.py b/Lib/fontTools/otlLib/builder_test.py index 5a0789c6c..ec766d488 100644 --- a/Lib/fontTools/otlLib/builder_test.py +++ b/Lib/fontTools/otlLib/builder_test.py @@ -109,6 +109,22 @@ class BuilderTest(unittest.TestCase): ' ' '') + def test_buildComponentRecord(self): + a = builder.buildAnchor + rec = builder.buildComponentRecord([a(500, -20), None, a(300, -15)]) + self.assertEqual(getXML(rec.toXML), + '' + ' ' + ' ' + ' ' + ' ' + ' ' + ' ' + ' ' + ' ' + ' ' + '') + def test_buildCoverage(self): cov = builder.buildCoverage({"two", "four"}, {"two": 2, "four": 4}) self.assertEqual(getXML(cov.toXML),