[varLib.merger] Support sparse CursivePos

Part of https://github.com/fonttools/fonttools/issues/3168
This commit is contained in:
Behdad Esfahbod 2023-07-18 05:43:23 -06:00
parent 56731a9f14
commit b14a29c353
2 changed files with 80 additions and 1 deletions

View File

@ -912,6 +912,30 @@ def _Lookup_SinglePos_subtables_flatten(lst, font, min_inclusive_rec_format):
return [new]
@AligningMerger.merger(ot.CursivePos)
def merge(merger, self, lst):
# Align them
glyphs, padded = _merge_GlyphOrders(
merger.font,
[l.Coverage.glyphs for l in lst],
[l.EntryExitRecord for l in lst],
)
self.Format = 1
self.Coverage = ot.Coverage()
self.Coverage.glyphs = glyphs
self.EntryExitRecord = []
for _ in glyphs:
rec = ot.EntryExitRecord()
rec.EntryAnchor = ot.Anchor()
rec.EntryAnchor.Format = 1
rec.ExitAnchor = ot.Anchor()
rec.ExitAnchor.Format = 1
self.EntryExitRecord.append(rec)
merger.mergeLists(self.EntryExitRecord, padded)
self.EntryExitCount = len(self.EntryExitRecord)
@AligningMerger.merger(ot.Lookup)
def merge(merger, self, lst):
subtables = merger.lookup_subtables = [l.SubTable for l in lst]

View File

@ -1846,7 +1846,7 @@ class COLRVariationMergerTest:
class SparsePositioningMergerTest:
def test_sparse_positioning_at_default(self):
def test_zero_kern_at_default(self):
# https://github.com/fonttools/fonttools/issues/3111
pytest.importorskip("ufo2ft")
@ -1881,3 +1881,58 @@ class SparsePositioningMergerTest:
font.save(b)
assert font["GDEF"].table.VarStore.VarData[0].Item[0] == [100, -100]
def test_sparse_cursive(self):
# https://github.com/fonttools/fonttools/issues/3168
pytest.importorskip("ufo2ft")
pytest.importorskip("ufoLib2")
from fontTools.designspaceLib import DesignSpaceDocument
from ufo2ft import compileVariableTTF
from ufoLib2 import Font
ds = DesignSpaceDocument()
ds.addAxisDescriptor(
name="wght", tag="wght", minimum=100, maximum=900, default=400
)
ds.addSourceDescriptor(font=Font(), location=dict(wght=100))
ds.addSourceDescriptor(font=Font(), location=dict(wght=400))
ds.addSourceDescriptor(font=Font(), location=dict(wght=900))
ds.sources[0].font.newGlyph("a").unicode = ord("a")
ds.sources[0].font.newGlyph("b").unicode = ord("b")
ds.sources[
0
].font.features.text = """
feature curs {
position cursive a <anchor 400 20> <anchor 0 -20>;
} curs;
"""
ds.sources[1].font.newGlyph("a").unicode = ord("a")
ds.sources[1].font.newGlyph("b").unicode = ord("b")
ds.sources[
1
].font.features.text = """
feature curs {
position cursive a <anchor 500 20> <anchor 0 -20>;
position cursive b <anchor 50 22> <anchor 0 -10>;
} curs;
"""
ds.sources[2].font.newGlyph("a").unicode = ord("a")
ds.sources[2].font.newGlyph("b").unicode = ord("b")
ds.sources[
2
].font.features.text = """
feature curs {
position cursive b <anchor 100 40> <anchor 0 -30>;
} curs;
"""
font = compileVariableTTF(ds, inplace=True)
b = BytesIO()
font.save(b)
assert font["GDEF"].table.VarStore.VarData[0].Item[0] == [-100, 0]