[otlLib] Move building of LigGlyphs from feaLib to otlLib
This commit is contained in:
parent
bfff7b4e86
commit
939b03fbea
@ -216,16 +216,11 @@ class Builder(object):
|
|||||||
result.LigGlyphCount = len(glyphs)
|
result.LigGlyphCount = len(glyphs)
|
||||||
result.LigGlyph = []
|
result.LigGlyph = []
|
||||||
for glyph in glyphs:
|
for glyph in glyphs:
|
||||||
ligGlyph = otTables.LigGlyph()
|
coords = self.ligatureCaretByPos_.get(glyph)
|
||||||
result.LigGlyph.append(ligGlyph)
|
points = self.ligatureCaretByIndex_.get(glyph)
|
||||||
ligGlyph.CaretValue = []
|
ligGlyph = otl.buildLigGlyph(coords, points)
|
||||||
for caretPos in sorted(self.ligatureCaretByPos_.get(glyph, [])):
|
if ligGlyph:
|
||||||
ligGlyph.CaretValue.append(
|
result.LigGlyph.append(ligGlyph)
|
||||||
otl.buildCaretValueForCoord(caretPos))
|
|
||||||
for point in sorted(self.ligatureCaretByIndex_.get(glyph, [])):
|
|
||||||
ligGlyph.CaretValue.append(
|
|
||||||
otl.buildCaretValueForPoint(point))
|
|
||||||
ligGlyph.CaretCount = len(ligGlyph.CaretValue)
|
|
||||||
return result
|
return result
|
||||||
|
|
||||||
def buildGDEFMarkAttachClassDef_(self):
|
def buildGDEFMarkAttachClassDef_(self):
|
||||||
|
@ -258,3 +258,18 @@ def buildCaretValueForPoint(point):
|
|||||||
self.Format = 2
|
self.Format = 2
|
||||||
self.CaretValuePoint = point
|
self.CaretValuePoint = point
|
||||||
return self
|
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
|
||||||
|
@ -173,6 +173,35 @@ class BuilderTest(unittest.TestCase):
|
|||||||
' <DeltaValue value="[77, 0, 0, 0, 3]"/>'
|
' <DeltaValue value="[77, 0, 0, 0, 3]"/>'
|
||||||
'</Device>')
|
'</Device>')
|
||||||
|
|
||||||
|
def test_buildLigGlyph_coords(self):
|
||||||
|
lig = builder.buildLigGlyph([500, 800], None)
|
||||||
|
self.assertEqual(getXML(lig.toXML),
|
||||||
|
'<LigGlyph>'
|
||||||
|
' <!-- CaretCount=2 -->'
|
||||||
|
' <CaretValue index="0" Format="1">'
|
||||||
|
' <Coordinate value="500"/>'
|
||||||
|
' </CaretValue>'
|
||||||
|
' <CaretValue index="1" Format="1">'
|
||||||
|
' <Coordinate value="800"/>'
|
||||||
|
' </CaretValue>'
|
||||||
|
'</LigGlyph>')
|
||||||
|
|
||||||
|
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),
|
||||||
|
'<LigGlyph>'
|
||||||
|
' <!-- CaretCount=1 -->'
|
||||||
|
' <CaretValue index="0" Format="2">'
|
||||||
|
' <CaretValuePoint value="2"/>'
|
||||||
|
' </CaretValue>'
|
||||||
|
'</LigGlyph>')
|
||||||
|
|
||||||
def test_buildSinglePos(self):
|
def test_buildSinglePos(self):
|
||||||
subtables = builder.buildSinglePos({
|
subtables = builder.buildSinglePos({
|
||||||
"one": builder.buildValue({"XPlacement": 500}),
|
"one": builder.buildValue({"XPlacement": 500}),
|
||||||
|
Loading…
x
Reference in New Issue
Block a user